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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Lib.Sequence.fst | Lib.Sequence.of_list | val of_list:
#a:Type
-> l:list a{List.Tot.length l <= max_size_t} ->
Tot (s:lseq a (List.Tot.length l){to_seq s == Seq.seq_of_list l}) | val of_list:
#a:Type
-> l:list a{List.Tot.length l <= max_size_t} ->
Tot (s:lseq a (List.Tot.length l){to_seq s == Seq.seq_of_list l}) | let of_list #a l = Seq.seq_of_list #a l | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 17,
"start_col": 0,
"start_line": 17
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list a {FStar.List.Tot.Base.length l <= Lib.IntTypes.max_size_t}
-> s:
Lib.Sequence.lseq a (FStar.List.Tot.Base.length l)
{Lib.Sequence.to_seq s == FStar.Seq.Base.seq_of_list l} | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length",
"Lib.IntTypes.max_size_t",
"FStar.Seq.Base.seq_of_list",
"Lib.Sequence.lseq",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq"
] | [] | false | false | false | false | false | let of_list #a l =
| Seq.seq_of_list #a l | false |
Lib.Sequence.fst | Lib.Sequence.upd | val upd:
#a:Type
-> #len:size_nat
-> s:lseq a len
-> n:size_nat{n < len}
-> x:a ->
Tot (o:lseq a len{to_seq o == Seq.upd (to_seq s) n x /\ index o n == x /\ (forall (i:size_nat).
{:pattern (index s i)} (i < len /\ i <> n) ==> index o i == index s i)}) | val upd:
#a:Type
-> #len:size_nat
-> s:lseq a len
-> n:size_nat{n < len}
-> x:a ->
Tot (o:lseq a len{to_seq o == Seq.upd (to_seq s) n x /\ index o n == x /\ (forall (i:size_nat).
{:pattern (index s i)} (i < len /\ i <> n) ==> index o i == index s i)}) | let upd #a #len s n x = Seq.upd #a s n x | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Lib.Sequence.lseq a len -> n: Lib.IntTypes.size_nat{n < len} -> x: a
-> o:
Lib.Sequence.lseq a len
{ Lib.Sequence.to_seq o == FStar.Seq.Base.upd (Lib.Sequence.to_seq s) n x /\
Lib.Sequence.index o n == x /\
(forall (i: Lib.IntTypes.size_nat). {:pattern Lib.Sequence.index s i}
i < len /\ i <> n ==> Lib.Sequence.index o i == Lib.Sequence.index s i) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.upd",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index"
] | [] | false | false | false | false | false | let upd #a #len s n x =
| Seq.upd #a s n x | false |
Lib.Sequence.fst | Lib.Sequence.eq_elim | val eq_elim: #a:Type -> #len:size_nat -> s1:lseq a len -> s2:lseq a len ->
Lemma
(requires equal s1 s2)
(ensures s1 == s2)
[SMTPat (equal s1 s2)] | val eq_elim: #a:Type -> #len:size_nat -> s1:lseq a len -> s2:lseq a len ->
Lemma
(requires equal s1 s2)
(ensures s1 == s2)
[SMTPat (equal s1 s2)] | let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2 | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 33,
"start_col": 0,
"start_line": 30
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Lib.Sequence.lseq a len -> s2: Lib.Sequence.lseq a len
-> FStar.Pervasives.Lemma (requires Lib.Sequence.equal s1 s2)
(ensures s1 == s2)
[SMTPat (Lib.Sequence.equal s1 s2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"FStar.Seq.Base.lemma_eq_elim",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index"
] | [] | false | false | true | false | false | let eq_elim #a #len s1 s2 =
| assert (forall (i: nat{i < len}). {:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2 | false |
Lib.Sequence.fst | Lib.Sequence.lemma_concat2 | val lemma_concat2:
#a:Type0
-> len0:size_nat
-> s0:lseq a len0
-> len1:size_nat{len0 + len1 <= max_size_t}
-> s1:lseq a len1
-> s:lseq a (len0 + len1) ->
Lemma
(requires
sub s 0 len0 == s0 /\
sub s len0 len1 == s1)
(ensures s == concat s0 s1) | val lemma_concat2:
#a:Type0
-> len0:size_nat
-> s0:lseq a len0
-> len1:size_nat{len0 + len1 <= max_size_t}
-> s1:lseq a len1
-> s:lseq a (len0 + len1) ->
Lemma
(requires
sub s 0 len0 == s0 /\
sub s len0 len1 == s1)
(ensures s == concat s0 s1) | let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 60,
"start_col": 0,
"start_line": 57
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len0: Lib.IntTypes.size_nat ->
s0: Lib.Sequence.lseq a len0 ->
len1: Lib.IntTypes.size_nat{len0 + len1 <= Lib.IntTypes.max_size_t} ->
s1: Lib.Sequence.lseq a len1 ->
s: Lib.Sequence.lseq a (len0 + len1)
-> FStar.Pervasives.Lemma
(requires Lib.Sequence.sub s 0 len0 == s0 /\ Lib.Sequence.sub s len0 len1 == s1)
(ensures s == Lib.Sequence.concat s0 s1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"FStar.Seq.Base.lemma_eq_intro",
"Lib.Sequence.concat",
"Prims.unit",
"FStar.Seq.Properties.lemma_split"
] | [] | true | false | true | false | false | let lemma_concat2 #a len0 s0 len1 s1 s =
| Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1) | false |
Lib.Sequence.fst | Lib.Sequence.createi_a | val createi_a : a: Type0 ->
len: Lib.IntTypes.size_nat ->
init: (i: Prims.nat{i < len} -> a) ->
k: Prims.nat{k <= len}
-> Type0 | let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 71,
"start_col": 0,
"start_line": 70
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type0 ->
len: Lib.IntTypes.size_nat ->
init: (i: Prims.nat{i < len} -> a) ->
k: Prims.nat{k <= len}
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | true | let createi_a (a: Type) (len: size_nat) (init: (i: nat{i < len} -> a)) (k: nat{k <= len}) =
| lseq a k | false |
|
Lib.Sequence.fst | Lib.Sequence.of_list_index | val of_list_index:
#a:Type
-> l:list a{List.Tot.length l <= max_size_t}
-> i:nat{i < List.Tot.length l} ->
Lemma (index (of_list l) i == List.Tot.index l i)
[SMTPat (index (of_list l) i)] | val of_list_index:
#a:Type
-> l:list a{List.Tot.length l <= max_size_t}
-> i:nat{i < List.Tot.length l} ->
Lemma (index (of_list l) i == List.Tot.index l i)
[SMTPat (index (of_list l) i)] | let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 20,
"start_col": 0,
"start_line": 19
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: Prims.list a {FStar.List.Tot.Base.length l <= Lib.IntTypes.max_size_t} ->
i: Prims.nat{i < FStar.List.Tot.Base.length l}
-> FStar.Pervasives.Lemma
(ensures Lib.Sequence.index (Lib.Sequence.of_list l) i == FStar.List.Tot.Base.index l i)
[SMTPat (Lib.Sequence.index (Lib.Sequence.of_list l) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"FStar.Seq.Properties.lemma_seq_of_list_index",
"Prims.unit"
] | [] | true | false | true | false | false | let of_list_index #a l i =
| Seq.lemma_seq_of_list_index #a l i | false |
Lib.Sequence.fst | Lib.Sequence.equal | val equal (#a:Type) (#len:size_nat) (s1:lseq a len) (s2:lseq a len) : Type0 | val equal (#a:Type) (#len:size_nat) (s1:lseq a len) (s2:lseq a len) : Type0 | let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 93,
"end_line": 23,
"start_col": 0,
"start_line": 22
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Lib.Sequence.lseq a len -> s2: Lib.Sequence.lseq a len -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index"
] | [] | false | false | false | false | true | let equal #a #len s1 s2 =
| forall (i: size_nat{i < len}). {:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i | false |
Lib.Sequence.fst | Lib.Sequence.map | val map:#a:Type -> #b:Type -> #len:size_nat
-> f:(a -> Tot b)
-> s1:lseq a len ->
Tot (s2:lseq b len{(forall (i:nat).
{:pattern (index s2 i)} i < len ==> index s2 i == f s1.[i])}) | val map:#a:Type -> #b:Type -> #len:size_nat
-> f:(a -> Tot b)
-> s1:lseq a len ->
Tot (s2:lseq b len{(forall (i:nat).
{:pattern (index s2 i)} i < len ==> index s2 i == f s1.[i])}) | let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 110,
"start_col": 0,
"start_line": 109
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> b) -> s1: Lib.Sequence.lseq a len
-> s2:
Lib.Sequence.lseq b len
{ forall (i: Prims.nat). {:pattern Lib.Sequence.index s2 i}
i < len ==> Lib.Sequence.index s2 i == f s1.[ i ] } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Lib.Sequence.createi",
"Lib.Sequence.map_inner",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let map #a #b #len f s =
| createi #b len (map_inner #a #b #len f s) | false |
Lib.Sequence.fst | Lib.Sequence.eq_intro | val eq_intro: #a:Type -> #len:size_nat -> s1:lseq a len -> s2:lseq a len ->
Lemma
(requires forall i. {:pattern index s1 i; index s2 i} index s1 i == index s2 i)
(ensures equal s1 s2)
[SMTPat (equal s1 s2)] | val eq_intro: #a:Type -> #len:size_nat -> s1:lseq a len -> s2:lseq a len ->
Lemma
(requires forall i. {:pattern index s1 i; index s2 i} index s1 i == index s2 i)
(ensures equal s1 s2)
[SMTPat (equal s1 s2)] | let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 28,
"start_col": 0,
"start_line": 25
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Lib.Sequence.lseq a len -> s2: Lib.Sequence.lseq a len
-> FStar.Pervasives.Lemma
(requires
forall (i: Lib.IntTypes.size_nat{i < len /\ i < len}).
{:pattern Lib.Sequence.index s1 i; Lib.Sequence.index s2 i}
Lib.Sequence.index s1 i == Lib.Sequence.index s2 i)
(ensures Lib.Sequence.equal s1 s2)
[SMTPat (Lib.Sequence.equal s1 s2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"FStar.Seq.Base.lemma_eq_intro",
"Lib.Sequence.to_seq",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index"
] | [] | false | false | true | false | false | let eq_intro #a #len s1 s2 =
| assert (forall (i: nat{i < len}). {:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2) | false |
Lib.Sequence.fst | Lib.Sequence.map2i | val map2i:#a:Type -> #b:Type -> #c:Type -> #len:size_nat
-> f:(i:nat{i < len} -> a -> b -> Tot c)
-> s1:lseq a len
-> s2:lseq b len ->
Tot (s3:lseq c len{(forall (i:nat).
{:pattern (index s3 i)} i < len ==> index s3 i == f i s1.[i] s2.[i])}) | val map2i:#a:Type -> #b:Type -> #c:Type -> #len:size_nat
-> f:(i:nat{i < len} -> a -> b -> Tot c)
-> s1:lseq a len
-> s2:lseq b len ->
Tot (s3:lseq c len{(forall (i:nat).
{:pattern (index s3 i)} i < len ==> index s3 i == f i s1.[i] s2.[i])}) | let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i]) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 113,
"start_col": 0,
"start_line": 112
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: (i: Prims.nat{i < len} -> _: a -> _: b -> c) ->
s1: Lib.Sequence.lseq a len ->
s2: Lib.Sequence.lseq b len
-> s3:
Lib.Sequence.lseq c len
{ forall (i: Prims.nat). {:pattern Lib.Sequence.index s3 i}
i < len ==> Lib.Sequence.index s3 i == f i s1.[ i ] s2.[ i ] } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.Sequence.createi",
"Lib.Sequence.op_String_Access",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Lib.Sequence.index"
] | [] | false | false | false | false | false | let map2i #a #b #c #len f s1 s2 =
| createi #c len (fun i -> f i s1.[ i ] s2.[ i ]) | false |
Lib.Sequence.fst | Lib.Sequence.update_sub | val update_sub:
#a:Type
-> #len:size_nat
-> i:lseq a len
-> start:size_nat
-> n:size_nat{start + n <= len}
-> x:lseq a n ->
Tot (o:lseq a len{sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < len)}).
{:pattern (index o k)} index o k == index i k)}) | val update_sub:
#a:Type
-> #len:size_nat
-> i:lseq a len
-> start:size_nat
-> n:size_nat{start + n <= len}
-> x:lseq a n ->
Tot (o:lseq a len{sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < len)}).
{:pattern (index o k)} index o k == index i k)}) | let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 47,
"start_col": 0,
"start_line": 41
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Lib.Sequence.lseq a len ->
start: Lib.IntTypes.size_nat ->
n: Lib.IntTypes.size_nat{start + n <= len} ->
x: Lib.Sequence.lseq a n
-> o:
Lib.Sequence.lseq a len
{ Lib.Sequence.sub o start n == x /\
(forall (k: Prims.nat{0 <= k /\ k < start \/ start + n <= k /\ k < len}).
{:pattern Lib.Sequence.index o k}
Lib.Sequence.index o k == Lib.Sequence.index i k) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.unit",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"Lib.Sequence.length",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index"
] | [] | false | false | false | false | false | let update_sub #a #len s start n x =
| let o = Seq.append (Seq.append (Seq.slice s 0 start) x) (Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o | false |
Lib.Sequence.fst | Lib.Sequence.sub | val sub:
#a:Type
-> #len:size_nat
-> s1:lseq a len
-> start:size_nat
-> n:size_nat{start + n <= len} ->
Tot (s2:lseq a n{to_seq s2 == Seq.slice (to_seq s1) start (start + n) /\
(forall (k:nat{k < n}). {:pattern (index s2 k)} index s2 k == index s1 (start + k))}) | val sub:
#a:Type
-> #len:size_nat
-> s1:lseq a len
-> start:size_nat
-> n:size_nat{start + n <= len} ->
Tot (s2:lseq a n{to_seq s2 == Seq.slice (to_seq s1) start (start + n) /\
(forall (k:nat{k < n}). {:pattern (index s2 k)} index s2 k == index s1 (start + k))}) | let sub #a #len s start n = Seq.slice #a s start (start + n) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: Lib.Sequence.lseq a len ->
start: Lib.IntTypes.size_nat ->
n: Lib.IntTypes.size_nat{start + n <= len}
-> s2:
Lib.Sequence.lseq a n
{ Lib.Sequence.to_seq s2 == FStar.Seq.Base.slice (Lib.Sequence.to_seq s1) start (start + n) /\
(forall (k: Prims.nat{k < n}). {:pattern Lib.Sequence.index s2 k}
Lib.Sequence.index s2 k == Lib.Sequence.index s1 (start + k)) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.slice",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index"
] | [] | false | false | false | false | false | let sub #a #len s start n =
| Seq.slice #a s start (start + n) | false |
Lib.Sequence.fst | Lib.Sequence.mapi | val mapi:#a:Type -> #b:Type -> #len:size_nat
-> f:(i:nat{i < len} -> a -> Tot b)
-> s1:lseq a len ->
Tot (s2:lseq b len{(forall (i:nat).
{:pattern (index s2 i)} i < len ==> index s2 i == f i s1.[i])}) | val mapi:#a:Type -> #b:Type -> #len:size_nat
-> f:(i:nat{i < len} -> a -> Tot b)
-> s1:lseq a len ->
Tot (s2:lseq b len{(forall (i:nat).
{:pattern (index s2 i)} i < len ==> index s2 i == f i s1.[i])}) | let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s) | {
"file_name": "lib/Lib.Sequence.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": 101
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (i: Prims.nat{i < len} -> _: a -> b) -> s1: Lib.Sequence.lseq a len
-> s2:
Lib.Sequence.lseq b len
{ forall (i: Prims.nat). {:pattern Lib.Sequence.index s2 i}
i < len ==> Lib.Sequence.index s2 i == f i s1.[ i ] } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.Sequence.createi",
"Lib.Sequence.mapi_inner",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let mapi #a #b #len f s =
| createi #b len (mapi_inner #a #b #len f s) | false |
Lib.Sequence.fst | Lib.Sequence.generate_blocks_simple_a | val generate_blocks_simple_a : a: Type0 -> bs: Lib.IntTypes.size_nat -> max: Prims.nat -> i: Prims.nat{i <= max} -> Type0 | let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs} | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 109,
"end_line": 210,
"start_col": 0,
"start_line": 210
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> bs: Lib.IntTypes.size_nat -> max: Prims.nat -> i: Prims.nat{i <= max} -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | true | let generate_blocks_simple_a (a: Type) (bs: size_nat) (max: nat) (i: nat{i <= max}) =
| s: seq a {length s == i * bs} | false |
|
Lib.Sequence.fst | Lib.Sequence.generate_blocks_a | val generate_blocks_a : t: Type0 ->
blocklen: Lib.IntTypes.size_nat ->
max: Prims.nat ->
a: (i: Prims.nat{i <= max} -> Type) ->
i: Prims.nat{i <= max}
-> Type | let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen} | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 150,
"end_line": 198,
"start_col": 0,
"start_line": 198
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Type0 ->
blocklen: Lib.IntTypes.size_nat ->
max: Prims.nat ->
a: (i: Prims.nat{i <= max} -> Type) ->
i: Prims.nat{i <= max}
-> Type | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | true | let generate_blocks_a
(t: Type)
(blocklen: size_nat)
(max: nat)
(a: (i: nat{i <= max} -> Type))
(i: nat{i <= max})
=
| a i & s: seq t {length s == i * blocklen} | false |
|
Lib.Sequence.fst | Lib.Sequence.map2 | val map2:#a:Type -> #b:Type -> #c:Type -> #len:size_nat
-> f:(a -> b -> Tot c)
-> s1:lseq a len
-> s2:lseq b len ->
Tot (s3:lseq c len{(forall (i:nat).
{:pattern (index s3 i)} i < len ==> index s3 i == f s1.[i] s2.[i])}) | val map2:#a:Type -> #b:Type -> #c:Type -> #len:size_nat
-> f:(a -> b -> Tot c)
-> s1:lseq a len
-> s2:lseq b len ->
Tot (s3:lseq c len{(forall (i:nat).
{:pattern (index s3 i)} i < len ==> index s3 i == f s1.[i] s2.[i])}) | let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 121,
"start_col": 0,
"start_line": 120
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> _: b -> c) -> s1: Lib.Sequence.lseq a len -> s2: Lib.Sequence.lseq b len
-> s3:
Lib.Sequence.lseq c len
{ forall (i: Prims.nat). {:pattern Lib.Sequence.index s3 i}
i < len ==> Lib.Sequence.index s3 i == f s1.[ i ] s2.[ i ] } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Lib.Sequence.createi",
"Lib.Sequence.map2_inner",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let map2 #a #b #c #len f s1 s2 =
| createi #c len (map2_inner #a #b #c #len f s1 s2) | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.clens_ifthenelse_payload | val clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b)) | val clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b)) | let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
} | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 175,
"start_col": 0,
"start_line": 167
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p -> b: Prims.bool
-> LowParse.Low.Base.Spec.clens (Mkparse_ifthenelse_param?.parse_ifthenelse_t p)
(Mkparse_ifthenelse_param?.parse_ifthenelse_payload_t p b) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.bool",
"LowParse.Low.Base.Spec.Mkclens",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"Prims.eq2",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"FStar.Pervasives.dfst",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_recip",
"FStar.Pervasives.dsnd",
"Prims.l_True",
"LowParse.Low.Base.Spec.clens"
] | [] | false | false | false | false | false | let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b)) =
| {
clens_cond
=
(fun (x: p.parse_ifthenelse_t) ->
p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get
=
(fun (x: p.parse_ifthenelse_t) ->
dsnd (s.serialize_ifthenelse_synth_recip x)
<:
Ghost (p.parse_ifthenelse_payload_t b)
(requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b))
(ensures (fun _ -> True)))
} | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload'' | val gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires
(gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
input))
(ensures
(fun res ->
gaccessor_post' (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
input
res)) | val gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires
(gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
input))
(ensures
(fun res ->
gaccessor_post' (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
input
res)) | let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input
))
(ensures (fun res ->
gaccessor_post' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input res
))
= parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 192,
"start_col": 0,
"start_line": 177
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos
let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p ->
b: Prims.bool ->
input: LowParse.Bytes.bytes
-> Prims.Ghost Prims.nat | Prims.Ghost | [] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.bool",
"LowParse.Bytes.bytes",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.Base.consumed_length",
"Prims.nat",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"Prims.unit",
"LowParse.Spec.IfThenElse.parse_ifthenelse_parse_tag_payload",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Low.IfThenElse.clens_ifthenelse_payload",
"LowParse.Low.Base.Spec.gaccessor_post'"
] | [] | false | false | false | false | false | let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires
(gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
input))
(ensures
(fun res ->
gaccessor_post' (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
input
res)) =
| parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed | false |
Lib.Sequence.fst | Lib.Sequence.createi | val createi: #a:Type
-> len:size_nat
-> init:(i:nat{i < len} -> a) ->
Tot (s:lseq a len{(forall (i:nat).
{:pattern (index s i)} i < len ==> index s i == init i)}) | val createi: #a:Type
-> len:size_nat
-> init:(i:nat{i < len} -> a) ->
Tot (s:lseq a len{(forall (i:nat).
{:pattern (index s i)} i < len ==> index s i == init i)}) | let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list []) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 92,
"start_col": 0,
"start_line": 87
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"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 | len: Lib.IntTypes.size_nat -> init: (i: Prims.nat{i < len} -> a)
-> s:
Lib.Sequence.lseq a len
{ forall (i: Prims.nat). {:pattern Lib.Sequence.index s i}
i < len ==> Lib.Sequence.index s i == init i } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.LoopCombinators.repeat_gen_inductive",
"Lib.Sequence.createi_a",
"Lib.Sequence.createi_pred",
"Lib.Sequence.createi_step",
"Lib.Sequence.of_list",
"Prims.Nil",
"Lib.Sequence.lseq",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Lib.Sequence.index"
] | [] | false | false | false | false | false | let createi #a len init_f =
| repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list []) | false |
Lib.Sequence.fst | Lib.Sequence.createi_step | val createi_step
(a: Type)
(len: size_nat)
(init: (i: nat{i < len} -> a))
(i: nat{i < len})
(si: createi_a a len init i)
: r:
createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r} | val createi_step
(a: Type)
(len: size_nat)
(init: (i: nat{i < len} -> a))
(i: nat{i < len})
(si: createi_a a len init i)
: r:
createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r} | let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 83,
"start_col": 0,
"start_line": 77
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type0 ->
len: Lib.IntTypes.size_nat ->
init: (i: Prims.nat{i < len} -> a) ->
i: Prims.nat{i < len} ->
si: Lib.Sequence.createi_a a len init i
-> r:
Lib.Sequence.createi_a a len init (i + 1)
{Lib.Sequence.createi_pred a len init i si ==> Lib.Sequence.createi_pred a len init (i + 1) r} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.createi_a",
"FStar.Seq.Properties.snoc",
"Prims.unit",
"Prims._assert",
"Prims.l_imp",
"Lib.Sequence.createi_pred",
"Prims.l_Forall",
"Prims.eq2",
"Lib.Sequence.index",
"Prims.op_Addition"
] | [] | false | false | false | false | false | let createi_step
(a: Type)
(len: size_nat)
(init: (i: nat{i < len} -> a))
(i: nat{i < len})
(si: createi_a a len init i)
: r:
createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r} =
| assert (createi_pred a len init i si ==> (forall (j: nat). j < i ==> index si j == init j));
Seq.snoc si (init i) | false |
Lib.Sequence.fst | Lib.Sequence.createi_pred | val createi_pred : a: Type0 ->
len: Lib.IntTypes.size_nat ->
init: (i: Prims.nat{i < len} -> a) ->
k: Prims.nat{k <= len} ->
s: Lib.Sequence.createi_a a len init k
-> Prims.logical | let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 75,
"start_col": 0,
"start_line": 73
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type0 ->
len: Lib.IntTypes.size_nat ->
init: (i: Prims.nat{i < len} -> a) ->
k: Prims.nat{k <= len} ->
s: Lib.Sequence.createi_a a len init k
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.createi_a",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Lib.Sequence.index",
"Prims.logical"
] | [] | false | false | false | false | true | let createi_pred
(a: Type)
(len: size_nat)
(init: (i: nat{i < len} -> a))
(k: nat{k <= len})
(s: createi_a a len init k)
=
| forall (i: nat). {:pattern (index s i)} i < k ==> index s i == init i | false |
|
Lib.Sequence.fst | Lib.Sequence.seq_sub | val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))} | val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))} | let seq_sub #a s start n =
Seq.slice #a s start (start + n) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 138,
"start_col": 0,
"start_line": 137
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Lib.Sequence.seq a -> start: Prims.nat -> n: Prims.nat{start + n <= Lib.Sequence.length s1}
-> s2:
Lib.Sequence.seq a
{ Lib.Sequence.length s2 == n /\
(forall (k: Prims.nat{k < n}). {:pattern FStar.Seq.Base.index s2 k}
FStar.Seq.Base.index s2 k == FStar.Seq.Base.index s1 (start + k)) } | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.Sequence.length",
"FStar.Seq.Base.slice",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index"
] | [] | false | false | false | false | false | let seq_sub #a s start n =
| Seq.slice #a s start (start + n) | false |
Lib.Sequence.fst | Lib.Sequence.for_all2 | val for_all2:#a:Type -> #b:Type -> #len:size_nat
-> (a -> b -> Tot bool)
-> s1:lseq a len
-> s2:lseq b len ->
Tot bool | val for_all2:#a:Type -> #b:Type -> #len:size_nat
-> (a -> b -> Tot bool)
-> s1:lseq a len
-> s2:lseq b len ->
Tot bool | let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 127,
"start_col": 0,
"start_line": 125
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> _: b -> Prims.bool) -> s1: Lib.Sequence.lseq a len -> s2: Lib.Sequence.lseq b len
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.bool",
"Lib.Sequence.lseq",
"FStar.Seq.Properties.for_all",
"Prims.op_Equality",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.Sequence.map2"
] | [] | false | false | false | false | false | let for_all2 #a #b #len f x y =
| let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r | false |
Lib.Sequence.fst | Lib.Sequence.lemma_concat3 | val lemma_concat3:
#a:Type0
-> len0:size_nat
-> s0:lseq a len0
-> len1:size_nat{len0 + len1 <= max_size_t}
-> s1:lseq a len1
-> len2:size_nat{len0 + len1 + len2 <= max_size_t}
-> s2:lseq a len2
-> s:lseq a (len0 + len1 + len2) ->
Lemma
(requires
sub s 0 len0 == s0 /\
sub s len0 len1 == s1 /\
sub s (len0 + len1) len2 == s2)
(ensures s == concat (concat s0 s1) s2) | val lemma_concat3:
#a:Type0
-> len0:size_nat
-> s0:lseq a len0
-> len1:size_nat{len0 + len1 <= max_size_t}
-> s1:lseq a len1
-> len2:size_nat{len0 + len1 + len2 <= max_size_t}
-> s2:lseq a len2
-> s:lseq a (len0 + len1 + len2) ->
Lemma
(requires
sub s 0 len0 == s0 /\
sub s len0 len1 == s1 /\
sub s (len0 + len1) len2 == s2)
(ensures s == concat (concat s0 s1) s2) | let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 68,
"start_col": 0,
"start_line": 62
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len0: Lib.IntTypes.size_nat ->
s0: Lib.Sequence.lseq a len0 ->
len1: Lib.IntTypes.size_nat{len0 + len1 <= Lib.IntTypes.max_size_t} ->
s1: Lib.Sequence.lseq a len1 ->
len2: Lib.IntTypes.size_nat{len0 + len1 + len2 <= Lib.IntTypes.max_size_t} ->
s2: Lib.Sequence.lseq a len2 ->
s: Lib.Sequence.lseq a (len0 + len1 + len2)
-> FStar.Pervasives.Lemma
(requires
Lib.Sequence.sub s 0 len0 == s0 /\ Lib.Sequence.sub s len0 len1 == s1 /\
Lib.Sequence.sub s (len0 + len1) len2 == s2)
(ensures s == Lib.Sequence.concat (Lib.Sequence.concat s0 s1) s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"FStar.Seq.Base.lemma_eq_intro",
"Lib.Sequence.concat",
"Prims.unit",
"FStar.Seq.Properties.lemma_split",
"Lib.Sequence.sub",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append"
] | [] | true | false | true | false | false | let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
| let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2) | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_tag | val gaccessor_ifthenelse_tag (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s)) | val gaccessor_ifthenelse_tag (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s)) | let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 155,
"start_col": 0,
"start_line": 150
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p)
(LowParse.Low.IfThenElse.clens_ifthenelse_tag s) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_tag'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.IfThenElse.clens_ifthenelse_tag",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | false | false | false | false | false | let gaccessor_ifthenelse_tag (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s)) =
| gaccessor_prop_equiv (parse_ifthenelse p)
p.parse_ifthenelse_tag_parser
(clens_ifthenelse_tag s)
(gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.jump_ifthenelse | val jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b)))))
: Tot (jumper (parse_ifthenelse p)) | val jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b)))))
: Tot (jumper (parse_ifthenelse p)) | let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 129,
"start_col": 0,
"start_line": 114
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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.IfThenElse.parse_ifthenelse_param ->
vt: LowParse.Low.Base.jumper (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p) ->
test: LowParse.Low.IfThenElse.test_ifthenelse_tag p ->
vp:
(b: Prims.bool
-> LowParse.Low.Base.jumper (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b)))
-> LowParse.Low.Base.jumper (LowParse.Spec.IfThenElse.parse_ifthenelse p) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Low.Base.jumper",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.IfThenElse.test_ifthenelse_tag",
"Prims.bool",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"FStar.Classical.move_requires",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.l_and",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"LowParse.Low.IfThenElse.valid_ifthenelse_elim",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b)))))
: Tot (jumper (parse_ifthenelse p)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = Classical.move_requires (valid_ifthenelse_elim p h input) pos in
let pos_after_t = vt input pos in
let b = test input pos in
if b then vp true input pos_after_t else vp false input pos_after_t | false |
Lib.Sequence.fst | Lib.Sequence.repeati_blocks_f | val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b | val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b | let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 171,
"start_col": 0,
"start_line": 168
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_nat{blocksize > 0} ->
inp: Lib.Sequence.seq a ->
f:
(
i: Prims.nat{i < Lib.Sequence.length inp / blocksize} ->
_: Lib.Sequence.lseq a blocksize ->
_: b
-> b) ->
nb: Prims.nat{nb == Lib.Sequence.length inp / blocksize} ->
i: Prims.nat{i < nb} ->
acc: b
-> b | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.Sequence.seq",
"Prims.nat",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.Sequence.lseq",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.op_Multiply",
"Lib.Sequence.seq_sub",
"FStar.Mul.op_Star",
"Prims.unit",
"Prims._assert",
"Prims.op_LessThanOrEqual"
] | [] | false | false | false | false | false | let repeati_blocks_f #a #b bs inp f nb i acc =
| assert ((i + 1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc | false |
Lib.Sequence.fst | Lib.Sequence.seq_update_sub | val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)} | val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)} | let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 156,
"start_col": 0,
"start_line": 150
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}). | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Lib.Sequence.seq a ->
start: Prims.nat ->
n: Prims.nat{start + n <= Lib.Sequence.length i} ->
x: Lib.Sequence.seq a {Lib.Sequence.length x == n}
-> o:
Lib.Sequence.seq a
{ Lib.Sequence.length o == Lib.Sequence.length i /\ Lib.Sequence.seq_sub o start n == x /\
(forall (k: Prims.nat{0 <= k /\ k < start \/ start + n <= k /\ k < Lib.Sequence.length i}).
{:pattern FStar.Seq.Base.index o k}
FStar.Seq.Base.index o k == FStar.Seq.Base.index i k) } | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.Sequence.length",
"Prims.eq2",
"Prims.unit",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"Prims.l_and",
"Prims.l_or",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.seq_sub"
] | [] | false | false | false | false | false | let seq_update_sub #a s start n x =
| let o = Seq.append (Seq.append (Seq.slice s 0 start) x) (Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload' | val gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot
(gaccessor' (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)) | val gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot
(gaccessor' (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)) | let gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= fun (input: bytes) ->
match parse (parse_ifthenelse p) input with
| Some (x, _) ->
if p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) = b
then gaccessor_ifthenelse_payload'' s b input
else 0 (* dummy *)
| _ -> 0 | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 205,
"start_col": 0,
"start_line": 194
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos
let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
}
let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input
))
(ensures (fun res ->
gaccessor_post' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input res
))
= parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p -> b: Prims.bool
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser p b))
(LowParse.Low.IfThenElse.clens_ifthenelse_payload s b) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.bool",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Spec.Base.consumed_length",
"Prims.op_Equality",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"FStar.Pervasives.dfst",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_recip",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload''",
"Prims.nat",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Low.IfThenElse.clens_ifthenelse_payload"
] | [] | false | false | false | false | false | let gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot
(gaccessor' (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)) =
| fun (input: bytes) ->
match parse (parse_ifthenelse p) input with
| Some (x, _) ->
if p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) = b
then gaccessor_ifthenelse_payload'' s b input
else 0
| _ -> 0 | false |
Lib.Sequence.fst | Lib.Sequence.repeati_blocks | val repeati_blocks:
#a:Type0
-> #b:Type0
-> blocksize:size_pos
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> l:(i:nat{i == length inp / blocksize} -> len:size_nat{len == length inp % blocksize} -> s:lseq a len -> b -> b)
-> init:b ->
Tot b | val repeati_blocks:
#a:Type0
-> #b:Type0
-> blocksize:size_pos
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> l:(i:nat{i == length inp / blocksize} -> len:size_nat{len == length inp % blocksize} -> s:lseq a len -> b -> b)
-> init:b ->
Tot b | let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 179,
"start_col": 0,
"start_line": 173
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
inp: Lib.Sequence.seq a ->
f:
(
i: Prims.nat{i < Lib.Sequence.length inp / blocksize} ->
_: Lib.Sequence.lseq a blocksize ->
_: b
-> b) ->
l:
(
i: Prims.nat{i == Lib.Sequence.length inp / blocksize} ->
len: Lib.IntTypes.size_nat{len == Lib.Sequence.length inp % blocksize} ->
s: Lib.Sequence.lseq a len ->
_: b
-> b) ->
init: b
-> b | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_pos",
"Lib.Sequence.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.Sequence.lseq",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.size_nat",
"Prims.op_Modulus",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.op_Multiply",
"Lib.Sequence.seq_sub",
"FStar.Mul.op_Star",
"Lib.LoopCombinators.repeati",
"Lib.Sequence.repeati_blocks_f"
] | [] | false | false | false | false | false | let repeati_blocks #a #b bs inp f g init =
| let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.valid_ifthenelse_elim | val valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_ifthenelse p) h sl pos))
(ensures
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos (parse_ifthenelse p)
h
sl
pos
(p.parse_ifthenelse_synth t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t))
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))) | val valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_ifthenelse p) h sl pos))
(ensures
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos (parse_ifthenelse p)
h
sl
pos
(p.parse_ifthenelse_synth t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t))
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))) | let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 75,
"end_line": 76,
"start_col": 0,
"start_line": 48
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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.IfThenElse.parse_ifthenelse_param ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires LowParse.Low.Base.Spec.valid (LowParse.Spec.IfThenElse.parse_ifthenelse p) h sl pos)
(ensures
LowParse.Low.Base.Spec.valid (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p)
h
sl
pos /\
(let t =
LowParse.Low.Base.Spec.contents (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p
)
h
sl
pos
in
let pos_after_t =
LowParse.Low.Base.Spec.get_valid_pos (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser
p)
h
sl
pos
in
let b = Mkparse_ifthenelse_param?.parse_ifthenelse_tag_cond p t in
LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.IfThenElse.parse_ifthenelse p)
h
sl
pos
(Mkparse_ifthenelse_param?.parse_ifthenelse_synth p
t
(LowParse.Low.Base.Spec.contents (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t))
(LowParse.Low.Base.Spec.get_valid_pos (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid_facts",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"Prims.bool",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Low.Base.Spec.contents",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.unit",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_ifthenelse p) h sl pos))
(ensures
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos (parse_ifthenelse p)
h
sl
pos
(p.parse_ifthenelse_synth t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t))
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))) =
| valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.valid_ifthenelse_intro | val valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))
(ensures
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos (parse_ifthenelse p)
h
sl
pos
(p.parse_ifthenelse_synth t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t))
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))) | val valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))
(ensures
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos (parse_ifthenelse p)
h
sl
pos
(p.parse_ifthenelse_synth t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t))
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))) | let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos) | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 46,
"start_col": 0,
"start_line": 12
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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.IfThenElse.parse_ifthenelse_param ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p)
h
sl
pos /\
(let t =
LowParse.Low.Base.Spec.contents (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p
)
h
sl
pos
in
let pos_after_t =
LowParse.Low.Base.Spec.get_valid_pos (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser
p)
h
sl
pos
in
let b = Mkparse_ifthenelse_param?.parse_ifthenelse_tag_cond p t in
LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t))
(ensures
LowParse.Low.Base.Spec.valid (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p)
h
sl
pos /\
(let t =
LowParse.Low.Base.Spec.contents (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p
)
h
sl
pos
in
let b = Mkparse_ifthenelse_param?.parse_ifthenelse_tag_cond p t in
let pos_after_t =
LowParse.Low.Base.Spec.get_valid_pos (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser
p)
h
sl
pos
in
LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.IfThenElse.parse_ifthenelse p)
h
sl
pos
(Mkparse_ifthenelse_param?.parse_ifthenelse_synth p
t
(LowParse.Low.Base.Spec.contents (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t))
(LowParse.Low.Base.Spec.get_valid_pos (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
h
sl
pos_after_t))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"LowParse.Slice.bytes_of_slice_from",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"Prims.bool",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Low.Base.Spec.contents",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))
(ensures
(valid p.parse_ifthenelse_tag_parser h sl pos /\
(let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos (parse_ifthenelse p)
h
sl
pos
(p.parse_ifthenelse_synth t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t))
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)))) =
| valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos) | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload_injective | val gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl' /\ injective_precond (parse_ifthenelse p) sl sl'))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl')) | val gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl' /\ injective_precond (parse_ifthenelse p) sl sl'))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl')) | let gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
injective_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_injective p.parse_ifthenelse_tag_parser sl sl' | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 223,
"start_col": 0,
"start_line": 207
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos
let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
}
let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input
))
(ensures (fun res ->
gaccessor_post' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input res
))
= parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed
let gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= fun (input: bytes) ->
match parse (parse_ifthenelse p) input with
| Some (x, _) ->
if p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) = b
then gaccessor_ifthenelse_payload'' s b input
else 0 (* dummy *)
| _ -> 0 (* dummy *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p ->
b: Prims.bool ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser p b))
(LowParse.Low.IfThenElse.clens_ifthenelse_payload s b)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser p b))
(LowParse.Low.IfThenElse.clens_ifthenelse_payload s b)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.IfThenElse.parse_ifthenelse p) sl sl')
(ensures
LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload' s b sl ==
LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload' s b sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.bool",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"Prims.unit",
"LowParse.Spec.IfThenElse.parse_ifthenelse_parse_tag_payload",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"Prims.l_and",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Low.IfThenElse.clens_ifthenelse_payload",
"LowParse.Spec.Base.injective_precond",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl' /\ injective_precond (parse_ifthenelse p) sl sl'))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl')) =
| parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl';
parse_injective p.parse_ifthenelse_tag_parser sl sl' | false |
Lib.Sequence.fst | Lib.Sequence.repeat_blocks | val repeat_blocks:
#a:Type0
-> #b:Type0
-> #c:Type0
-> blocksize:size_pos
-> inp:seq a
-> f:(lseq a blocksize -> b -> b)
-> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c)
-> init:b ->
Tot c | val repeat_blocks:
#a:Type0
-> #b:Type0
-> #c:Type0
-> blocksize:size_pos
-> inp:seq a
-> f:(lseq a blocksize -> b -> b)
-> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c)
-> init:b ->
Tot c | let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 187,
"start_col": 0,
"start_line": 181
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
inp: Lib.Sequence.seq a ->
f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) ->
l: (len: Prims.nat{len < blocksize} -> s: Lib.Sequence.lseq a len -> _: b -> c) ->
init: b
-> c | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_pos",
"Lib.Sequence.seq",
"Lib.Sequence.lseq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.l_Forall",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.op_Multiply",
"Lib.Sequence.seq_sub",
"FStar.Mul.op_Star",
"Lib.LoopCombinators.repeati",
"Lib.Sequence.repeat_blocks_f",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Division"
] | [] | false | false | false | false | false | let repeat_blocks #a #b #c bs inp f l init =
| let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload | val gaccessor_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot
(gaccessor (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)) | val gaccessor_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot
(gaccessor (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)) | let gaccessor_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_ifthenelse_payload_injective s b x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_ifthenelse_payload_no_lookahead s b x));
gaccessor_prop_equiv (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) (gaccessor_ifthenelse_payload' s b);
gaccessor_ifthenelse_payload' s b | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 35,
"end_line": 253,
"start_col": 0,
"start_line": 245
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos
let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
}
let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input
))
(ensures (fun res ->
gaccessor_post' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input res
))
= parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed
let gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= fun (input: bytes) ->
match parse (parse_ifthenelse p) input with
| Some (x, _) ->
if p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) = b
then gaccessor_ifthenelse_payload'' s b input
else 0 (* dummy *)
| _ -> 0 (* dummy *)
let gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
injective_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_injective p.parse_ifthenelse_tag_parser sl sl'
let gaccessor_ifthenelse_payload_no_lookahead
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
(parse_ifthenelse_kind p).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
no_lookahead_on_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_strong_prefix (parse_ifthenelse p) sl sl';
parse_injective p.parse_ifthenelse_tag_parser sl sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p -> b: Prims.bool
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser p b))
(LowParse.Low.IfThenElse.clens_ifthenelse_payload s b) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.bool",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Low.IfThenElse.clens_ifthenelse_payload",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.nat",
"FStar.Classical.move_requires",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload_no_lookahead",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload_injective",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | false | false | false | false | false | let gaccessor_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot
(gaccessor (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)) =
| Classical.forall_intro_2 (fun x ->
Classical.move_requires (gaccessor_ifthenelse_payload_injective s b x));
Classical.forall_intro_2 (fun x ->
Classical.move_requires (gaccessor_ifthenelse_payload_no_lookahead s b x));
gaccessor_prop_equiv (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
(gaccessor_ifthenelse_payload' s b);
gaccessor_ifthenelse_payload' s b | false |
Lib.Sequence.fst | Lib.Sequence.lemma_update_sub | val lemma_update_sub:
#a:Type
-> #len:size_nat
-> dst:lseq a len
-> start:size_nat
-> n:size_nat{start + n <= len}
-> src:lseq a n
-> res:lseq a len ->
Lemma
(requires
sub res 0 start == sub dst 0 start /\
sub res start n == src /\
sub res (start + n) (len - start - n) ==
sub dst (start + n) (len - start - n))
(ensures
res == update_sub dst start n src) | val lemma_update_sub:
#a:Type
-> #len:size_nat
-> dst:lseq a len
-> start:size_nat
-> n:size_nat{start + n <= len}
-> src:lseq a n
-> res:lseq a len ->
Lemma
(requires
sub res 0 start == sub dst 0 start /\
sub res start n == src /\
sub res (start + n) (len - start - n) ==
sub dst (start + n) (len - start - n))
(ensures
res == update_sub dst start n src) | let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 55,
"start_col": 0,
"start_line": 49
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Lib.Sequence.lseq a len ->
start: Lib.IntTypes.size_nat ->
n: Lib.IntTypes.size_nat{start + n <= len} ->
src: Lib.Sequence.lseq a n ->
res: Lib.Sequence.lseq a len
-> FStar.Pervasives.Lemma
(requires
Lib.Sequence.sub res 0 start == Lib.Sequence.sub dst 0 start /\
Lib.Sequence.sub res start n == src /\
Lib.Sequence.sub res (start + n) (len - start - n) ==
Lib.Sequence.sub dst (start + n) (len - start - n))
(ensures res == Lib.Sequence.update_sub dst start n src) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Lib.Sequence.lseq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.lemma_eq_intro",
"Lib.Sequence.update_sub",
"Prims.unit",
"FStar.Seq.Properties.lemma_split",
"Lib.Sequence.sub",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index"
] | [] | true | false | true | false | false | let lemma_update_sub #a #len dst start n src res =
| let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src) | false |
Lib.Sequence.fst | Lib.Sequence.generate_blocks_inner | val generate_blocks_inner
(t: Type)
(blocklen: size_nat)
(max: nat)
(a: (i: nat{i <= max} -> Type))
(f: (i: nat{i < max} -> a i -> a (i + 1) & s: seq t {length s == blocklen}))
(i: nat{i < max})
(acc: generate_blocks_a t blocklen max a i)
: generate_blocks_a t blocklen max a (i + 1) | val generate_blocks_inner
(t: Type)
(blocklen: size_nat)
(max: nat)
(a: (i: nat{i <= max} -> Type))
(f: (i: nat{i < max} -> a i -> a (i + 1) & s: seq t {length s == blocklen}))
(i: nat{i < max})
(acc: generate_blocks_a t blocklen max a i)
: generate_blocks_a t blocklen max a (i + 1) | let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o' | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 12,
"end_line": 204,
"start_col": 0,
"start_line": 200
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Type0 ->
blocklen: Lib.IntTypes.size_nat ->
max: Prims.nat ->
a: (i: Prims.nat{i <= max} -> Type) ->
f:
(i: Prims.nat{i < max} -> _: a i
-> a (i + 1) * s: Lib.Sequence.seq t {Lib.Sequence.length s == blocklen}) ->
i: Prims.nat{i < max} ->
acc: Lib.Sequence.generate_blocks_a t blocklen max a i
-> Lib.Sequence.generate_blocks_a t blocklen max a (i + 1) | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"Lib.Sequence.generate_blocks_a",
"Prims.int",
"FStar.Mul.op_Star",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Multiply",
"FStar.Seq.Base.append"
] | [] | false | false | false | false | false | let generate_blocks_inner
(t: Type)
(blocklen: size_nat)
(max: nat)
(a: (i: nat{i <= max} -> Type))
(f: (i: nat{i < max} -> a i -> a (i + 1) & s: seq t {length s == blocklen}))
(i: nat{i < max})
(acc: generate_blocks_a t blocklen max a i)
: generate_blocks_a t blocklen max a (i + 1) =
| let acc, o = acc in
let acc', block = f i acc in
let o':s: seq t {length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o' | false |
Lib.Sequence.fst | Lib.Sequence.mod_div_lt | val mod_div_lt: b:pos -> i:int -> j:int -> Lemma
(requires (j / b) * b <= i /\ i < j)
(ensures i % b < j % b) | val mod_div_lt: b:pos -> i:int -> j:int -> Lemma
(requires (j / b) * b <= i /\ i < j)
(ensures i % b < j % b) | let mod_div_lt b i j =
mod_interval_lt b (j / b) i j | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 238,
"start_col": 0,
"start_line": 237
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Prims.pos -> i: Prims.int -> j: Prims.int
-> FStar.Pervasives.Lemma (requires (j / b) * b <= i /\ i < j) (ensures i % b < j % b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.int",
"Lib.Sequence.mod_interval_lt",
"Prims.op_Division",
"Prims.unit"
] | [] | true | false | true | false | false | let mod_div_lt b i j =
| mod_interval_lt b (j / b) i j | false |
Lib.Sequence.fst | Lib.Sequence.generate_blocks | val generate_blocks:
#t:Type0
-> len:size_nat
-> max:nat
-> n:nat{n <= max}
-> a:(i:nat{i <= max} -> Type)
-> f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == len})
-> init:a 0 ->
Tot (a n & s:seq t{length s == n * len}) | val generate_blocks:
#t:Type0
-> len:size_nat
-> max:nat
-> n:nat{n <= max}
-> a:(i:nat{i <= max} -> Type)
-> f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == len})
-> init:a 0 ->
Tot (a n & s:seq t{length s == n * len}) | let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0 | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 208,
"start_col": 0,
"start_line": 206
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat ->
max: Prims.nat ->
n: Prims.nat{n <= max} ->
a: (i: Prims.nat{i <= max} -> Type) ->
f:
(i: Prims.nat{i < max} -> _: a i
-> a (i + 1) * s: Lib.Sequence.seq t {Lib.Sequence.length s == len}) ->
init: a 0
-> a n * s: Lib.Sequence.seq t {Lib.Sequence.length s == n * len} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"Lib.LoopCombinators.repeat_gen",
"Lib.Sequence.generate_blocks_a",
"Lib.Sequence.generate_blocks_inner",
"Prims.int",
"Prims.op_Multiply",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Mul.op_Star",
"FStar.Seq.Base.empty"
] | [] | false | false | false | false | false | let generate_blocks #t len max n a f acc0 =
| let a0 = (acc0, (Seq.empty <: s: seq t {length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0 | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_tag' | val gaccessor_ifthenelse_tag' (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s)) | val gaccessor_ifthenelse_tag' (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s)) | let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0 | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 148,
"start_col": 0,
"start_line": 140
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p)
(LowParse.Low.IfThenElse.clens_ifthenelse_tag s) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Bytes.bytes",
"Prims.unit",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Spec.IfThenElse.parse_ifthenelse_parse_tag_payload",
"Prims.bool",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"Prims.nat",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.IfThenElse.clens_ifthenelse_tag"
] | [] | false | false | false | false | false | let gaccessor_ifthenelse_tag' (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s)) =
| fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input) then parse_ifthenelse_parse_tag_payload s input;
0 | false |
Lib.Sequence.fst | Lib.Sequence.generate_blocks_simple | val generate_blocks_simple:
#a:Type0
-> blocksize:size_pos
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> lseq a blocksize) ->
Tot (s:seq a{length s == n * blocksize}) | val generate_blocks_simple:
#a:Type0
-> blocksize:size_pos
-> max:nat
-> n:nat{n <= max}
-> f:(i:nat{i < max} -> lseq a blocksize) ->
Tot (s:seq a{length s == n * blocksize}) | let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 224,
"start_col": 0,
"start_line": 222
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
max: Prims.nat ->
n: Prims.nat{n <= max} ->
f: (i: Prims.nat{i < max} -> Lib.Sequence.lseq a blocksize)
-> s: Lib.Sequence.seq a {Lib.Sequence.length s == n * blocksize} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.LoopCombinators.repeat_gen",
"Lib.Sequence.generate_blocks_simple_a",
"Lib.Sequence.generate_blocks_simple_f",
"FStar.Seq.Base.empty",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | false | let generate_blocks_simple #a bs max nb f =
| repeat_gen nb (generate_blocks_simple_a a bs max) (generate_blocks_simple_f #a bs max f) Seq.empty | false |
Lib.Sequence.fst | Lib.Sequence.repeat_blocks_multi | val repeat_blocks_multi:
#a:Type0
-> #b:Type0
-> blocksize:size_pos
-> inp:seq a{length inp % blocksize = 0}
-> f:(lseq a blocksize -> b -> b)
-> init:b ->
Tot b | val repeat_blocks_multi:
#a:Type0
-> #b:Type0
-> blocksize:size_pos
-> inp:seq a{length inp % blocksize = 0}
-> f:(lseq a blocksize -> b -> b)
-> init:b ->
Tot b | let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 194,
"start_col": 0,
"start_line": 191
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
inp: Lib.Sequence.seq a {Lib.Sequence.length inp % blocksize = 0} ->
f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) ->
init: b
-> b | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_pos",
"Lib.Sequence.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Sequence.length",
"Lib.Sequence.lseq",
"Lib.LoopCombinators.repeati",
"Lib.Sequence.repeat_blocks_f",
"Prims.op_Division",
"Prims.nat"
] | [] | false | false | false | false | false | let repeat_blocks_multi #a #b bs inp f init =
| let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init | false |
Lib.Sequence.fst | Lib.Sequence.map_blocks_multi | val map_blocks_multi:
#a:Type0
-> blocksize:size_pos
-> max:nat
-> n:nat{n <= max}
-> inp:seq a{length inp == max * blocksize}
-> f:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) ->
Tot (out:seq a {length out == n * blocksize}) | val map_blocks_multi:
#a:Type0
-> blocksize:size_pos
-> max:nat
-> n:nat{n <= max}
-> inp:seq a{length inp == max * blocksize}
-> f:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) ->
Tot (out:seq a {length out == n * blocksize}) | let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 258,
"start_col": 0,
"start_line": 256
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
max: Prims.nat ->
n: Prims.nat{n <= max} ->
inp: Lib.Sequence.seq a {Lib.Sequence.length inp == max * blocksize} ->
f: (i: Prims.nat{i < max} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize)
-> out: Lib.Sequence.seq a {Lib.Sequence.length out == n * blocksize} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.LoopCombinators.repeat_gen",
"Lib.Sequence.map_blocks_a",
"Lib.Sequence.map_blocks_f",
"FStar.Seq.Base.empty"
] | [] | false | false | false | false | false | let map_blocks_multi #a bs max nb inp f =
| repeat_gen nb (map_blocks_a a bs max) (map_blocks_f #a bs max inp f) Seq.empty | false |
Lib.Sequence.fst | Lib.Sequence.div_interval | val div_interval: b:pos -> n:int -> i:int -> Lemma
(requires n * b <= i /\ i < (n + 1) * b)
(ensures i / b = n) | val div_interval: b:pos -> n:int -> i:int -> Lemma
(requires n * b <= i /\ i < (n + 1) * b)
(ensures i / b = n) | let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 229,
"start_col": 0,
"start_line": 227
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Prims.pos -> n: Prims.int -> i: Prims.int
-> FStar.Pervasives.Lemma (requires n * b <= i /\ i < (n + 1) * b) (ensures i / b = n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.int",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.unit",
"FStar.Math.Lemmas.lemma_div_le",
"FStar.Mul.op_Star"
] | [] | true | false | true | false | false | let div_interval b n i =
| Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b | false |
Lib.Sequence.fst | Lib.Sequence.generate_blocks_simple_f | val generate_blocks_simple_f
(#a: Type)
(bs: size_nat{bs > 0})
(max: nat)
(f: (i: nat{i < max} -> lseq a bs))
(i: nat{i < max})
(acc: generate_blocks_simple_a a bs max i)
: generate_blocks_simple_a a bs max (i + 1) | val generate_blocks_simple_f
(#a: Type)
(bs: size_nat{bs > 0})
(max: nat)
(f: (i: nat{i < max} -> lseq a bs))
(i: nat{i < max})
(acc: generate_blocks_simple_a a bs max i)
: generate_blocks_simple_a a bs max (i + 1) | let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i) | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 220,
"start_col": 0,
"start_line": 212
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bs: Lib.IntTypes.size_nat{bs > 0} ->
max: Prims.nat ->
f: (i: Prims.nat{i < max} -> Lib.Sequence.lseq a bs) ->
i: Prims.nat{i < max} ->
acc: Lib.Sequence.generate_blocks_simple_a a bs max i
-> Lib.Sequence.generate_blocks_simple_a a bs max (i + 1) | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.Sequence.generate_blocks_simple_a",
"FStar.Seq.Base.append",
"Prims.op_Addition"
] | [] | false | false | false | false | false | let generate_blocks_simple_f
(#a: Type)
(bs: size_nat{bs > 0})
(max: nat)
(f: (i: nat{i < max} -> lseq a bs))
(i: nat{i < max})
(acc: generate_blocks_simple_a a bs max i)
: generate_blocks_simple_a a bs max (i + 1) =
| Seq.append acc (f i) | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.base_array_index_t | val base_array_index_t (n: array_size_t) : Tot eqtype | val base_array_index_t (n: array_size_t) : Tot eqtype | let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 15,
"start_col": 0,
"start_line": 14
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Pulse.C.Types.Array.array_size_t -> Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Array.array_size_t",
"Pulse.C.Types.Array.Base.array_domain",
"FStar.Ghost.hide",
"FStar.SizeT.t",
"Prims.eqtype"
] | [] | false | false | false | true | false | let base_array_index_t (n: array_size_t) : Tot eqtype =
| Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) | false |
Lib.Sequence.fst | Lib.Sequence.mod_interval_lt | val mod_interval_lt: b:pos -> n:int -> i:int -> j:int -> Lemma
(requires n * b <= i /\ i < j /\ j < (n + 1) * b)
(ensures i % b < j % b) | val mod_interval_lt: b:pos -> n:int -> i:int -> j:int -> Lemma
(requires n * b <= i /\ i < j /\ j < (n + 1) * b)
(ensures i % b < j % b) | let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 233,
"start_col": 0,
"start_line": 231
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Prims.pos -> n: Prims.int -> i: Prims.int -> j: Prims.int
-> FStar.Pervasives.Lemma (requires n * b <= i /\ i < j /\ j < (n + 1) * b)
(ensures i % b < j % b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.int",
"Lib.Sequence.div_interval",
"Prims.unit"
] | [] | true | false | true | false | false | let mod_interval_lt b n i j =
| div_interval b n i;
div_interval b n j | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.accessor_ifthenelse_payload' | val accessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(j: jumper p.parse_ifthenelse_tag_parser)
(b: bool)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
valid (parse_ifthenelse p) h input pos /\
(clens_ifthenelse_payload s b).clens_cond (contents (parse_ifthenelse p) h input pos)))
(ensures
(fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h (gaccessor_ifthenelse_payload s b) input pos)) | val accessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(j: jumper p.parse_ifthenelse_tag_parser)
(b: bool)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
valid (parse_ifthenelse p) h input pos /\
(clens_ifthenelse_payload s b).clens_cond (contents (parse_ifthenelse p) h input pos)))
(ensures
(fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h (gaccessor_ifthenelse_payload s b) input pos)) | let accessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(j: jumper p.parse_ifthenelse_tag_parser)
(b: bool)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid (parse_ifthenelse p) h input pos /\
(clens_ifthenelse_payload s b).clens_cond (contents (parse_ifthenelse p) h input pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h (gaccessor_ifthenelse_payload s b) input pos
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos' = get_valid_pos (parse_ifthenelse p) h input pos in
let large = bytes_of_slice_from h input pos in
slice_access_eq h (gaccessor_ifthenelse_payload s b) input pos;
valid_facts (parse_ifthenelse p) h input pos;
parse_ifthenelse_eq p large;
valid_facts p.parse_ifthenelse_tag_parser h input pos
in
j input pos | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 283,
"start_col": 0,
"start_line": 256
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos
let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
}
let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input
))
(ensures (fun res ->
gaccessor_post' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input res
))
= parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed
let gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= fun (input: bytes) ->
match parse (parse_ifthenelse p) input with
| Some (x, _) ->
if p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) = b
then gaccessor_ifthenelse_payload'' s b input
else 0 (* dummy *)
| _ -> 0 (* dummy *)
let gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
injective_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_injective p.parse_ifthenelse_tag_parser sl sl'
let gaccessor_ifthenelse_payload_no_lookahead
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
(parse_ifthenelse_kind p).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
no_lookahead_on_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_strong_prefix (parse_ifthenelse p) sl sl';
parse_injective p.parse_ifthenelse_tag_parser sl sl'
let gaccessor_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_ifthenelse_payload_injective s b x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_ifthenelse_payload_no_lookahead s b x));
gaccessor_prop_equiv (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) (gaccessor_ifthenelse_payload' s b);
gaccessor_ifthenelse_payload' s b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p ->
j: LowParse.Low.Base.jumper (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p) ->
b: Prims.bool ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Low.Base.jumper",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"Prims.bool",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Low.Base.Spec.slice_access_eq",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Low.IfThenElse.clens_ifthenelse_payload",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload",
"LowParse.Bytes.bytes",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.get_valid_pos",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.__proj__Mkclens__item__clens_cond",
"LowParse.Low.Base.Spec.contents",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.slice_access"
] | [] | false | true | false | false | false | let accessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(j: jumper p.parse_ifthenelse_tag_parser)
(b: bool)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
valid (parse_ifthenelse p) h input pos /\
(clens_ifthenelse_payload s b).clens_cond (contents (parse_ifthenelse p) h input pos)))
(ensures
(fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h (gaccessor_ifthenelse_payload s b) input pos)) =
| let h = HST.get () in
[@@ inline_let ]let _ =
let pos' = get_valid_pos (parse_ifthenelse p) h input pos in
let large = bytes_of_slice_from h input pos in
slice_access_eq h (gaccessor_ifthenelse_payload s b) input pos;
valid_facts (parse_ifthenelse p) h input pos;
parse_ifthenelse_eq p large;
valid_facts p.parse_ifthenelse_tag_parser h input pos
in
j input pos | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.accessor_ifthenelse_tag | val accessor_ifthenelse_tag (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s)) | val accessor_ifthenelse_tag (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s)) | let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 165,
"start_col": 0,
"start_line": 158
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p
-> LowParse.Low.Base.accessor (LowParse.Low.IfThenElse.gaccessor_ifthenelse_tag s) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.IfThenElse.clens_ifthenelse_tag",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_tag",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | false | false | false | false | false | let accessor_ifthenelse_tag (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s)) =
| fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos | false |
Lib.Sequence.fst | Lib.Sequence.mod_prop | val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n) | val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n) | let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 267,
"start_col": 0,
"start_line": 265
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "Lib.IntTypes",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.pos -> a: Prims.nat -> b: Prims.nat{a * n <= b /\ b < (a + 1) * n}
-> FStar.Pervasives.Lemma (ensures b - a * n == b % n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Math.Lemmas.lemma_mod_sub",
"Prims.unit",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.op_Subtraction"
] | [] | true | false | true | false | false | let mod_prop n a b =
| Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_ptr | val array_ptr : td: Pulse.C.Types.Base.typedef t -> Type0 | let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 169,
"start_col": 0,
"start_line": 169
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_ptr_gen"
] | [] | false | false | false | true | true | let array_ptr (#t: Type) (td: typedef t) =
| array_ptr_gen t | false |
|
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_size_t | val array_size_t : Type0 | let array_size_t = (n: SZ.t { SZ.v n > 0 }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 11,
"start_col": 0,
"start_line": 11
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.SizeT.v"
] | [] | false | false | false | true | true | let array_size_t =
| (n: SZ.t{SZ.v n > 0}) | false |
|
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_ptr_gen | val array_ptr_gen ([@@@ unused]t: Type0) : Tot Type0 | val array_ptr_gen ([@@@ unused]t: Type0) : Tot Type0 | let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 167,
"start_col": 0,
"start_line": 167
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Array.array_void_ptr"
] | [] | false | false | false | true | true | let array_ptr_gen ([@@@ unused]t: Type0) : Tot Type0 =
| array_void_ptr | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.validate_ifthenelse | val validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b)))))
: Tot (validator (parse_ifthenelse p)) | val validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b)))))
: Tot (validator (parse_ifthenelse p)) | let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 35,
"end_line": 111,
"start_col": 0,
"start_line": 92
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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.IfThenElse.parse_ifthenelse_param ->
vt: LowParse.Low.Base.validator (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p) ->
test: LowParse.Low.IfThenElse.test_ifthenelse_tag p ->
vp:
(b: Prims.bool
-> LowParse.Low.Base.validator (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b)))
-> LowParse.Low.Base.validator (LowParse.Spec.IfThenElse.parse_ifthenelse p) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Low.Base.validator",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Low.IfThenElse.test_ifthenelse_tag",
"Prims.bool",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"Prims.unit",
"FStar.Classical.move_requires",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.l_and",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"LowParse.Low.IfThenElse.valid_ifthenelse_elim",
"LowParse.Low.IfThenElse.valid_ifthenelse_intro",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b)))))
: Tot (validator (parse_ifthenelse p)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b then vp true input pos_after_t else vp false input pos_after_t | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_ref | val array_ref : td: Pulse.C.Types.Base.typedef t -> Type0 | let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 95,
"end_line": 178,
"start_col": 0,
"start_line": 178
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_ptr",
"Prims.eq2",
"Prims.bool",
"Pulse.C.Types.Array.g_array_ptr_is_null"
] | [] | false | false | false | true | true | let array_ref (#t: Type) (td: typedef t) =
| (a: array_ptr td {g_array_ptr_is_null a == false}) | false |
|
Lib.Sequence.fst | Lib.Sequence.map_blocks | val map_blocks:
#a:Type0
-> blocksize:size_pos
-> inp:seq a
-> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize)
-> g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) ->
Tot (out:seq a{length out == length inp}) | val map_blocks:
#a:Type0
-> blocksize:size_pos
-> inp:seq a
-> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize)
-> g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) ->
Tot (out:seq a{length out == length inp}) | let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 298,
"start_col": 0,
"start_line": 289
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
inp: Lib.Sequence.seq a ->
f:
(_: Lib.Sequence.block (Lib.Sequence.length inp) blocksize -> _: Lib.Sequence.lseq a blocksize
-> Lib.Sequence.lseq a blocksize) ->
g:
(
_: Lib.Sequence.last (Lib.Sequence.length inp) blocksize ->
rem: Lib.IntTypes.size_nat{rem < blocksize} ->
s: Lib.Sequence.lseq a rem
-> Lib.Sequence.lseq a rem)
-> out: Lib.Sequence.seq a {Lib.Sequence.length out == Lib.Sequence.length inp} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_pos",
"Lib.Sequence.seq",
"Lib.Sequence.block",
"Lib.Sequence.length",
"Lib.Sequence.lseq",
"Lib.Sequence.last",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_GreaterThan",
"FStar.Seq.Base.append",
"Prims.bool",
"Prims.eq2",
"Prims.nat",
"Prims.int",
"Prims.op_Multiply",
"Lib.Sequence.map_blocks_multi",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.op_Division"
] | [] | false | false | false | false | false | let map_blocks #a blocksize inp f g =
| let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then Seq.append bs (g nb rem last) else bs | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_len_t | val array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 | val array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 | let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 205,
"start_col": 0,
"start_line": 204
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: Pulse.C.Types.Array.array_ptr td -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_ptr",
"FStar.Ghost.erased",
"FStar.SizeT.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.SizeT.v",
"Pulse.C.Types.Array.array_ref_offset",
"FStar.Ghost.reveal",
"Pulse.C.Types.Array.array_ref_base_size"
] | [] | false | false | false | false | true | let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
| (len: Ghost.erased SZ.t {SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r)}) | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array | val array (#t: Type) (td: typedef t) : Tot Type0 | val array (#t: Type) (td: typedef t) : Tot Type0 | let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 103,
"end_line": 227,
"start_col": 0,
"start_line": 227
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a
inline_for_extraction [@@noextract_to "krml"]
let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |)
let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
g_array_ptr_is_null (array_ptr_of a) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_or_null",
"Prims.eq2",
"Prims.bool",
"Pulse.C.Types.Array.g_array_is_null"
] | [] | false | false | false | true | true | let array (#t: Type) (td: typedef t) : Tot Type0 =
| (a: array_or_null td {g_array_is_null a == false}) | false |
Lib.Sequence.fst | Lib.Sequence.unfold_generate_blocks | val unfold_generate_blocks:
#t:Type0
-> len:size_nat
-> n:nat
-> a:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < n} -> a i -> a (i + 1) & s:seq t{length s == len})
-> init:a 0
-> i:nat{i < n} ->
Lemma (generate_blocks #t len n (i+1) a f init ==
(let (acc,s) = generate_blocks #t len n i a f init in
let (acc',s') = f i acc in
(acc',Seq.append s s'))) | val unfold_generate_blocks:
#t:Type0
-> len:size_nat
-> n:nat
-> a:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < n} -> a i -> a (i + 1) & s:seq t{length s == len})
-> init:a 0
-> i:nat{i < n} ->
Lemma (generate_blocks #t len n (i+1) a f init ==
(let (acc,s) = generate_blocks #t len n i a f init in
let (acc',s') = f i acc in
(acc',Seq.append s s'))) | let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 346,
"start_col": 0,
"start_line": 342
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat ->
n: Prims.nat ->
a: (i: Prims.nat{i <= n} -> Type) ->
f:
(i: Prims.nat{i < n} -> _: a i
-> a (i + 1) * s: Lib.Sequence.seq t {Lib.Sequence.length s == len}) ->
init: a 0 ->
i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
Lib.Sequence.generate_blocks len n (i + 1) a f init ==
(let _ = Lib.Sequence.generate_blocks len n i a f init in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ acc s = _ in
let _ = f i acc in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ acc' s' = _ in
acc', FStar.Seq.Base.append s s')
<:
a (i + 1) * s: Lib.Sequence.seq t {Lib.Sequence.length s == (i + 1) * len})
<:
a (i + 1) * s: Lib.Sequence.seq t {Lib.Sequence.length s == (i + 1) * len})) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"Lib.LoopCombinators.unfold_repeat_gen",
"Lib.Sequence.generate_blocks_a",
"Lib.Sequence.generate_blocks_inner",
"Prims.unit",
"Prims._assert",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.Sequence.generate_blocks",
"Lib.LoopCombinators.repeat_gen",
"Prims.op_Multiply",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.empty"
] | [] | true | false | true | false | false | let unfold_generate_blocks #t len n a f acc0 i =
| let a0 = (acc0, (Seq.empty <: s: seq t {length s == 0 * len})) in
assert (generate_blocks #t len n (i + 1) a f acc0 ==
repeat_gen (i + 1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i + 1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_ptr_of | val array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) | val array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) | let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 213,
"start_col": 0,
"start_line": 211
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ar: Pulse.C.Types.Array.array_or_null td -> Pulse.C.Types.Array.array_ptr td | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_or_null",
"Pulse.C.Types.Array.array_ptr",
"Pulse.C.Types.Array.array_len_t"
] | [] | false | false | false | false | false | let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
| match ar with | (| a , _ |) -> a | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.null_array_ptr | val null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) | val null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) | let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 88,
"end_line": 173,
"start_col": 0,
"start_line": 173
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Pulse.C.Types.Array.array_ptr td | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.null_array_void_ptr",
"Pulse.C.Types.Array.array_ptr"
] | [] | false | false | false | false | false | let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) =
| null_array_void_ptr | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_or_null | val array_or_null (#t: Type) (td: typedef t) : Tot Type0 | val array_or_null (#t: Type) (td: typedef t) : Tot Type0 | let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 92,
"end_line": 208,
"start_col": 0,
"start_line": 208
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Prims.dtuple2",
"Pulse.C.Types.Array.array_ptr",
"Pulse.C.Types.Array.array_len_t"
] | [] | false | false | false | true | true | let array_or_null (#t: Type) (td: typedef t) : Tot Type0 =
| (r: array_ptr td & array_len_t r) | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.mk_array_or_null | val mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a)
: Tot (array_or_null td) | val mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a)
: Tot (array_or_null td) | let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 221,
"start_col": 0,
"start_line": 220
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: Pulse.C.Types.Array.array_ptr td -> len: Pulse.C.Types.Array.array_len_t a
-> Pulse.C.Types.Array.array_or_null td | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_ptr",
"Pulse.C.Types.Array.array_len_t",
"Prims.Mkdtuple2",
"Pulse.C.Types.Array.array_or_null"
] | [] | false | false | false | false | false | let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a)
: Tot (array_or_null td) =
| (| a, len |) | false |
Lib.Sequence.fst | Lib.Sequence.create2_lemma | val create2_lemma: #a:Type -> x0:a -> x1:a ->
Lemma (let s = create2 x0 x1 in
s.[0] == x0 /\ s.[1] == x1)
[SMTPat (create2 #a x0 x1)] | val create2_lemma: #a:Type -> x0:a -> x1:a ->
Lemma (let s = create2 x0 x1 in
s.[0] == x0 /\ s.[1] == x1)
[SMTPat (create2 #a x0 x1)] | let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1] | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 377,
"start_col": 0,
"start_line": 376
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a
-> FStar.Pervasives.Lemma
(ensures
(let s = Lib.Sequence.create2 x0 x1 in
s.[ 0 ] == x0 /\ s.[ 1 ] == x1)) [SMTPat (Lib.Sequence.create2 x0 x1)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Properties.elim_of_list",
"Prims.Cons",
"Prims.Nil",
"Prims.unit"
] | [] | true | false | true | false | false | let create2_lemma #a x0 x1 =
| Seq.elim_of_list [x0; x1] | false |
LowParse.Low.IfThenElse.fst | LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload_no_lookahead | val gaccessor_ifthenelse_payload_no_lookahead
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl': bytes)
: Lemma
(requires
((parse_ifthenelse_kind p).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl' /\ no_lookahead_on_precond (parse_ifthenelse p) sl sl'))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl')) | val gaccessor_ifthenelse_payload_no_lookahead
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl': bytes)
: Lemma
(requires
((parse_ifthenelse_kind p).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl' /\ no_lookahead_on_precond (parse_ifthenelse p) sl sl'))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl')) | let gaccessor_ifthenelse_payload_no_lookahead
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
(parse_ifthenelse_kind p).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
no_lookahead_on_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_strong_prefix (parse_ifthenelse p) sl sl';
parse_injective p.parse_ifthenelse_tag_parser sl sl' | {
"file_name": "src/lowparse/LowParse.Low.IfThenElse.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 243,
"start_col": 0,
"start_line": 225
} | module LowParse.Low.IfThenElse
include LowParse.Spec.IfThenElse
include LowParse.Low.Combinators
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_ifthenelse_intro
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
)))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos)
let valid_ifthenelse_elim
(p: parse_ifthenelse_param)
(h: HS.mem)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid (parse_ifthenelse p) h sl pos))
(ensures (
valid p.parse_ifthenelse_tag_parser h sl pos /\ (
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t /\
valid_content_pos
(parse_ifthenelse p) h sl pos
(p.parse_ifthenelse_synth
t
(contents (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)
(get_valid_pos (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t)
)))
= valid_facts (parse_ifthenelse p) h sl pos;
parse_ifthenelse_eq p (bytes_of_slice_from h sl pos);
valid_facts p.parse_ifthenelse_tag_parser h sl pos;
let pos_after_t = get_valid_pos p.parse_ifthenelse_tag_parser h sl pos in
let t = contents p.parse_ifthenelse_tag_parser h sl pos in
let b = p.parse_ifthenelse_tag_cond t in
valid_facts (dsnd (p.parse_ifthenelse_payload_parser b)) h sl pos_after_t
inline_for_extraction
type test_ifthenelse_tag
(p: parse_ifthenelse_param)
= (#rrel: _) -> (#rel: _) ->
(input: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p.parse_ifthenelse_tag_parser h input pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == p.parse_ifthenelse_tag_cond (contents p.parse_ifthenelse_tag_parser h input pos)
))
inline_for_extraction
let validate_ifthenelse
(p: parse_ifthenelse_param)
(vt: validator p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (validator (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (validator (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_intro p h input) (uint64_to_uint32 pos);
Classical.move_requires (valid_ifthenelse_elim p h input) (uint64_to_uint32 pos)
in
let pos_after_t = vt input pos in
if is_error pos_after_t
then pos_after_t
else
let b = test input (uint64_to_uint32 pos) in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
inline_for_extraction
let jump_ifthenelse
(p: parse_ifthenelse_param)
(vt: jumper p.parse_ifthenelse_tag_parser)
(test: test_ifthenelse_tag p)
(vp: (b: bool) -> Tot (jumper (dsnd (p.parse_ifthenelse_payload_parser b))))
: Tot (jumper (parse_ifthenelse p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_ifthenelse_elim p h input) pos
in
let pos_after_t = vt input pos in
let b = test input pos in
if b (* eta-expansion here *)
then vp true input pos_after_t
else vp false input pos_after_t
let clens_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (clens p.parse_ifthenelse_t p.parse_ifthenelse_tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dfst (s.serialize_ifthenelse_synth_recip x));
}
let gaccessor_ifthenelse_tag'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor' (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= fun input ->
parse_ifthenelse_eq p input;
if Some? (parse (parse_ifthenelse p) input)
then parse_ifthenelse_parse_tag_payload s input;
0
let gaccessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (gaccessor (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s))
= gaccessor_prop_equiv (parse_ifthenelse p) p.parse_ifthenelse_tag_parser (clens_ifthenelse_tag s) (gaccessor_ifthenelse_tag' s);
gaccessor_ifthenelse_tag' s
inline_for_extraction
let accessor_ifthenelse_tag
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (accessor (gaccessor_ifthenelse_tag s))
= fun #rrel #rel sl pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_ifthenelse_tag s) sl pos;
pos
let clens_ifthenelse_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (clens p.parse_ifthenelse_t (p.parse_ifthenelse_payload_t b))
= {
clens_cond = (fun (x: p.parse_ifthenelse_t) -> p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b);
clens_get = (fun (x: p.parse_ifthenelse_t) -> dsnd (s.serialize_ifthenelse_synth_recip x) <: Ghost (p.parse_ifthenelse_payload_t b) (requires (p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) == b)) (ensures (fun _ -> True)));
}
let gaccessor_ifthenelse_payload''
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(input: bytes)
: Ghost nat
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input
))
(ensures (fun res ->
gaccessor_post' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) input res
))
= parse_ifthenelse_eq p input;
parse_ifthenelse_parse_tag_payload s input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
consumed
let gaccessor_ifthenelse_payload'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
: Tot (gaccessor' (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b))
= fun (input: bytes) ->
match parse (parse_ifthenelse p) input with
| Some (x, _) ->
if p.parse_ifthenelse_tag_cond (dfst (s.serialize_ifthenelse_synth_recip x)) = b
then gaccessor_ifthenelse_payload'' s b input
else 0 (* dummy *)
| _ -> 0 (* dummy *)
let gaccessor_ifthenelse_payload_injective
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl /\
gaccessor_pre (parse_ifthenelse p) (dsnd (p.parse_ifthenelse_payload_parser b)) (clens_ifthenelse_payload s b) sl' /\
injective_precond (parse_ifthenelse p) sl sl'
))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl'))
= parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl' ;
parse_injective p.parse_ifthenelse_tag_parser sl sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.IfThenElse.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.IfThenElse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p ->
b: Prims.bool ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.IfThenElse.parse_ifthenelse_kind p) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser p b))
(LowParse.Low.IfThenElse.clens_ifthenelse_payload s b)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser p b))
(LowParse.Low.IfThenElse.clens_ifthenelse_payload s b)
sl' /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.IfThenElse.parse_ifthenelse p)
sl
sl')
(ensures
LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload' s b sl ==
LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload' s b sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.bool",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"Prims.unit",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"LowParse.Spec.IfThenElse.parse_ifthenelse_parse_tag_payload",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Low.IfThenElse.clens_ifthenelse_payload",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.squash",
"Prims.nat",
"LowParse.Low.IfThenElse.gaccessor_ifthenelse_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_ifthenelse_payload_no_lookahead
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(b: bool)
(sl sl': bytes)
: Lemma
(requires
((parse_ifthenelse_kind p).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl /\
gaccessor_pre (parse_ifthenelse p)
(dsnd (p.parse_ifthenelse_payload_parser b))
(clens_ifthenelse_payload s b)
sl' /\ no_lookahead_on_precond (parse_ifthenelse p) sl sl'))
(ensures (gaccessor_ifthenelse_payload' s b sl == gaccessor_ifthenelse_payload' s b sl')) =
| parse_ifthenelse_eq p sl;
parse_ifthenelse_eq p sl';
parse_ifthenelse_parse_tag_payload s sl;
parse_ifthenelse_parse_tag_payload s sl';
parse_strong_prefix (parse_ifthenelse p) sl sl';
parse_injective p.parse_ifthenelse_tag_parser sl sl' | false |
Lib.Sequence.fst | Lib.Sequence.index_map_blocks | val index_map_blocks:
#a:Type
-> blocksize:size_pos
-> inp:seq a
-> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize)
-> g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> lseq a rem -> lseq a rem)
-> i:nat{i < length inp} ->
Lemma (
let output = map_blocks blocksize inp f g in
let j = i % blocksize in
if i < (length inp / blocksize) * blocksize
then
let block_i = get_block blocksize inp f i in
Seq.index output i == Seq.index block_i j
else
let block_i = get_last blocksize inp g i in
Seq.index output i == Seq.index block_i j
) | val index_map_blocks:
#a:Type
-> blocksize:size_pos
-> inp:seq a
-> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize)
-> g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> lseq a rem -> lseq a rem)
-> i:nat{i < length inp} ->
Lemma (
let output = map_blocks blocksize inp f g in
let j = i % blocksize in
if i < (length inp / blocksize) * blocksize
then
let block_i = get_block blocksize inp f i in
Seq.index output i == Seq.index block_i j
else
let block_i = get_last blocksize inp g i in
Seq.index output i == Seq.index block_i j
) | let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 334,
"start_col": 0,
"start_line": 302
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
blocksize: Lib.IntTypes.size_pos ->
inp: Lib.Sequence.seq a ->
f:
(_: Lib.Sequence.block (Lib.Sequence.length inp) blocksize -> _: Lib.Sequence.lseq a blocksize
-> Lib.Sequence.lseq a blocksize) ->
g:
(
_: Lib.Sequence.last (Lib.Sequence.length inp) blocksize ->
rem: Lib.IntTypes.size_nat{rem < blocksize} ->
_: Lib.Sequence.lseq a rem
-> Lib.Sequence.lseq a rem) ->
i: Prims.nat{i < Lib.Sequence.length inp}
-> FStar.Pervasives.Lemma
(ensures
(let output = Lib.Sequence.map_blocks blocksize inp f g in
let j = i % blocksize in
(match i < (Lib.Sequence.length inp / blocksize) * blocksize with
| true ->
let block_i = Lib.Sequence.get_block blocksize inp f i in
FStar.Seq.Base.index output i == FStar.Seq.Base.index block_i j
| _ ->
let block_i = Lib.Sequence.get_last blocksize inp g i in
FStar.Seq.Base.index output i == FStar.Seq.Base.index block_i j)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_pos",
"Lib.Sequence.seq",
"Lib.Sequence.block",
"Lib.Sequence.length",
"Lib.Sequence.lseq",
"Lib.Sequence.last",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.nat",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"Lib.Sequence.index_map_blocks_multi",
"Prims.unit",
"FStar.Seq.Base.lemma_index_app1",
"Lib.Sequence.div_mul_lt",
"Prims.bool",
"Lib.Sequence.mod_prop",
"FStar.Seq.Base.lemma_index_app2",
"Prims._assert",
"FStar.Seq.Base.equal",
"Lib.Sequence.map_blocks",
"FStar.Seq.Base.append",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"Prims.op_Subtraction",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Seq.Base.lemma_len_slice",
"Prims.squash",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Prims.int",
"Prims.op_Multiply",
"Lib.Sequence.map_blocks_multi",
"Prims.op_Division"
] | [] | false | false | true | false | false | let index_map_blocks #a bs inp f g i =
| let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0
then
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc ( == ) {
length last;
( == ) { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
( == ) { mod_prop bs nb len }
len % bs;
( == ) { () }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs
then
(div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i)
else
(Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i)
else index_map_blocks_multi #a bs nb nb blocks f i | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.g_array_is_null | val g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool | val g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool | let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
g_array_ptr_is_null (array_ptr_of a) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 224,
"start_col": 0,
"start_line": 223
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a
inline_for_extraction [@@noextract_to "krml"]
let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: Pulse.C.Types.Array.array_or_null td -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_or_null",
"Pulse.C.Types.Array.g_array_ptr_is_null",
"Pulse.C.Types.Array.array_ptr_of",
"Prims.bool"
] | [] | false | false | false | false | false | let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
| g_array_ptr_is_null (array_ptr_of a) | false |
Lib.Sequence.fst | Lib.Sequence.create8_lemma | val create8_lemma: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (let s = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\
s.[4] == x4 /\ s.[5] == x5 /\ s.[6] == x6 /\ s.[7] == x7)
[SMTPat (create8 #a x0 x1 x2 x3 x4 x5 x6 x7)] | val create8_lemma: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (let s = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\
s.[4] == x4 /\ s.[5] == x5 /\ s.[6] == x6 /\ s.[7] == x7)
[SMTPat (create8 #a x0 x1 x2 x3 x4 x5 x6 x7)] | let create8_lemma #a x0 x1 x2 x3 x4 x5 x6 x7 =
Seq.elim_of_list [x0; x1; x2; x3; x4; x5; x6; x7] | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 393,
"start_col": 0,
"start_line": 392
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l
let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1]
let create4 #a x0 x1 x2 x3 =
let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l
let create4_lemma #a x0 x1 x2 x3 =
Seq.elim_of_list [x0; x1; x2; x3]
let create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let l = [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.Tot.length l = 8);
createL l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a -> x2: a -> x3: a -> x4: a -> x5: a -> x6: a -> x7: a
-> FStar.Pervasives.Lemma
(ensures
(let s = Lib.Sequence.create8 x0 x1 x2 x3 x4 x5 x6 x7 in
s.[ 0 ] == x0 /\ s.[ 1 ] == x1 /\ s.[ 2 ] == x2 /\ s.[ 3 ] == x3 /\ s.[ 4 ] == x4 /\
s.[ 5 ] == x5 /\ s.[ 6 ] == x6 /\ s.[ 7 ] == x7))
[SMTPat (Lib.Sequence.create8 x0 x1 x2 x3 x4 x5 x6 x7)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Properties.elim_of_list",
"Prims.Cons",
"Prims.Nil",
"Prims.unit"
] | [] | true | false | true | false | false | let create8_lemma #a x0 x1 x2 x3 x4 x5 x6 x7 =
| Seq.elim_of_list [x0; x1; x2; x3; x4; x5; x6; x7] | false |
Lib.Sequence.fst | Lib.Sequence.create4_lemma | val create4_lemma: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a ->
Lemma (let s = create4 x0 x1 x2 x3 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3)
[SMTPat (create4 #a x0 x1 x2 x3)] | val create4_lemma: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a ->
Lemma (let s = create4 x0 x1 x2 x3 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3)
[SMTPat (create4 #a x0 x1 x2 x3)] | let create4_lemma #a x0 x1 x2 x3 =
Seq.elim_of_list [x0; x1; x2; x3] | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 385,
"start_col": 0,
"start_line": 384
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l
let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1]
let create4 #a x0 x1 x2 x3 =
let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a -> x2: a -> x3: a
-> FStar.Pervasives.Lemma
(ensures
(let s = Lib.Sequence.create4 x0 x1 x2 x3 in
s.[ 0 ] == x0 /\ s.[ 1 ] == x1 /\ s.[ 2 ] == x2 /\ s.[ 3 ] == x3))
[SMTPat (Lib.Sequence.create4 x0 x1 x2 x3)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Properties.elim_of_list",
"Prims.Cons",
"Prims.Nil",
"Prims.unit"
] | [] | true | false | true | false | false | let create4_lemma #a x0 x1 x2 x3 =
| Seq.elim_of_list [x0; x1; x2; x3] | false |
Lib.Sequence.fst | Lib.Sequence.create16_lemma | val create16_lemma: #a:Type
-> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a
-> x8:a -> x9:a -> x10:a -> x11:a -> x12:a -> x13:a -> x14:a -> x15:a ->
Lemma (let s = create16 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\
s.[4] == x4 /\ s.[5] == x5 /\ s.[6] == x6 /\ s.[7] == x7 /\
s.[8] == x8 /\ s.[9] == x9 /\ s.[10] == x10 /\ s.[11] == x11 /\
s.[12] == x12 /\ s.[13] == x13 /\ s.[14] == x14 /\ s.[15] == x15)
[SMTPat (create16 #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15)] | val create16_lemma: #a:Type
-> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a
-> x8:a -> x9:a -> x10:a -> x11:a -> x12:a -> x13:a -> x14:a -> x15:a ->
Lemma (let s = create16 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\
s.[4] == x4 /\ s.[5] == x5 /\ s.[6] == x6 /\ s.[7] == x7 /\
s.[8] == x8 /\ s.[9] == x9 /\ s.[10] == x10 /\ s.[11] == x11 /\
s.[12] == x12 /\ s.[13] == x13 /\ s.[14] == x14 /\ s.[15] == x15)
[SMTPat (create16 #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15)] | let create16_lemma #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 =
Seq.elim_of_list [x0; x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15] | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 89,
"end_line": 401,
"start_col": 0,
"start_line": 400
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l
let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1]
let create4 #a x0 x1 x2 x3 =
let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l
let create4_lemma #a x0 x1 x2 x3 =
Seq.elim_of_list [x0; x1; x2; x3]
let create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let l = [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.Tot.length l = 8);
createL l
let create8_lemma #a x0 x1 x2 x3 x4 x5 x6 x7 =
Seq.elim_of_list [x0; x1; x2; x3; x4; x5; x6; x7]
let create16 #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 =
let l = [x0; x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15] in
assert_norm (List.Tot.length l = 16);
createL l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x0: a ->
x1: a ->
x2: a ->
x3: a ->
x4: a ->
x5: a ->
x6: a ->
x7: a ->
x8: a ->
x9: a ->
x10: a ->
x11: a ->
x12: a ->
x13: a ->
x14: a ->
x15: a
-> FStar.Pervasives.Lemma
(ensures
(let s = Lib.Sequence.create16 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 in
s.[ 0 ] == x0 /\ s.[ 1 ] == x1 /\ s.[ 2 ] == x2 /\ s.[ 3 ] == x3 /\ s.[ 4 ] == x4 /\
s.[ 5 ] == x5 /\ s.[ 6 ] == x6 /\ s.[ 7 ] == x7 /\ s.[ 8 ] == x8 /\ s.[ 9 ] == x9 /\
s.[ 10 ] == x10 /\ s.[ 11 ] == x11 /\ s.[ 12 ] == x12 /\ s.[ 13 ] == x13 /\
s.[ 14 ] == x14 /\ s.[ 15 ] == x15))
[SMTPat (Lib.Sequence.create16 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Properties.elim_of_list",
"Prims.Cons",
"Prims.Nil",
"Prims.unit"
] | [] | true | false | true | false | false | let create16_lemma #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 =
| Seq.elim_of_list [x0; x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15] | false |
Lib.Sequence.fst | Lib.Sequence.create2 | val create2: #a:Type -> x0:a -> x1:a -> lseq a 2 | val create2: #a:Type -> x0:a -> x1:a -> lseq a 2 | let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 374,
"start_col": 0,
"start_line": 371
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a -> Lib.Sequence.lseq a 2 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.createL",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let create2 #a x0 x1 =
| let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l | false |
Lib.Sequence.fst | Lib.Sequence.div_mul_l | val div_mul_l: a:int -> b:int -> c:pos -> d:pos -> Lemma
(requires a / d = b / d)
(ensures a / (c * d) = b / (c * d)) | val div_mul_l: a:int -> b:int -> c:pos -> d:pos -> Lemma
(requires a / d = b / d)
(ensures a / (c * d) = b / (c * d)) | let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
} | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 253,
"start_col": 0,
"start_line": 240
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> b: Prims.int -> c: Prims.pos -> d: Prims.pos
-> FStar.Pervasives.Lemma (requires a / d = b / d) (ensures a / (c * d) = b / (c * d)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Prims.pos",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Division",
"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",
"Prims.squash",
"FStar.Math.Lemmas.division_multiplication_lemma"
] | [] | false | false | true | false | false | let div_mul_l a b c d =
| calc ( == ) {
a / (c * d);
( == ) { () }
a / (d * c);
( == ) { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
( == ) { () }
(b / d) / c;
( == ) { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
( == ) { () }
b / (c * d);
} | false |
Lib.Sequence.fst | Lib.Sequence.create16 | val create16: #a:Type
-> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a
-> x8:a -> x9:a -> x10:a -> x11:a -> x12:a -> x13:a -> x14:a -> x15:a -> lseq a 16 | val create16: #a:Type
-> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a
-> x8:a -> x9:a -> x10:a -> x11:a -> x12:a -> x13:a -> x14:a -> x15:a -> lseq a 16 | let create16 #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 =
let l = [x0; x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15] in
assert_norm (List.Tot.length l = 16);
createL l | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 398,
"start_col": 0,
"start_line": 395
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l
let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1]
let create4 #a x0 x1 x2 x3 =
let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l
let create4_lemma #a x0 x1 x2 x3 =
Seq.elim_of_list [x0; x1; x2; x3]
let create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let l = [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.Tot.length l = 8);
createL l
let create8_lemma #a x0 x1 x2 x3 x4 x5 x6 x7 =
Seq.elim_of_list [x0; x1; x2; x3; x4; x5; x6; x7] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x0: a ->
x1: a ->
x2: a ->
x3: a ->
x4: a ->
x5: a ->
x6: a ->
x7: a ->
x8: a ->
x9: a ->
x10: a ->
x11: a ->
x12: a ->
x13: a ->
x14: a ->
x15: a
-> Lib.Sequence.lseq a 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.createL",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let create16 #a x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 =
| let l = [x0; x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15] in
assert_norm (List.Tot.length l = 16);
createL l | false |
Lib.Sequence.fst | Lib.Sequence.eq_generate_blocks0 | val eq_generate_blocks0:
#t:Type0
-> len:size_nat
-> n:nat
-> a:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < n} -> a i -> a (i + 1) & s:seq t{length s == len})
-> init:a 0 ->
Lemma (generate_blocks #t len n 0 a f init ==
(init,Seq.empty)) | val eq_generate_blocks0:
#t:Type0
-> len:size_nat
-> n:nat
-> a:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < n} -> a i -> a (i + 1) & s:seq t{length s == len})
-> init:a 0 ->
Lemma (generate_blocks #t len n 0 a f init ==
(init,Seq.empty)) | let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 340,
"start_col": 0,
"start_line": 336
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat ->
n: Prims.nat ->
a: (i: Prims.nat{i <= n} -> Type) ->
f:
(i: Prims.nat{i < n} -> _: a i
-> a (i + 1) * s: Lib.Sequence.seq t {Lib.Sequence.length s == len}) ->
init: a 0
-> FStar.Pervasives.Lemma
(ensures Lib.Sequence.generate_blocks len n 0 a f init == (init, FStar.Seq.Base.empty)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Lib.Sequence.seq",
"Prims.eq2",
"Lib.Sequence.length",
"Lib.LoopCombinators.eq_repeat_gen0",
"Lib.Sequence.generate_blocks_a",
"Lib.Sequence.generate_blocks_inner",
"Prims.unit",
"Prims._assert",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.Sequence.generate_blocks",
"Lib.LoopCombinators.repeat_gen",
"Prims.op_Multiply",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.empty"
] | [] | true | false | true | false | false | let eq_generate_blocks0 #t len n a f acc0 =
| let a0 = (acc0, (Seq.empty <: s: seq t {length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 | false |
Lib.Sequence.fst | Lib.Sequence.create8 | val create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> lseq a 8 | val create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> lseq a 8 | let create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let l = [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.Tot.length l = 8);
createL l | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 390,
"start_col": 0,
"start_line": 387
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l
let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1]
let create4 #a x0 x1 x2 x3 =
let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l
let create4_lemma #a x0 x1 x2 x3 =
Seq.elim_of_list [x0; x1; x2; x3] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a -> x2: a -> x3: a -> x4: a -> x5: a -> x6: a -> x7: a -> Lib.Sequence.lseq a 8 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.createL",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
| let l = [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.Tot.length l = 8);
createL l | false |
Lib.Sequence.fst | Lib.Sequence.create4 | val create4: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> lseq a 4 | val create4: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> lseq a 4 | let create4 #a x0 x1 x2 x3 =
let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l | {
"file_name": "lib/Lib.Sequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 382,
"start_col": 0,
"start_line": 379
} | module Lib.Sequence
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
#set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'"
let index #a #len s n = Seq.index s n
let create #a len init = Seq.create #a len init
let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1
let to_list #a s = Seq.seq_to_list s
let of_list #a l = Seq.seq_of_list #a l
let of_list_index #a l i =
Seq.lemma_seq_of_list_index #a l i
let equal #a #len s1 s2 =
forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i
let eq_intro #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2)
let eq_elim #a #len s1 s2 =
assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)}
index s1 i == index s2 i);
Seq.lemma_eq_elim #a s1 s2
let upd #a #len s n x = Seq.upd #a s n x
let member #a #len x l = Seq.count x l > 0
let sub #a #len s start n = Seq.slice #a s start (start + n)
let update_sub #a #len s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
let lemma_update_sub #a #len dst start n src res =
let res1 = update_sub dst start n src in
Seq.lemma_split (sub res 0 (start + n)) start;
Seq.lemma_split (sub res1 0 (start + n)) start;
Seq.lemma_split res (start + n);
Seq.lemma_split res1 (start + n);
Seq.lemma_eq_intro res (update_sub dst start n src)
let lemma_concat2 #a len0 s0 len1 s1 s =
Seq.Properties.lemma_split s len0;
Seq.Properties.lemma_split (concat s0 s1) len0;
Seq.lemma_eq_intro s (concat s0 s1)
let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s =
let s' = concat (concat s0 s1) s2 in
Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0;
Seq.Properties.lemma_split s (len0 + len1);
Seq.Properties.lemma_split s' (len0 + len1);
Seq.lemma_eq_intro s (concat (concat s0 s1) s2)
let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) =
lseq a k
let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len})
(s:createi_a a len init k) =
forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i
let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len})
(si:createi_a a len init i)
: r:createi_a a len init (i + 1)
{createi_pred a len init i si ==> createi_pred a len init (i + 1) r}
=
assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j));
Seq.snoc si (init i)
#push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'"
let createi #a len init_f =
repeat_gen_inductive len
(createi_a a len init_f)
(createi_pred a len init_f)
(createi_step a len init_f)
(of_list [])
#pop-options
inline_for_extraction
let mapi_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) =
f i s.[i]
let mapi #a #b #len f s =
createi #b len (mapi_inner #a #b #len f s)
inline_for_extraction
let map_inner (#a:Type) (#b:Type) (#len:size_nat)
(f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) =
f s.[i]
let map #a #b #len f s =
createi #b len (map_inner #a #b #len f s)
let map2i #a #b #c #len f s1 s2 =
createi #c len (fun i -> f i s1.[i] s2.[i])
inline_for_extraction
let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat)
(f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) =
f s1.[i] s2.[i]
let map2 #a #b #c #len f s1 s2 =
createi #c len (map2_inner #a #b #c #len f s1 s2)
let for_all #a #len f x = Seq.for_all f x
let for_all2 #a #b #len f x y =
let r = map2 (fun xi yi -> f xi yi) x y in
Seq.for_all (fun bi -> bi = true) r
(** Selecting a subset of an unbounded Sequence *)
val seq_sub:
#a:Type
-> s1:seq a
-> start:nat
-> n:nat{start + n <= length s1}
-> s2:seq a{length s2 == n /\
(forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))}
let seq_sub #a s start n =
Seq.slice #a s start (start + n)
(** Updating a subset of an unbounded Sequence with another Sequence *)
val seq_update_sub:
#a:Type
-> i:seq a
-> start:nat
-> n:nat{start + n <= length i}
-> x:seq a{length x == n}
-> o:seq a{length o == length i /\ seq_sub o start n == x /\
(forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}).
{:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)}
let seq_update_sub #a s start n x =
let o =
Seq.append
(Seq.append (Seq.slice s 0 start) x)
(Seq.slice s (start + n) (length s)) in
Seq.lemma_eq_intro (Seq.slice o start (start + n)) x;
o
val repeati_blocks_f:
#a:Type0
-> #b:Type0
-> blocksize:size_nat{blocksize > 0}
-> inp:seq a
-> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b)
-> nb:nat{nb == length inp / blocksize}
-> i:nat{i < nb}
-> acc:b
-> b
let repeati_blocks_f #a #b bs inp f nb i acc =
assert ((i+1) * bs <= nb * bs);
let block = seq_sub inp (i * bs) bs in
f i block acc
let repeati_blocks #a #b bs inp f g init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeati_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
g nb rem last acc
let repeat_blocks #a #b #c bs inp f l init =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let acc = repeati nb (repeat_blocks_f bs inp f nb) init in
let last = seq_sub inp (nb * bs) rem in
l rem last acc
let lemma_repeat_blocks #a #b #c bs inp f l init = ()
let repeat_blocks_multi #a #b bs inp f init =
let len = length inp in
let nb = len / bs in
repeati nb (repeat_blocks_f bs inp f nb) init
let lemma_repeat_blocks_multi #a #b bs inp f init = ()
let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen}
let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) =
let acc, o = acc in
let acc', block = f i acc in
let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in
acc', o'
let generate_blocks #t len max n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0
let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs}
let generate_blocks_simple_f
(#a:Type)
(bs:size_nat{bs > 0})
(max:nat)
(f:(i:nat{i < max} -> lseq a bs))
(i:nat{i < max})
(acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1)
=
Seq.append acc (f i)
let generate_blocks_simple #a bs max nb f =
repeat_gen nb (generate_blocks_simple_a a bs max)
(generate_blocks_simple_f #a bs max f) Seq.empty
#restart-solver
let div_interval b n i =
Math.Lemmas.lemma_div_le (n * b) i b;
Math.Lemmas.cancel_mul_div n b
let mod_interval_lt b n i j =
div_interval b n i;
div_interval b n j
let div_mul_lt b a n = ()
let mod_div_lt b i j =
mod_interval_lt b (j / b) i j
let div_mul_l a b c d =
calc (==) {
a / (c * d);
== { }
a / (d * c);
== { Math.Lemmas.division_multiplication_lemma a d c }
(a / d) / c;
== { }
(b / d) / c;
== { Math.Lemmas.division_multiplication_lemma b d c }
b / (d * c);
== { }
b / (c * d);
}
let map_blocks_multi #a bs max nb inp f =
repeat_gen nb (map_blocks_a a bs max)
(map_blocks_f #a bs max inp f) Seq.empty
let lemma_map_blocks_multi #a bs max nb inp f = ()
private
val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} ->
Lemma (b - a * n == b % n)
let mod_prop n a b =
Math.Lemmas.modulo_lemma (b - a * n) n;
Math.Lemmas.lemma_mod_sub b n a
#push-options "--z3rlimit 200"
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in
let map_blocks_f = map_blocks_f #a bs max inp f in
let acc0 = Seq.empty #a in
let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in
unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1);
let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in
//assert (s1 == map_blocks_f (n-1) s);
let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in
//assert (s1 == Seq.append s s');
if i < (n-1)*bs then begin
Seq.lemma_index_app1 s s' i;
index_map_blocks_multi #a bs max (n-1) inp f i end
else begin
Seq.lemma_index_app2 s s' i;
mod_prop bs (n-1) i
end
let map_blocks #a blocksize inp f g =
let len = length inp in
let nb = len / blocksize in
let rem = len % blocksize in
let blocks = Seq.slice inp 0 (nb * blocksize) in
let last = Seq.slice inp (nb * blocksize) len in
let bs = map_blocks_multi #a blocksize nb nb blocks f in
if (rem > 0) then
Seq.append bs (g nb rem last)
else bs
let lemma_map_blocks #a blocksize inp f g = ()
let index_map_blocks #a bs inp f g i =
let len = length inp in
let nb = len / bs in
let rem = len % bs in
let blocks = Seq.slice inp 0 (nb * bs) in
if rem > 0 then
begin
let s1 = map_blocks_multi #a bs nb nb blocks f in
let last = Seq.slice inp (nb * bs) len in
calc (==) {
length last;
== { Seq.lemma_len_slice inp (nb * bs) len }
len - nb * bs;
== {mod_prop bs nb len}
len % bs;
== { }
rem;
};
let s2 = g nb rem last in
assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2));
if i < nb * bs then
begin
div_mul_lt bs i nb;
Seq.lemma_index_app1 s1 s2 i;
index_map_blocks_multi bs nb nb blocks f i
end
else
begin
Seq.lemma_index_app2 s1 s2 i;
mod_prop bs nb i
end
end
else index_map_blocks_multi #a bs nb nb blocks f i
let eq_generate_blocks0 #t len n a f acc0 =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n 0 a f acc0 ==
repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0
let unfold_generate_blocks #t len n a f acc0 i =
let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in
assert (generate_blocks #t len n (i+1) a f acc0 ==
repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0);
unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
let rec index_generate_blocks #t len max n f i =
assert (0 < n);
let a_spec (i:nat{i <= max}) = unit in
let _,s = generate_blocks #t len max (n-1) a_spec f () in
let _,s' = f (n-1) () in
let _,s1 = generate_blocks #t len max n a_spec f () in
unfold_generate_blocks #t len max a_spec f () (n-1);
Seq.Properties.lemma_split s1 (n * len - len);
Seq.Properties.lemma_split (Seq.append s s') (n * len - len);
Seq.lemma_eq_intro s1 (Seq.append s s');
if i < (n-1) * len then
begin
Seq.lemma_index_app1 s s' i;
index_generate_blocks len max (n-1) f i
end
else
begin
Seq.lemma_index_app2 s s' i;
mod_prop len (n-1) i
end
#push-options "--using_facts_from '+FStar.UInt.pow2_values'"
let create2 #a x0 x1 =
let l = [x0; x1] in
assert_norm (List.Tot.length l = 2);
createL l
let create2_lemma #a x0 x1 =
Seq.elim_of_list [x0; x1] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.Sequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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": "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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a -> x2: a -> x3: a -> Lib.Sequence.lseq a 4 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.createL",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let create4 #a x0 x1 x2 x3 =
| let l = [x0; x1; x2; x3] in
assert_norm (List.Tot.length l = 4);
createL l | false |
VariantsWithRecords.fst | VariantsWithRecords.e | val e : VariantsWithRecords.expr Prims.string | let e = StringOfInt { value = Add { x = ConstInt 3; y = ConstInt 39} } | {
"file_name": "examples/misc/VariantsWithRecords.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | module VariantsWithRecords
(**** General usage *)
/// A record type is declared using the following syntax:
type record = { field1: int; field2: string (* ... *) }
/// A variant type can be of any arity, and can be declared using a
/// few different syntaxes.
type foo =
(** constructor [A] carries an integer and a string *)
| A: int -> string -> foo
(** fields can be named *)
| B: named:int -> other:string -> foo
(** for constructor of arity 1, one cam use OCaml's [of] notation *)
| C of int * string
(** [D] carries nothing *)
| D
(** [E] carries a record *)
| E { a: int; b: int }
/// Example of a GADT:
type expr: Type -> Type =
(** [ConstInt] constructs an [expr int] *)
| ConstInt: int -> expr int
(** but [ConstStr] constructs an [expr string] *)
| ConstStr: string -> expr string
(** [Add] carries a record and constructs a [expr int] *)
| Add { x: expr int; y: expr int }: expr int
| StringOfInt { value: expr int }: expr string
let rec eval (e: expr 'a): 'a
= match e with
| ConstInt c -> c
| ConstStr s -> s
| Add {x; y} -> eval x + eval y
| StringOfInt {value} -> string_of_int (eval value) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "VariantsWithRecords.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | VariantsWithRecords.expr Prims.string | Prims.Tot | [
"total"
] | [] | [
"VariantsWithRecords.StringOfInt",
"VariantsWithRecords.Mkexpr__StringOfInt__payload",
"VariantsWithRecords.Add",
"VariantsWithRecords.Mkexpr__Add__payload",
"VariantsWithRecords.ConstInt"
] | [] | false | false | false | true | false | let e =
| StringOfInt ({ value = Add ({ x = ConstInt 3; y = ConstInt 39 }) }) | false |
|
FStar.Pure.BreakVC.fsti | FStar.Pure.BreakVC.break_wp' | val break_wp':pure_wp' unit | val break_wp':pure_wp' unit | let break_wp' : pure_wp' unit =
fun p -> spinoff (squash (p ())) | {
"file_name": "ulib/FStar.Pure.BreakVC.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 6,
"start_col": 0,
"start_line": 5
} | module FStar.Pure.BreakVC
open FStar.Tactics | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Pure.BreakVC.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.pure_wp' Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_post",
"Prims.unit",
"FStar.Pervasives.spinoff",
"Prims.squash",
"Prims.pure_pre"
] | [] | false | false | false | true | false | let break_wp':pure_wp' unit =
| fun p -> spinoff (squash (p ())) | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_length | val array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat | val array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat | let array_length
(#t: Type)
(#td: typedef t)
(a: array td)
: GTot nat
= SZ.v (dsnd a) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 242,
"start_col": 0,
"start_line": 237
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a
inline_for_extraction [@@noextract_to "krml"]
let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |)
let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
g_array_ptr_is_null (array_ptr_of a)
inline_for_extraction [@@noextract_to "krml"]
let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false })
inline_for_extraction [@@noextract_to "krml"]
let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) =
array_ptr_of ar
inline_for_extraction [@@noextract_to "krml"]
let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) =
mk_array_or_null a len | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: Pulse.C.Types.Array.array td -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array",
"FStar.SizeT.v",
"FStar.Ghost.reveal",
"FStar.SizeT.t",
"FStar.Pervasives.dsnd",
"Pulse.C.Types.Array.array_ptr",
"Pulse.C.Types.Array.array_len_t",
"Prims.nat"
] | [] | false | false | false | false | false | let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat =
| SZ.v (dsnd a) | false |
FStar.Pure.BreakVC.fsti | FStar.Pure.BreakVC.post | val post: Prims.unit -> Tac unit | val post: Prims.unit -> Tac unit | let post () : Tac unit =
norm [delta_fully [`%mono_lem; `%break_wp']];
trefl() | {
"file_name": "ulib/FStar.Pure.BreakVC.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 13,
"start_col": 0,
"start_line": 11
} | module FStar.Pure.BreakVC
open FStar.Tactics
let break_wp' : pure_wp' unit =
fun p -> spinoff (squash (p ()))
val mono_lem () : Lemma (pure_wp_monotonic unit break_wp') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Pure.BreakVC.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V1.Derived.trefl",
"FStar.Stubs.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_fully",
"Prims.string",
"Prims.Nil"
] | [] | false | true | false | false | false | let post () : Tac unit =
| norm [delta_fully [`%mono_lem; `%break_wp']];
trefl () | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.full_seq | val full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop | val full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop | let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop =
forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 91,
"end_line": 522,
"start_col": 0,
"start_line": 521
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a
inline_for_extraction [@@noextract_to "krml"]
let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |)
let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
g_array_ptr_is_null (array_ptr_of a)
inline_for_extraction [@@noextract_to "krml"]
let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false })
inline_for_extraction [@@noextract_to "krml"]
let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) =
array_ptr_of ar
inline_for_extraction [@@noextract_to "krml"]
let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) =
mk_array_or_null a len
let array_length
(#t: Type)
(#td: typedef t)
(a: array td)
: GTot nat
= SZ.v (dsnd a)
val array_pts_to
(#t: Type)
(#td: typedef t)
(r: array td)
(v: Ghost.erased (Seq.seq t))
: Tot vprop
let array_pts_to_or_null
(#t: Type)
(#td: typedef t)
(r: array_or_null td)
(v: Ghost.erased (Seq.seq t))
: Tot vprop
= if g_array_is_null r
then emp
else array_pts_to r v
[@@noextract_to "krml"] // primitive
val array_ptr_is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: array_ptr td)
(len: array_len_t r)
// : STAtomicBase bool false opened Unobservable
: stt bool
(array_pts_to_or_null (mk_array_or_null r len) v)
(fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure (
b == g_array_is_null (mk_array_or_null r len)
))
#set-options "--print_implicits"
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: array_or_null td)
// : STAtomicBase bool false opened Unobservable
requires
(array_pts_to_or_null r v)
returns b: bool
ensures
(array_pts_to_or_null r v ** pure (
b == g_array_is_null r
))
{
let a = array_ptr_of r;
let len : array_len_t a = array_len_of r;
rewrite (array_pts_to_or_null r v)
as (array_pts_to_or_null (mk_array_or_null a len) v);
let res = array_ptr_is_null a len;
rewrite (array_pts_to_or_null (mk_array_or_null a len) v)
as (array_pts_to_or_null r v);
res
}
```
val array_pts_to_length
(#t: Type)
(#td: typedef t)
(r: array td)
(v: Ghost.erased (Seq.seq t))
: stt_ghost unit
(array_pts_to r v)
(fun _ -> array_pts_to r v ** pure (
Seq.length v == SZ.v (dsnd r)
))
#set-options "--print_implicits"
let has_array_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(a: array td)
: GTot prop
= let (| al, len |) = a in
array_ref_base_size al == n /\
has_array_ref_base al #tn r /\
array_ref_offset al == 0sz /\
Ghost.reveal len == n
let has_array_of_base_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(a1 a2: array td)
: Lemma
(requires (
has_array_of_base #t #tn #n #td r a1 /\
has_array_of_base #t #tn #n #td r a2
))
(ensures (a1 == a2))
= let (| ar1, _ |) = a1 in
let (| ar2, _ |) = a2 in
array_ref_base_offset_inj #t #td #tn ar1 r ar2 r
let seq_of_base_array
(#t: Type)
(#tn: Type)
(#n: array_size_t)
(v: base_array_t t tn n)
: GTot (Seq.lseq t (SZ.v n))
= Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i))
val ghost_array_of_base_focus
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array td)
: stt_ghost unit
(pts_to r v ** pure (
has_array_of_base r a
))
(fun _ -> array_pts_to a (seq_of_base_array v))
val ghost_array_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
: stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a })
(pts_to r v)
(fun a -> array_pts_to a (seq_of_base_array v))
let array_ref_of_base_post
(#t: Type)
(#tn: Type0)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array_ref td)
(ar: array td)
: GTot prop
=
array_ptr_of ar == a /\
array_ref_base_size a == Ghost.reveal n /\
array_ref_offset a == 0sz /\
has_array_of_base r ar /\
Ghost.reveal (dsnd ar) == Ghost.reveal n
// to be extracted to just r
[@@noextract_to "krml"] // primitive
val array_ref_of_base
(#t: Type)
(#tn: Type0)
// (#opened: _)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
//: STAtomicBase (array_ref td) false opened Unobservable
: stt (array_ref td)
(pts_to r v)
(fun a -> exists* (ar: array td) .
array_pts_to ar (seq_of_base_array v) ** pure (
array_ref_of_base_post v r a ar
))
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_of_base
(#t: Type)
(#tn: Type0)
// (#opened: _)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
// : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable
requires
(pts_to r v)
returns
a: (a: array td { has_array_of_base r a })
ensures
(array_pts_to a (seq_of_base_array v))
{
let al = array_ref_of_base r;
with ga . assert (array_pts_to #t #td ga (seq_of_base_array v));
let a = mk_array_or_null al (Ghost.hide (n <: SZ.t));
rewrite (array_pts_to ga (seq_of_base_array v))
as (array_pts_to a (seq_of_base_array v));
a
}
```
val unarray_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: ref (base_array0 tn td n))
(a: array td)
: stt_ghost (Ghost.erased (base_array_t t tn n))
(array_pts_to a v ** pure (
has_array_of_base r a
))
(fun v' -> pts_to r v' ** pure (
Ghost.reveal v `Seq.equal` seq_of_base_array v'
))
val freeable_array
(#t: Type)
(#td: typedef t)
(a: array td)
: Tot vprop
let freeable_or_null_array
(#t: Type)
(#td: typedef t)
(a: array_or_null td)
: Tot vprop
= if g_array_is_null a
then emp
else freeable_array a
[@@noextract_to "krml"] // primitive
val array_ptr_alloc
(#t: Type)
(td: typedef t)
(sz: SZ.t { SZ.v sz > 0 })
: stt (array_ptr td)
emp
(fun a ->
exists* (ar: array_or_null td) (s: Seq.seq t) .
freeable_or_null_array ar **
array_pts_to_or_null ar s ** pure (
array_ptr_of ar == a /\
(g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\
Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td)
))
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_alloc
(#t: Type)
(td: typedef t)
(sz: SZ.t { SZ.v sz > 0 })
requires
emp
returns ar: array_or_null td
ensures
(
freeable_or_null_array ar ** (
exists* s .
array_pts_to_or_null ar s ** pure (
(g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\
Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td)
)))
{
let a : array_ptr td = array_ptr_alloc td sz;
with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s);
let len: array_len_t a = array_len_of ar';
let ar = mk_array_or_null a len;
rewrite (array_pts_to_or_null ar' s)
as (array_pts_to_or_null ar s);
rewrite (freeable_or_null_array ar')
as (freeable_or_null_array ar);
ar
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> v: FStar.Seq.Base.seq t -> Prims.GTot Prims.prop | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.C.Types.Base.typedef",
"FStar.Seq.Base.seq",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Pulse.C.Types.Base.full",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | false | true | let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop =
| forall (i: nat{i < Seq.length v}). {:pattern (Seq.index v i)} full td (Seq.index v i) | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_ref_of_base_post | val array_ref_of_base_post
(#t: Type)
(#tn: Type0)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array_ref td)
(ar: array td)
: GTot prop | val array_ref_of_base_post
(#t: Type)
(#tn: Type0)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array_ref td)
(ar: array td)
: GTot prop | let array_ref_of_base_post
(#t: Type)
(#tn: Type0)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array_ref td)
(ar: array td)
: GTot prop
=
array_ptr_of ar == a /\
array_ref_base_size a == Ghost.reveal n /\
array_ref_offset a == 0sz /\
has_array_of_base r ar /\
Ghost.reveal (dsnd ar) == Ghost.reveal n | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 397,
"start_col": 0,
"start_line": 382
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a
inline_for_extraction [@@noextract_to "krml"]
let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |)
let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
g_array_ptr_is_null (array_ptr_of a)
inline_for_extraction [@@noextract_to "krml"]
let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false })
inline_for_extraction [@@noextract_to "krml"]
let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) =
array_ptr_of ar
inline_for_extraction [@@noextract_to "krml"]
let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) =
mk_array_or_null a len
let array_length
(#t: Type)
(#td: typedef t)
(a: array td)
: GTot nat
= SZ.v (dsnd a)
val array_pts_to
(#t: Type)
(#td: typedef t)
(r: array td)
(v: Ghost.erased (Seq.seq t))
: Tot vprop
let array_pts_to_or_null
(#t: Type)
(#td: typedef t)
(r: array_or_null td)
(v: Ghost.erased (Seq.seq t))
: Tot vprop
= if g_array_is_null r
then emp
else array_pts_to r v
[@@noextract_to "krml"] // primitive
val array_ptr_is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: array_ptr td)
(len: array_len_t r)
// : STAtomicBase bool false opened Unobservable
: stt bool
(array_pts_to_or_null (mk_array_or_null r len) v)
(fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure (
b == g_array_is_null (mk_array_or_null r len)
))
#set-options "--print_implicits"
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: array_or_null td)
// : STAtomicBase bool false opened Unobservable
requires
(array_pts_to_or_null r v)
returns b: bool
ensures
(array_pts_to_or_null r v ** pure (
b == g_array_is_null r
))
{
let a = array_ptr_of r;
let len : array_len_t a = array_len_of r;
rewrite (array_pts_to_or_null r v)
as (array_pts_to_or_null (mk_array_or_null a len) v);
let res = array_ptr_is_null a len;
rewrite (array_pts_to_or_null (mk_array_or_null a len) v)
as (array_pts_to_or_null r v);
res
}
```
val array_pts_to_length
(#t: Type)
(#td: typedef t)
(r: array td)
(v: Ghost.erased (Seq.seq t))
: stt_ghost unit
(array_pts_to r v)
(fun _ -> array_pts_to r v ** pure (
Seq.length v == SZ.v (dsnd r)
))
#set-options "--print_implicits"
let has_array_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(a: array td)
: GTot prop
= let (| al, len |) = a in
array_ref_base_size al == n /\
has_array_ref_base al #tn r /\
array_ref_offset al == 0sz /\
Ghost.reveal len == n
let has_array_of_base_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(a1 a2: array td)
: Lemma
(requires (
has_array_of_base #t #tn #n #td r a1 /\
has_array_of_base #t #tn #n #td r a2
))
(ensures (a1 == a2))
= let (| ar1, _ |) = a1 in
let (| ar2, _ |) = a2 in
array_ref_base_offset_inj #t #td #tn ar1 r ar2 r
let seq_of_base_array
(#t: Type)
(#tn: Type)
(#n: array_size_t)
(v: base_array_t t tn n)
: GTot (Seq.lseq t (SZ.v n))
= Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i))
val ghost_array_of_base_focus
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array td)
: stt_ghost unit
(pts_to r v ** pure (
has_array_of_base r a
))
(fun _ -> array_pts_to a (seq_of_base_array v))
val ghost_array_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
: stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a })
(pts_to r v)
(fun a -> array_pts_to a (seq_of_base_array v)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
v: FStar.Ghost.erased (Pulse.C.Types.Array.base_array_t t tn (FStar.Ghost.reveal n)) ->
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Array.base_array0 tn td (FStar.Ghost.reveal n)) ->
a: Pulse.C.Types.Array.array_ref td ->
ar: Pulse.C.Types.Array.array td
-> Prims.GTot Prims.prop | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Ghost.erased",
"Pulse.C.Types.Array.array_size_t",
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.base_array_t",
"FStar.Ghost.reveal",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Array.base_array0",
"Pulse.C.Types.Array.array_ref",
"Pulse.C.Types.Array.array",
"Prims.l_and",
"Prims.eq2",
"Pulse.C.Types.Array.array_ptr",
"Pulse.C.Types.Array.array_ptr_of",
"FStar.SizeT.t",
"Pulse.C.Types.Array.array_ref_base_size",
"Pulse.C.Types.Array.array_ref_offset",
"FStar.SizeT.__uint_to_t",
"Pulse.C.Types.Array.has_array_of_base",
"FStar.Pervasives.dsnd",
"Pulse.C.Types.Array.array_len_t",
"Prims.prop"
] | [] | false | false | false | false | true | let array_ref_of_base_post
(#t: Type)
(#tn: Type0)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array_ref td)
(ar: array td)
: GTot prop =
| array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\
has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n | false |
VariantsWithRecords.fst | VariantsWithRecords.eval | val eval (e: expr 'a) : 'a | val eval (e: expr 'a) : 'a | let rec eval (e: expr 'a): 'a
= match e with
| ConstInt c -> c
| ConstStr s -> s
| Add {x; y} -> eval x + eval y
| StringOfInt {value} -> string_of_int (eval value) | {
"file_name": "examples/misc/VariantsWithRecords.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 37,
"start_col": 0,
"start_line": 32
} | module VariantsWithRecords
(**** General usage *)
/// A record type is declared using the following syntax:
type record = { field1: int; field2: string (* ... *) }
/// A variant type can be of any arity, and can be declared using a
/// few different syntaxes.
type foo =
(** constructor [A] carries an integer and a string *)
| A: int -> string -> foo
(** fields can be named *)
| B: named:int -> other:string -> foo
(** for constructor of arity 1, one cam use OCaml's [of] notation *)
| C of int * string
(** [D] carries nothing *)
| D
(** [E] carries a record *)
| E { a: int; b: int }
/// Example of a GADT:
type expr: Type -> Type =
(** [ConstInt] constructs an [expr int] *)
| ConstInt: int -> expr int
(** but [ConstStr] constructs an [expr string] *)
| ConstStr: string -> expr string
(** [Add] carries a record and constructs a [expr int] *)
| Add { x: expr int; y: expr int }: expr int
| StringOfInt { value: expr int }: expr string | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "VariantsWithRecords.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: VariantsWithRecords.expr 'a -> 'a | Prims.Tot | [
"total"
] | [] | [
"VariantsWithRecords.expr",
"Prims.int",
"Prims.string",
"Prims.op_Addition",
"VariantsWithRecords.eval",
"Prims.string_of_int"
] | [
"recursion"
] | false | false | false | true | false | let rec eval (e: expr 'a) : 'a =
| match e with
| ConstInt c -> c
| ConstStr s -> s
| Add { x = x ; y = y } -> eval x + eval y
| StringOfInt { value = value } -> string_of_int (eval value) | false |
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.fractionable_seq | val fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop | val fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop | let fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop =
forall (i: nat). i < Seq.length s ==> fractionable td (Seq.index s i) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 71,
"end_line": 980,
"start_col": 0,
"start_line": 979
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a
let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a
inline_for_extraction [@@noextract_to "krml"]
let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) =
(| a, len |)
let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool =
g_array_ptr_is_null (array_ptr_of a)
inline_for_extraction [@@noextract_to "krml"]
let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false })
inline_for_extraction [@@noextract_to "krml"]
let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) =
array_ptr_of ar
inline_for_extraction [@@noextract_to "krml"]
let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) =
mk_array_or_null a len
let array_length
(#t: Type)
(#td: typedef t)
(a: array td)
: GTot nat
= SZ.v (dsnd a)
val array_pts_to
(#t: Type)
(#td: typedef t)
(r: array td)
(v: Ghost.erased (Seq.seq t))
: Tot vprop
let array_pts_to_or_null
(#t: Type)
(#td: typedef t)
(r: array_or_null td)
(v: Ghost.erased (Seq.seq t))
: Tot vprop
= if g_array_is_null r
then emp
else array_pts_to r v
[@@noextract_to "krml"] // primitive
val array_ptr_is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: array_ptr td)
(len: array_len_t r)
// : STAtomicBase bool false opened Unobservable
: stt bool
(array_pts_to_or_null (mk_array_or_null r len) v)
(fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure (
b == g_array_is_null (mk_array_or_null r len)
))
#set-options "--print_implicits"
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: array_or_null td)
// : STAtomicBase bool false opened Unobservable
requires
(array_pts_to_or_null r v)
returns b: bool
ensures
(array_pts_to_or_null r v ** pure (
b == g_array_is_null r
))
{
let a = array_ptr_of r;
let len : array_len_t a = array_len_of r;
rewrite (array_pts_to_or_null r v)
as (array_pts_to_or_null (mk_array_or_null a len) v);
let res = array_ptr_is_null a len;
rewrite (array_pts_to_or_null (mk_array_or_null a len) v)
as (array_pts_to_or_null r v);
res
}
```
val array_pts_to_length
(#t: Type)
(#td: typedef t)
(r: array td)
(v: Ghost.erased (Seq.seq t))
: stt_ghost unit
(array_pts_to r v)
(fun _ -> array_pts_to r v ** pure (
Seq.length v == SZ.v (dsnd r)
))
#set-options "--print_implicits"
let has_array_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(a: array td)
: GTot prop
= let (| al, len |) = a in
array_ref_base_size al == n /\
has_array_ref_base al #tn r /\
array_ref_offset al == 0sz /\
Ghost.reveal len == n
let has_array_of_base_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(a1 a2: array td)
: Lemma
(requires (
has_array_of_base #t #tn #n #td r a1 /\
has_array_of_base #t #tn #n #td r a2
))
(ensures (a1 == a2))
= let (| ar1, _ |) = a1 in
let (| ar2, _ |) = a2 in
array_ref_base_offset_inj #t #td #tn ar1 r ar2 r
let seq_of_base_array
(#t: Type)
(#tn: Type)
(#n: array_size_t)
(v: base_array_t t tn n)
: GTot (Seq.lseq t (SZ.v n))
= Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i))
val ghost_array_of_base_focus
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array td)
: stt_ghost unit
(pts_to r v ** pure (
has_array_of_base r a
))
(fun _ -> array_pts_to a (seq_of_base_array v))
val ghost_array_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
: stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a })
(pts_to r v)
(fun a -> array_pts_to a (seq_of_base_array v))
let array_ref_of_base_post
(#t: Type)
(#tn: Type0)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
(a: array_ref td)
(ar: array td)
: GTot prop
=
array_ptr_of ar == a /\
array_ref_base_size a == Ghost.reveal n /\
array_ref_offset a == 0sz /\
has_array_of_base r ar /\
Ghost.reveal (dsnd ar) == Ghost.reveal n
// to be extracted to just r
[@@noextract_to "krml"] // primitive
val array_ref_of_base
(#t: Type)
(#tn: Type0)
// (#opened: _)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
//: STAtomicBase (array_ref td) false opened Unobservable
: stt (array_ref td)
(pts_to r v)
(fun a -> exists* (ar: array td) .
array_pts_to ar (seq_of_base_array v) ** pure (
array_ref_of_base_post v r a ar
))
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_of_base
(#t: Type)
(#tn: Type0)
// (#opened: _)
(#n: Ghost.erased array_size_t)
(#td: typedef t)
(#v: Ghost.erased (base_array_t t tn n))
(r: ref (base_array0 tn td n))
// : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable
requires
(pts_to r v)
returns
a: (a: array td { has_array_of_base r a })
ensures
(array_pts_to a (seq_of_base_array v))
{
let al = array_ref_of_base r;
with ga . assert (array_pts_to #t #td ga (seq_of_base_array v));
let a = mk_array_or_null al (Ghost.hide (n <: SZ.t));
rewrite (array_pts_to ga (seq_of_base_array v))
as (array_pts_to a (seq_of_base_array v));
a
}
```
val unarray_of_base
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(#v: Ghost.erased (Seq.seq t))
(r: ref (base_array0 tn td n))
(a: array td)
: stt_ghost (Ghost.erased (base_array_t t tn n))
(array_pts_to a v ** pure (
has_array_of_base r a
))
(fun v' -> pts_to r v' ** pure (
Ghost.reveal v `Seq.equal` seq_of_base_array v'
))
val freeable_array
(#t: Type)
(#td: typedef t)
(a: array td)
: Tot vprop
let freeable_or_null_array
(#t: Type)
(#td: typedef t)
(a: array_or_null td)
: Tot vprop
= if g_array_is_null a
then emp
else freeable_array a
[@@noextract_to "krml"] // primitive
val array_ptr_alloc
(#t: Type)
(td: typedef t)
(sz: SZ.t { SZ.v sz > 0 })
: stt (array_ptr td)
emp
(fun a ->
exists* (ar: array_or_null td) (s: Seq.seq t) .
freeable_or_null_array ar **
array_pts_to_or_null ar s ** pure (
array_ptr_of ar == a /\
(g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\
Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td)
))
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_alloc
(#t: Type)
(td: typedef t)
(sz: SZ.t { SZ.v sz > 0 })
requires
emp
returns ar: array_or_null td
ensures
(
freeable_or_null_array ar ** (
exists* s .
array_pts_to_or_null ar s ** pure (
(g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\
Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td)
)))
{
let a : array_ptr td = array_ptr_alloc td sz;
with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s);
let len: array_len_t a = array_len_of ar';
let ar = mk_array_or_null a len;
rewrite (array_pts_to_or_null ar' s)
as (array_pts_to_or_null ar s);
rewrite (freeable_or_null_array ar')
as (freeable_or_null_array ar);
ar
}
```
let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop =
forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i)
let full_seq_seq_of_base_array
(#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t)
(b: base_array_t t tn n)
: Lemma
(ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b))
[SMTPat (full_seq td (seq_of_base_array b))]
= assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i))
[@@noextract_to "krml"] // primitive
val array_ref_free
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array_ref td)
(n: array_len_t a)
: stt unit
(freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure (
full_seq td s
))
(fun _ -> emp)
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_free
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array td)
requires
(freeable_array a ** array_pts_to a s ** pure (
full_seq td s
))
ensures emp
{
let al = array_ptr_of a;
let n: array_len_t al = array_len_of a;
rewrite (freeable_array a) as (freeable_array (mk_array al n));
rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s);
array_ref_free al n
}
```
(*
val has_array_of_ref
(#t: Type)
(#td: typedef t)
(r: ref td)
(a: array td)
: Tot vprop
val has_array_of_ref_post
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ref td)
(a: array td)
: STGhost unit opened
(has_array_of_ref r a)
(fun _ -> has_array_of_ref r a)
(True)
(fun _ ->
let (| al, len |) = a in
array_ref_base_size al == 1sz /\
array_ref_offset al == 0sz /\
Ghost.reveal len == 1sz
)
// val has_array_of_ref_inj
// (#t: Type)
// (#td: typedef t)
// (r: ref td)
// (a1 a2: array td)
// : Lemma
// (requires (
// has_array_of_ref r a1 /\
// has_array_of_ref r a2
// ))
// (ensures a1 == a2)
val ghost_array_of_ref_focus
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(r: ref td)
(a: array td)
: stt_ghost unit opened
(pts_to r v ** has_array_of_ref r a)
(fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v)))
val ghost_array_of_ref
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(r: ref td)
: stt_ghost (Ghost.erased (array td)) opened
(pts_to r v)
(fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a)
// to be extracted to just r
[@@noextract_to "krml"] // primitive
val array_ref_of_ref
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(r: ref td)
: stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz })
(pts_to r v)
(fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |))
inline_for_extraction [@@noextract_to "krml"]
let array_of_ref
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(r: ref td)
: stt (array td)
(pts_to r v)
(fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a)
= let al = array_ref_of_ref r in
let a : array td = (| al, Ghost.hide 1sz |) in
rewrite (array_pts_to _ _) (array_pts_to _ _);
rewrite (has_array_of_ref _ _) (has_array_of_ref r a);
return a
val unarray_of_ref
(#t: Type)
(#opened: _)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(r: ref td)
(a: array td)
: stt_ghost (squash (Seq.length s == 1)) opened
(array_pts_to a s ** has_array_of_ref r a)
(fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a)
*)
val has_array_cell
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
(r: ref td)
: Tot vprop
(*
= SZ.v i < SZ.v (dsnd a) /\
has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r
*)
val has_array_cell_post
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_array_cell a i r')
(fun _ -> has_array_cell a i r' ** pure (
SZ.v i < SZ.v (dsnd a)
))
val has_array_cell_has_base_array_cell
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
(r: ref td)
(#ty: Type)
(br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a))))
: stt_ghost (Ghost.erased SZ.t)
(has_array_cell a i r ** pure (
has_array_ref_base (array_ptr_of a) br
))
(fun j -> has_base_array_cell br j r ** pure (
SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i
))
val has_base_array_cell_has_array_cell
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
(r: ref td)
(#ty: Type)
(br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a))))
: stt_ghost (Ghost.erased SZ.t)
(has_base_array_cell br i r ** pure (
has_array_ref_base (array_ptr_of a) br /\
SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\
SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a)
))
(fun j -> has_array_cell a j r ** pure (
SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j
))
val has_array_cell_inj
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(
has_array_cell a i r1 **
has_array_cell a i r2
)
(fun _ ->
has_array_cell a i r1 **
has_array_cell a i r2 **
ref_equiv r1 r2
)
// = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2
(*
val has_array_cell_array_of_ref
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ref td)
(a: array td)
: SteelGhostT unit opened
(has_array_of_ref r a)
(fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r)
*)
val ghost_array_cell_focus
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array td)
(i: SZ.t)
(r: ref td)
: stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a)))
(array_pts_to a s ** has_array_cell a i r)
(fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r)
val ghost_array_cell
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array td)
(i: SZ.t)
: stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) })
(array_pts_to a s ** pure (
SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a)
))
(fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r)
[@@noextract_to "krml"] // primitive
val array_ref_cell
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array_ref td)
(len: array_len_t a)
(i: SZ.t)
: stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len })
(array_pts_to (mk_array a len) s ** pure (
SZ.v i < Seq.length s \/ SZ.v i < SZ.v len
))
(fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r)
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_cell
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array td)
(i: SZ.t)
requires
(array_pts_to a s ** pure (
SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a)
))
returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) })
ensures
(array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r)
{
let al = array_ptr_of a;
let len = array_len_of a;
rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s);
let r = array_ref_cell al len i;
rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)));
rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r);
r
}
```
val unarray_cell
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(#v: Ghost.erased t)
(a: array td)
(i: SZ.t)
(r: ref td)
: stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a)))
(array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure (
SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td
))
(fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r)
val array_ref_shift
(#t: Type)
(#td: typedef t)
(a: array_ref td)
(i: SZ.t)
: Ghost (array_ref td)
(requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a)))
(ensures (fun y ->
array_ref_base_size y == array_ref_base_size a /\
(forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\
array_ref_offset y == array_ref_offset a `SZ.add` i
))
val array_ref_shift_zero
(#t: Type)
(#td: typedef t)
(a: array_ref td)
: Lemma
(ensures (
array_ref_shift a 0sz == a
))
val array_ref_shift_assoc
(#t: Type)
(#td: typedef t)
(a: array_ref td)
(i1 i2: SZ.t)
: Lemma
(requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a)))
(ensures (
array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2
))
inline_for_extraction [@@noextract_to "krml"]
let array_split_l
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
: Pure (array td)
(requires (SZ.v i <= SZ.v (dsnd a)))
(ensures (fun _ -> True))
= let (| al, _ |) = a in
(| al, Ghost.hide i |)
let array_split_r
(#t: Type)
(#td: typedef t)
(a: array td)
(i: SZ.t)
: Ghost (array td)
(requires (SZ.v i <= SZ.v (dsnd a)))
(ensures (fun _ -> True))
= let (| al, len |) = a in
(| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |)
val ghost_array_split
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array td)
(i: SZ.t)
: stt_ghost (squash (SZ.v i <= SZ.v (dsnd a) /\ Seq.length s == SZ.v (dsnd a)))
(array_pts_to a s ** pure (
SZ.v i <= SZ.v (dsnd a) \/ SZ.v i <= Seq.length s
))
(fun _ -> array_pts_to (array_split_l a i) (Seq.slice s 0 (SZ.v i)) **
array_pts_to (array_split_r a i) (Seq.slice s (SZ.v i) (Seq.length s)))
let array_ref_split_post
(#t: Type)
(#td: typedef t)
(s: Ghost.erased (Seq.seq t))
(a: array td)
(i: SZ.t)
(sl sr: Ghost.erased (Seq.seq t))
: GTot prop
= SZ.v i <= array_length a /\ Seq.length s == array_length a /\
Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\
Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s)
[@@noextract_to "krml"] // primitive
val array_ref_split
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(al: array_ref td)
(len: array_len_t al)
(i: SZ.t { SZ.v i <= SZ.v len })
: stt (array_ref td)
(array_pts_to (mk_array al len) s)
(fun ar -> exists* sl sr .
array_pts_to (array_split_l (mk_array al len) i) sl **
array_pts_to (array_split_r (mk_array al len) i) sr **
pure (
array_ref_split_post s (mk_array al len) i sl sr /\
SZ.v i <= SZ.v len /\ SZ.v i <= Seq.length s /\
ar == array_ptr_of (array_split_r (mk_array al len) i)
))
inline_for_extraction [@@noextract_to "krml"]
```pulse
fn array_split
(#t: Type)
(#td: typedef t)
(#s: Ghost.erased (Seq.seq t))
(a: array td)
(i: SZ.t { SZ.v i <= array_length a })
requires
(array_pts_to a s)
returns a': array td
ensures
(exists* sl sr .
array_pts_to (array_split_l a i) sl **
array_pts_to a' sr **
pure (
array_ref_split_post s a i sl sr /\
SZ.v i <= array_length a /\ SZ.v i <= Seq.length s /\
a' == array_split_r a i
))
{
let al = array_ptr_of a;
let len = array_len_of a;
rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s);
let ar = array_ref_split al len i;
with sl sr . assert (
array_pts_to (array_split_l (mk_array al len) i) sl **
array_pts_to (array_split_r (mk_array al len) i) sr
);
let a' = mk_array ar (Ghost.hide (len `SZ.sub` i));
rewrite (array_pts_to (array_split_l (mk_array al len) i) sl)
as (array_pts_to (array_split_l a i) sl);
rewrite (array_pts_to (array_split_r (mk_array al len) i) sr)
as (array_pts_to a' sr);
a'
}
```
val array_join
(#t: Type)
(#td: typedef t)
(#sl #sr: Ghost.erased (Seq.seq t))
(a al ar: array td)
(i: SZ.t)
: stt_ghost unit
(array_pts_to al sl ** array_pts_to ar sr ** pure (
SZ.v i <= SZ.v (dsnd a) /\
al == array_split_l a i /\
ar == array_split_r a i
))
(fun _ -> array_pts_to a (sl `Seq.append` sr)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> s: FStar.Seq.Base.seq t -> Prims.GTot Prims.prop | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.C.Types.Base.typedef",
"FStar.Seq.Base.seq",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Pulse.C.Types.Base.fractionable",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | false | true | let fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop =
| forall (i: nat). i < Seq.length s ==> fractionable td (Seq.index s i) | false |
IfcExample.fst | IfcExample.c1_0 | val c1_0 : body: While.com -> While.com | let c1_0 body = While (AVar c) body (AVar c) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | body: While.com -> While.com | Prims.Tot | [
"total"
] | [] | [
"While.com",
"While.While",
"While.AVar",
"IfcExample.c"
] | [] | false | false | false | true | false | let c1_0 body =
| While (AVar c) body (AVar c) | false |
|
IfcExample.fst | IfcExample.c1_1 | val c1_1 : While.com | let c1_1 = Assign x (AVar y) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"While.Assign",
"IfcExample.x",
"While.AVar",
"IfcExample.y"
] | [] | false | false | false | true | false | let c1_1 =
| Assign x (AVar y) | false |
|
IfcExample.fst | IfcExample.c1_2 | val c1_2 : While.com | let c1_2 = Assign y (AOp Plus (AVar x) (AInt 6)) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*)
let c1_0 body = While (AVar c) body (AVar c) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"While.Assign",
"IfcExample.y",
"While.AOp",
"While.Plus",
"While.AVar",
"IfcExample.x",
"While.AInt"
] | [] | false | false | false | true | false | let c1_2 =
| Assign y (AOp Plus (AVar x) (AInt 6)) | false |
|
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.mk_base_array_inj | val mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t)
: Lemma
(requires
(Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] | val mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t)
: Lemma
(requires
(Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] | let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 28,
"end_line": 53,
"start_col": 0,
"start_line": 44
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)] | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
tn: Type0 ->
n: Pulse.C.Types.Array.array_size_t ->
v1: FStar.Seq.Base.seq t ->
v2: FStar.Seq.Base.seq t
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length v1 == FStar.SizeT.v n /\ FStar.Seq.Base.length v2 == FStar.SizeT.v n /\
Pulse.C.Types.Array.mk_base_array tn n v1 == Pulse.C.Types.Array.mk_base_array tn n v2)
(ensures v1 == v2)
[
SMTPat (Pulse.C.Types.Array.mk_base_array tn n v1);
SMTPat (Pulse.C.Types.Array.mk_base_array tn n v2)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.C.Types.Array.array_size_t",
"FStar.Seq.Base.seq",
"Prims._assert",
"FStar.Seq.Base.equal",
"Prims.unit",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"Prims.eq2",
"Pulse.C.Types.Array.base_array_index",
"Pulse.C.Types.Array.mk_base_array",
"FStar.SizeT.uint_to_t",
"Prims.l_and",
"FStar.Seq.Base.length",
"Pulse.C.Types.Array.base_array_t",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t)
: Lemma
(requires
(Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] =
| assert (forall (i: nat).
i < SZ.v n ==>
base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) ==
base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2) | false |
IfcExample.fst | IfcExample.c1_3 | val c1_3 : While.com | let c1_3 = Assign z (AOp Plus (AVar y) (AInt 7)) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*)
let c1_0 body = While (AVar c) body (AVar c)
let c1_1 = Assign x (AVar y) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"While.Assign",
"IfcExample.z",
"While.AOp",
"While.Plus",
"While.AVar",
"IfcExample.y",
"While.AInt"
] | [] | false | false | false | true | false | let c1_3 =
| Assign z (AOp Plus (AVar y) (AInt 7)) | false |
|
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.array_len_of | val array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td)
: Tot (array_len_t (array_ptr_of ar)) | val array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td)
: Tot (array_len_t (array_ptr_of ar)) | let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) =
match ar with
| (| _, a |) -> a | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 217,
"start_col": 0,
"start_line": 215
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction
[@@noextract_to "krml"] // proof-only
let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n)
val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t
val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (a1 == a2)) /\
(y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i))
))
val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n)
(requires (
Seq.length v == SZ.v n
))
(ensures (fun y -> True))
val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma
(requires (Seq.length v == SZ.v n))
(ensures (
Seq.length v == SZ.v n /\
base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i)
))
[SMTPat (base_array_index (mk_base_array tn n v) i)]
let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma
(requires (
Seq.length v1 == SZ.v n /\
Seq.length v2 == SZ.v n /\
mk_base_array tn n v1 == mk_base_array tn n v2
))
(ensures (v1 == v2))
[SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)]
= assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i));
assert (v1 `Seq.equal` v2)
val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma
(
fractionable (base_array0 tn td n) a <==>
(forall (i: base_array_index_t n) . fractionable td (base_array_index a i))
)
[SMTPat (fractionable (base_array0 tn td n) a)]
val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma
(requires (
fractionable (base_array0 tn td n) a
))
(ensures (
fractionable (base_array0 tn td n) a /\
base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p
))
[SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)]
val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (unknown (base_array0 tn td n)) i == unknown td)
[SMTPat (base_array_index (unknown (base_array0 tn td n)) i)]
val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma
(base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td)
[SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)]
val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma
(full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i)))
[SMTPat (full (base_array0 tn td n) x)]
val has_base_array_cell
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: Tot vprop
val has_base_array_cell_post
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** pure (
SZ.v i < SZ.v n
))
val has_base_array_cell_dup
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r i r')
(fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r')
val has_base_array_cell_inj
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** has_base_array_cell r i r2)
(fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2)
val has_base_array_cell_equiv_from
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r1 r2: ref (base_array0 tn td n))
(i: SZ.t)
(r': ref td)
: stt_ghost unit
(has_base_array_cell r1 i r' ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2)
val has_base_array_cell_equiv_to
(#t: Type)
(#tn: Type0)
(#n: array_size_t)
(#td: typedef t)
(r: ref (base_array0 tn td n))
(i: SZ.t)
(r1 r2: ref td)
: stt_ghost unit
(has_base_array_cell r i r1 ** ref_equiv r1 r2)
(fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2)
// contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead
// To be extracted to: t* (array type decays to pointer type)
// We still want to prove that cutting off some cell range on the
// right-hand end of an array won't change the C pointer to which an
// array extracts to. This is why we separately introduce `array_ref`
// to represent the "base+offset" pointer, and `array` which holds the
// ghost length of an array.
[@@noextract_to "krml"] // primitive
val array_void_ptr : Type0
[@@noextract_to "krml"] // primitive
let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr
inline_for_extraction [@@noextract_to "krml"] // primitive
let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t
[@@noextract_to "krml"] // primitive
val null_array_void_ptr: array_void_ptr
[@@noextract_to "krml"] // primitive
let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr
val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool
(requires True)
(ensures (fun y -> y == true <==> a == null_array_ptr td))
inline_for_extraction [@@noextract_to "krml"]
let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false })
(*
val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0
*)
val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td))
val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop
val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma
(requires (has_array_ref_base a r1 /\ has_array_ref_base a r2))
(ensures (r1 == r2))
val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t
(requires True)
(ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a)))
val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma
(requires (
array_ref_base_size a1 == array_ref_base_size a2 /\
has_array_ref_base a1 r1 /\
has_array_ref_base a2 r2 /\
r1 == coerce_eq () r2 /\
array_ref_offset a1 == array_ref_offset a2
))
(ensures (a1 == a2))
inline_for_extraction [@@noextract_to "krml"]
let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 =
(len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) })
inline_for_extraction [@@noextract_to "krml"]
let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r)
inline_for_extraction [@@noextract_to "krml"]
let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) =
match ar with
| (| a, _ |) -> a | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ar: Pulse.C.Types.Array.array_or_null td
-> Pulse.C.Types.Array.array_len_t (Pulse.C.Types.Array.array_ptr_of ar) | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Array.array_or_null",
"Pulse.C.Types.Array.array_ptr",
"Pulse.C.Types.Array.array_len_t",
"Pulse.C.Types.Array.array_ptr_of"
] | [] | false | false | false | false | false | let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td)
: Tot (array_len_t (array_ptr_of ar)) =
| match ar with | (| _ , a |) -> a | false |
Hacl.Impl.K256.Verify.fst | Hacl.Impl.K256.Verify.ecdsa_verify_hashed_msg | val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature)) | val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature)) | let ecdsa_verify_hashed_msg msgHash public_key signature =
push_frame ();
let tmp = create 35ul (u64 0) in
let pk = sub tmp 0ul 15ul in
let r_q = sub tmp 15ul 4ul in
let s_q = sub tmp 19ul 4ul in
let u1 = sub tmp 23ul 4ul in
let u2 = sub tmp 27ul 4ul in
let m_q = sub tmp 31ul 4ul in
let is_pk_valid = load_point_vartime pk public_key in
let is_rs_valid = load_signature r_q s_q signature in
QA.load_qelem_modq m_q msgHash;
let res =
if not (is_pk_valid && is_rs_valid) then false
else begin
ecdsa_verify_get_u12 u1 u2 r_q s_q m_q;
ecdsa_verify_cmpr r_q pk u1 u2 end in
pop_frame ();
res | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 219,
"start_col": 0,
"start_line": 199
} | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline]
let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b
inline_for_extraction noextract
val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_avoid_finv p r =
let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
assert (modifies (loc r_fe) h0 h1);
//assert (inv_fully_reduced h1 r_fe);
//assert (as_nat h1 r_fe == qas_nat h1 r);
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
assert (modifies (loc tmp_x) h2 h3);
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h2 x);
//assert (inv_fully_reduced h3 tmp_x);
//assert (inv_lazy_reduced2 h3 z);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
//assert (is_rz_x == (S.fmul (as_nat h3 r_fe) (feval h3 z) = as_nat h3 tmp_x));
let res : bool =
if not is_rz_x then begin
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q then begin
assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1,1,1,1,1) (1,1,1,1,1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x end
//assert (is_rqz_x == (S.fmul (feval h5 tmp) (feval h5 z) = as_nat h5 tmp_x));
else false end
else true in
let h4 = ST.get () in
assert (modifies (loc tmp_q) h3 h4);
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res
inline_for_extraction noextract
val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_g_double_split_lambda_vartime res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (point_eval h1 res) ==
S.to_aff_point (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk)));
KL.lemma_aff_is_point_at_inf (point_eval h1 res);
KL.lemma_aff_is_point_at_inf (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk));
let b =
if is_proj_point_at_inf_vartime res then false
else ecdsa_verify_avoid_finv res r in
pop_frame ();
b
inline_for_extraction noextract
val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q)))
let load_signature r_q s_q signature =
let is_r_valid = QA.load_qelem_vartime r_q (sub signature 0ul 32ul) in
let is_s_valid = QA.load_qelem_vartime s_q (sub signature 32ul 32ul) in
is_r_valid && is_s_valid
inline_for_extraction noextract
val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.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.Impl.K256.Verify.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
msgHash: Hacl.Impl.K256.Verify.lbytes 32ul ->
public_key: Hacl.Impl.K256.Verify.lbytes 64ul ->
signature: Hacl.Impl.K256.Verify.lbytes 64ul
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.K256.Verify.lbytes",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Prims.op_Negation",
"Prims.op_AmpAmp",
"Hacl.Impl.K256.Verify.ecdsa_verify_cmpr",
"Hacl.Impl.K256.Verify.ecdsa_verify_get_u12",
"Hacl.K256.Scalar.load_qelem_modq",
"Hacl.Impl.K256.Verify.load_signature",
"Hacl.Impl.K256.Point.load_point_vartime",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.IntTypes.uint64",
"Lib.Buffer.create",
"Lib.IntTypes.u64",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let ecdsa_verify_hashed_msg msgHash public_key signature =
| push_frame ();
let tmp = create 35ul (u64 0) in
let pk = sub tmp 0ul 15ul in
let r_q = sub tmp 15ul 4ul in
let s_q = sub tmp 19ul 4ul in
let u1 = sub tmp 23ul 4ul in
let u2 = sub tmp 27ul 4ul in
let m_q = sub tmp 31ul 4ul in
let is_pk_valid = load_point_vartime pk public_key in
let is_rs_valid = load_signature r_q s_q signature in
QA.load_qelem_modq m_q msgHash;
let res =
if not (is_pk_valid && is_rs_valid)
then false
else
(ecdsa_verify_get_u12 u1 u2 r_q s_q m_q;
ecdsa_verify_cmpr r_q pk u1 u2)
in
pop_frame ();
res | false |
IfcExample.fst | IfcExample.env | val env : var: Prims.nat -> Prims.GTot IfcRules.label | let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 36,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | var: Prims.nat -> Prims.GTot IfcRules.label | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Monotonic.Heap.addr_of",
"FStar.Heap.trivial_preorder",
"IfcExample.x",
"IfcRules.Low",
"Prims.bool",
"IfcExample.y",
"IfcExample.c",
"IfcExample.z",
"IfcRules.High",
"IfcRules.label"
] | [] | false | false | false | false | false | let env (var: nat) =
| if var = addr_of x
then Low
else
if var = addr_of y
then Low
else if var = addr_of c then Low else if var = addr_of z then High else High | false |
|
Pulse.C.Types.Array.fsti | Pulse.C.Types.Array.base_array | val base_array
(#t #tn: Type0)
(td: typedef t)
(n: nat{SZ.fits n /\ n > 0})
(#[solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn)))
: Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) | val base_array
(#t #tn: Type0)
(td: typedef t)
(n: nat{SZ.fits n /\ n > 0})
(#[solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn)))
: Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) | let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n)))
= base_array0 tn td (SZ.uint_to_t n) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 22,
"start_col": 0,
"start_line": 21
} | module Pulse.C.Types.Array
open Pulse.Lib.Pervasives
include Pulse.C.Types.Base
open Pulse.C.Typenat
module SZ = FStar.SizeT
// To be extracted as: t[tn]
// Per the C standard, base array types must be of nonzero size
inline_for_extraction [@@noextract_to "krml"]
let array_size_t = (n: SZ.t { SZ.v n > 0 })
val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0
inline_for_extraction [@@noextract_to "krml"]
let base_array_index_t (n: array_size_t) : Tot eqtype =
Pulse.C.Types.Array.Base.array_domain (Ghost.hide n)
[@@noextract_to "krml"]
val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Types.Base.fsti.checked",
"Pulse.C.Types.Array.Base.fst.checked",
"Pulse.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Array.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Pulse.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> n: Prims.nat{FStar.SizeT.fits n /\ n > 0}
-> Pulse.C.Types.Base.typedef (Pulse.C.Types.Array.base_array_t t tn (FStar.SizeT.uint_to_t n)) | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Prims.nat",
"Prims.l_and",
"FStar.SizeT.fits",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.squash",
"FStar.Pervasives.norm",
"Pulse.C.Typenat.norm_typenat",
"Prims.eq2",
"Pulse.C.Typenat.nat_t_of_nat",
"Pulse.C.Types.Array.base_array0",
"FStar.SizeT.uint_to_t",
"Pulse.C.Types.Array.base_array_t"
] | [] | false | false | false | false | false | let base_array
(#t #tn: Type0)
(td: typedef t)
(n: nat{SZ.fits n /\ n > 0})
(#[solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn)))
: Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) =
| base_array0 tn td (SZ.uint_to_t n) | false |
IfcExample.fst | IfcExample.c1_5 | val c1_5 : While.com | let c1_5 = Assign c (AOp Minus (AVar c) (AInt 1)) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 54,
"start_col": 0,
"start_line": 54
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*)
let c1_0 body = While (AVar c) body (AVar c)
let c1_1 = Assign x (AVar y)
let c1_2 = Assign y (AOp Plus (AVar x) (AInt 6))
let c1_3 = Assign z (AOp Plus (AVar y) (AInt 7)) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"While.Assign",
"IfcExample.c",
"While.AOp",
"While.Minus",
"While.AVar",
"While.AInt"
] | [] | false | false | false | true | false | let c1_5 =
| Assign c (AOp Minus (AVar c) (AInt 1)) | false |
|
IfcExample.fst | IfcExample.c1_4 | val c1_4 : While.com | let c1_4 = Assign x (AOp Plus (AVar z) (AInt 7)) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 53,
"start_col": 0,
"start_line": 53
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*)
let c1_0 body = While (AVar c) body (AVar c)
let c1_1 = Assign x (AVar y)
let c1_2 = Assign y (AOp Plus (AVar x) (AInt 6)) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"While.Assign",
"IfcExample.x",
"While.AOp",
"While.Plus",
"While.AVar",
"IfcExample.z",
"While.AInt"
] | [] | false | false | false | true | false | let c1_4 =
| Assign x (AOp Plus (AVar z) (AInt 7)) | false |
|
IfcExample.fst | IfcExample.c1 | val c1 : While.com | let c1 = c1_0 c1_6 | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 57,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*)
let c1_0 body = While (AVar c) body (AVar c)
let c1_1 = Assign x (AVar y)
let c1_2 = Assign y (AOp Plus (AVar x) (AInt 6))
let c1_3 = Assign z (AOp Plus (AVar y) (AInt 7))
let c1_4 = Assign x (AOp Plus (AVar z) (AInt 7))
let c1_5 = Assign c (AOp Minus (AVar c) (AInt 1))
let c1_6 = Seq c1_1 (Seq c1_2 (Seq c1_3 (Seq c1_4 c1_5))) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"IfcExample.c1_0",
"IfcExample.c1_6"
] | [] | false | false | false | true | false | let c1 =
| c1_0 c1_6 | false |
|
IfcExample.fst | IfcExample.c1_6 | val c1_6 : While.com | let c1_6 = Seq c1_1 (Seq c1_2 (Seq c1_3 (Seq c1_4 c1_5))) | {
"file_name": "examples/rel/IfcExample.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 57,
"end_line": 55,
"start_col": 0,
"start_line": 55
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExample
open Rel
open While
open IfcRules
open FStar.Heap
open FStar.ST
(* (Warning) Top-level let-bindings must be total; this term may have effects *)
assume val x : ref int
assume val y : ref int
assume val z : ref int
assume val c : ref int
let env (var: nat) =
if var = addr_of x then Low
else if var = addr_of y then Low
else if var = addr_of c then Low
else if var = addr_of z then High
else High
(*
While c > 0{
x := y;
y := y + 6;
z := y + 7;
x := z + 7;
c := c - 1
}
*)
let c1_0 body = While (AVar c) body (AVar c)
let c1_1 = Assign x (AVar y)
let c1_2 = Assign y (AOp Plus (AVar x) (AInt 6))
let c1_3 = Assign z (AOp Plus (AVar y) (AInt 7))
let c1_4 = Assign x (AOp Plus (AVar z) (AInt 7)) | {
"checked_file": "/",
"dependencies": [
"While.fst.checked",
"Rel.fst.checked",
"prims.fst.checked",
"IfcRules.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "IfcExample.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "IfcRules",
"short_module": null
},
{
"abbrev": false,
"full_module": "While",
"short_module": null
},
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | While.com | Prims.Tot | [
"total"
] | [] | [
"While.Seq",
"IfcExample.c1_1",
"IfcExample.c1_2",
"IfcExample.c1_3",
"IfcExample.c1_4",
"IfcExample.c1_5"
] | [] | false | false | false | true | false | let c1_6 =
| Seq c1_1 (Seq c1_2 (Seq c1_3 (Seq c1_4 c1_5))) | false |
|
FStar.Pure.BreakVC.fsti | FStar.Pure.BreakVC.break_wp | val break_wp:pure_wp unit | val break_wp:pure_wp unit | let break_wp : pure_wp unit =
let _ = mono_lem () in
break_wp' | {
"file_name": "ulib/FStar.Pure.BreakVC.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 19,
"start_col": 0,
"start_line": 17
} | module FStar.Pure.BreakVC
open FStar.Tactics
let break_wp' : pure_wp' unit =
fun p -> spinoff (squash (p ()))
val mono_lem () : Lemma (pure_wp_monotonic unit break_wp')
private
let post () : Tac unit =
norm [delta_fully [`%mono_lem; `%break_wp']];
trefl()
[@@postprocess_with post] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Pure.BreakVC.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.pure_wp Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Prims.l_True",
"FStar.Pervasives.spinoff",
"Prims.squash",
"Prims.pure_pre"
] | [] | false | false | false | true | false | let break_wp:pure_wp unit =
| let _ = mono_lem () in
break_wp' | false |
ExtractRefs.fst | ExtractRefs.swap | val swap (r1 r2: ref U32.t)
: Steel unit
((vptr r1) `star` (vptr r2))
(fun _ -> (vptr r1) `star` (vptr r2))
(requires fun _ -> True)
(ensures fun h0 _ h1 -> sel r1 h0 == sel r2 h1 /\ sel r2 h0 == sel r1 h1) | val swap (r1 r2: ref U32.t)
: Steel unit
((vptr r1) `star` (vptr r2))
(fun _ -> (vptr r1) `star` (vptr r2))
(requires fun _ -> True)
(ensures fun h0 _ h1 -> sel r1 h0 == sel r2 h1 /\ sel r2 h0 == sel r1 h1) | let swap (r1 r2:ref U32.t) : Steel unit
(vptr r1 `star` vptr r2)
(fun _ -> vptr r1 `star` vptr r2)
(requires fun _ -> True)
(ensures fun h0 _ h1 ->
sel r1 h0 == sel r2 h1 /\
sel r2 h0 == sel r1 h1)
= let x1 = read r1 in
let x2 = read r2 in
write r2 x1;
write r1 x2 | {
"file_name": "share/steel/tutorial/ExtractRefs.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 27,
"start_col": 0,
"start_line": 17
} | module ExtractRefs
open FStar.Ghost
open Steel.FractionalPermission
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Reference
module U32 = FStar.UInt32
/// Some examples using Steel references with fractional permissions
#push-options "--fuel 0 --ifuel 0 --ide_id_info_off"
(** Swap examples **) | {
"checked_file": "/",
"dependencies": [
"Steel.Reference.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ExtractRefs.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r1: Steel.Reference.ref FStar.UInt32.t -> r2: Steel.Reference.ref FStar.UInt32.t
-> Steel.Effect.Steel Prims.unit | Steel.Effect.Steel | [] | [] | [
"Steel.Reference.ref",
"FStar.UInt32.t",
"Steel.Reference.write",
"Prims.unit",
"Steel.Reference.read",
"Steel.Effect.Common.star",
"Steel.Reference.vptr",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of",
"Steel.Reference.sel"
] | [] | false | true | false | false | false | let swap (r1 r2: ref U32.t)
: Steel unit
((vptr r1) `star` (vptr r2))
(fun _ -> (vptr r1) `star` (vptr r2))
(requires fun _ -> True)
(ensures fun h0 _ h1 -> sel r1 h0 == sel r2 h1 /\ sel r2 h0 == sel r1 h1) =
| let x1 = read r1 in
let x2 = read r2 in
write r2 x1;
write r1 x2 | false |
Lib.IntTypes.fst | Lib.IntTypes.cast | val cast: #t:inttype -> #l:secrecy_level
-> t':inttype
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> u1:int_t t l{unsigned t' \/ range (v u1) t'}
-> u2:int_t t' l'{v u2 == v u1 @%. t'} | val cast: #t:inttype -> #l:secrecy_level
-> t':inttype
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> u1:int_t t l{unsigned t' \/ range (v u1) t'}
-> u2:int_t t' l'{v u2 == v u1 @%. t'} | let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 261,
"start_col": 0,
"start_line": 116
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 1000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t': Lib.IntTypes.inttype ->
l': Lib.IntTypes.secrecy_level{PUB? l \/ SEC? l'} ->
u1:
Lib.IntTypes.int_t t l {Lib.IntTypes.unsigned t' \/ Lib.IntTypes.range (Lib.IntTypes.v u1) t'}
-> u2: Lib.IntTypes.int_t t' l' {Lib.IntTypes.v u2 == Lib.IntTypes.v u1 @%. t'} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Prims.l_or",
"Prims.b2t",
"Lib.IntTypes.uu___is_PUB",
"Lib.IntTypes.uu___is_SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Int.Cast.uint8_to_uint16",
"FStar.Int.Cast.uint8_to_uint32",
"FStar.Int.Cast.uint8_to_uint64",
"FStar.UInt128.uint64_to_uint128",
"FStar.Int.Cast.uint8_to_int8",
"FStar.Int.Cast.uint8_to_int16",
"FStar.Int.Cast.uint8_to_int32",
"FStar.Int.Cast.uint8_to_int64",
"Lib.IntTypes.uint64_to_int128",
"FStar.UInt8.rem",
"FStar.UInt8.__uint_to_t",
"FStar.Int.Cast.uint16_to_uint8",
"FStar.Int.Cast.uint16_to_uint32",
"FStar.Int.Cast.uint16_to_uint64",
"FStar.Int.Cast.uint16_to_int8",
"FStar.Int.Cast.uint16_to_int16",
"FStar.Int.Cast.uint16_to_int32",
"FStar.Int.Cast.uint16_to_int64",
"FStar.Int.Cast.uint32_to_uint8",
"FStar.Int.Cast.uint32_to_uint16",
"FStar.Int.Cast.uint32_to_uint64",
"FStar.Int.Cast.uint32_to_int8",
"FStar.Int.Cast.uint32_to_int16",
"FStar.Int.Cast.uint32_to_int32",
"FStar.Int.Cast.uint32_to_int64",
"FStar.Int.Cast.uint64_to_uint8",
"FStar.Int.Cast.uint64_to_uint16",
"FStar.Int.Cast.uint64_to_uint32",
"FStar.Int.Cast.uint64_to_int8",
"FStar.Int.Cast.uint64_to_int16",
"FStar.Int.Cast.uint64_to_int32",
"FStar.Int.Cast.uint64_to_int64",
"FStar.Int.Cast.Full.uint128_to_uint64",
"FStar.UInt128.uint128_to_uint64",
"Lib.IntTypes.uint128_to_int128",
"FStar.Int.Cast.int8_to_uint8",
"FStar.Int.Cast.int8_to_uint16",
"FStar.Int.Cast.int8_to_uint32",
"FStar.Int.Cast.int8_to_uint64",
"Lib.IntTypes.int64_to_uint128",
"FStar.Int.Cast.int8_to_int64",
"FStar.Int.Cast.int8_to_int16",
"FStar.Int.Cast.int8_to_int32",
"Lib.IntTypes.int64_to_int128",
"FStar.Int.Cast.int16_to_uint8",
"FStar.Int.Cast.int16_to_uint16",
"FStar.Int.Cast.int16_to_uint32",
"FStar.Int.Cast.int16_to_uint64",
"FStar.Int.Cast.int16_to_int64",
"FStar.Int.Cast.int16_to_int8",
"FStar.Int.Cast.int16_to_int32",
"FStar.Int.Cast.int32_to_uint8",
"FStar.Int.Cast.int32_to_uint16",
"FStar.Int.Cast.int32_to_uint32",
"FStar.Int.Cast.int32_to_uint64",
"FStar.Int.Cast.int32_to_int64",
"FStar.Int.Cast.int32_to_int8",
"FStar.Int.Cast.int32_to_int16",
"FStar.Int.Cast.int64_to_uint8",
"FStar.Int.Cast.int64_to_uint16",
"FStar.Int.Cast.int64_to_uint32",
"FStar.Int.Cast.int64_to_uint64",
"FStar.Int.Cast.int64_to_int8",
"FStar.Int.Cast.int64_to_int16",
"FStar.Int.Cast.int64_to_int32",
"Lib.IntTypes.int128_to_uint64",
"Lib.IntTypes.int128_to_uint128",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.op_At_Percent_Dot",
"Prims.unit",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | false | let cast #t #l t' l' u =
| assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.