effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Pervasives.Lemma | val map_append (#a #b: Type) (f: (a -> Tot b)) (l1 l2: list a)
: Lemma (ensures map f (l1 @ l2) == map f l1 @ map f l2) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2 | val map_append (#a #b: Type) (f: (a -> Tot b)) (l1 l2: list a)
: Lemma (ensures map f (l1 @ l2) == map f l1 @ map f l2)
let rec map_append (#a #b: Type) (f: (a -> Tot b)) (l1 l2: list a)
: Lemma (ensures map f (l1 @ l2) == map f l1 @ map f l2) = | false | null | true | match l1 with
| [] -> ()
| x :: q -> map_append f q l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.map_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Base.op_At",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val map_append (#a #b: Type) (f: (a -> Tot b)) (l1 l2: list a)
: Lemma (ensures map f (l1 @ l2) == map f l1 @ map f l2) | [
"recursion"
] | FStar.List.Tot.Properties.map_append | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> b) -> l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.map f (l1 @ l2) ==
FStar.List.Tot.Base.map f l1 @ FStar.List.Tot.Base.map f l2) | {
"end_col": 31,
"end_line": 839,
"start_col": 2,
"start_line": 837
} |
FStar.Pervasives.Lemma | val noRepeats_append_elim (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(decreases l1) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2 | val noRepeats_append_elim (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(decreases l1)
let rec noRepeats_append_elim (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(decreases l1) = | false | null | true | match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"Prims.list",
"FStar.List.Tot.Properties.noRepeats_append_elim",
"Prims.unit",
"FStar.List.Tot.Properties.append_mem",
"Prims.b2t",
"FStar.List.Tot.Base.noRepeats",
"FStar.List.Tot.Base.op_At",
"Prims.squash",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.List.Tot.Base.mem",
"Prims.l_not",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2)))) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val noRepeats_append_elim (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(decreases l1) | [
"recursion"
] | FStar.List.Tot.Properties.noRepeats_append_elim | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.noRepeats (l1 @ l2))
(ensures
FStar.List.Tot.Base.noRepeats l1 /\ FStar.List.Tot.Base.noRepeats l2 /\
(forall (x: a). FStar.List.Tot.Base.mem x l1 ==> ~(FStar.List.Tot.Base.mem x l2)))
(decreases l1) | {
"end_col": 31,
"end_line": 684,
"start_col": 2,
"start_line": 680
} |
FStar.Pervasives.Lemma | val lemma_append_last (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0)) (ensures (last (l1 @ l2) == last l2)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2 | val lemma_append_last (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0)) (ensures (last (l1 @ l2) == last l2))
let rec lemma_append_last (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0)) (ensures (last (l1 @ l2) == last l2)) = | false | null | true | match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.lemma_append_last",
"Prims.unit",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.last",
"FStar.List.Tot.Base.op_At",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_last (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0)) (ensures (last (l1 @ l2) == last l2)) | [
"recursion"
] | FStar.List.Tot.Properties.lemma_append_last | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.length l2 > 0)
(ensures FStar.List.Tot.Base.last (l1 @ l2) == FStar.List.Tot.Base.last l2) | {
"end_col": 40,
"end_line": 311,
"start_col": 2,
"start_line": 309
} |
FStar.Pervasives.Lemma | val noRepeats_append_intro (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2 | val noRepeats_append_intro (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
let rec noRepeats_append_intro (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1) = | false | null | true | match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"Prims.list",
"FStar.List.Tot.Properties.noRepeats_append_intro",
"Prims.unit",
"FStar.List.Tot.Properties.append_mem",
"Prims.l_and",
"Prims.b2t",
"FStar.List.Tot.Base.noRepeats",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.List.Tot.Base.mem",
"Prims.l_not",
"Prims.squash",
"FStar.List.Tot.Base.op_At",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2))) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val noRepeats_append_intro (#a: eqtype) (l1 l2: list a)
: Lemma (requires (noRepeats l1 /\ noRepeats l2 /\ (forall x. mem x l1 ==> ~(mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1) | [
"recursion"
] | FStar.List.Tot.Properties.noRepeats_append_intro | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.noRepeats l1 /\ FStar.List.Tot.Base.noRepeats l2 /\
(forall (x: a). FStar.List.Tot.Base.mem x l1 ==> ~(FStar.List.Tot.Base.mem x l2)))
(ensures FStar.List.Tot.Base.noRepeats (l1 @ l2))
(decreases l1) | {
"end_col": 32,
"end_line": 697,
"start_col": 2,
"start_line": 693
} |
FStar.Pervasives.Lemma | val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l))))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x | val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = | false | null | true | match l with
| [] -> ()
| hd :: tl -> partition_count f tl x | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"Prims.bool",
"Prims.list",
"FStar.List.Tot.Properties.partition_count",
"Prims.unit"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l))))) | [
"recursion"
] | FStar.List.Tot.Properties.partition_count | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> Prims.bool) -> l: Prims.list a -> x: a
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.count x l =
FStar.List.Tot.Base.count x (FStar.Pervasives.Native.fst (FStar.List.Tot.Base.partition f l)) +
FStar.List.Tot.Base.count x (FStar.Pervasives.Native.snd (FStar.List.Tot.Base.partition f l))) | {
"end_col": 36,
"end_line": 563,
"start_col": 35,
"start_line": 561
} |
FStar.Pervasives.Lemma | val assoc_append_elim_l (#a: eqtype) (#b: Type) (x: a) (l1 l2: list (a * b))
: Lemma (requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2 | val assoc_append_elim_l (#a: eqtype) (#b: Type) (x: a) (l1 l2: list (a * b))
: Lemma (requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
let rec assoc_append_elim_l (#a: eqtype) (#b: Type) (x: a) (l1 l2: list (a * b))
: Lemma (requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1) = | false | null | true | match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Equality",
"Prims._assert",
"Prims.l_False",
"Prims.bool",
"FStar.List.Tot.Properties.assoc_append_elim_l",
"Prims.unit",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.List.Tot.Base.assoc",
"FStar.Pervasives.Native.None",
"Prims.squash",
"FStar.List.Tot.Base.op_At",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2)) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val assoc_append_elim_l (#a: eqtype) (#b: Type) (x: a) (l1 l2: list (a * b))
: Lemma (requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1) | [
"recursion"
] | FStar.List.Tot.Properties.assoc_append_elim_l | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> l1: Prims.list (a * b) -> l2: Prims.list (a * b)
-> FStar.Pervasives.Lemma
(requires FStar.List.Tot.Base.assoc x l1 == FStar.Pervasives.Native.None)
(ensures FStar.List.Tot.Base.assoc x (l1 @ l2) == FStar.List.Tot.Base.assoc x l2)
(decreases l1) | {
"end_col": 79,
"end_line": 754,
"start_col": 2,
"start_line": 752
} |
FStar.Pervasives.Lemma | val fold_left_map
(#a #b #c: Type)
(f_aba: (a -> b -> Tot a))
(f_bc: (b -> Tot c))
(f_aca: (a -> c -> Tot a))
(l: list b)
: Lemma (requires forall (x: a) (y: b). f_aba x y == f_aca x (f_bc y))
(ensures forall (x: a). fold_left f_aba x l == fold_left f_aca x (map f_bc l)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q | val fold_left_map
(#a #b #c: Type)
(f_aba: (a -> b -> Tot a))
(f_bc: (b -> Tot c))
(f_aca: (a -> c -> Tot a))
(l: list b)
: Lemma (requires forall (x: a) (y: b). f_aba x y == f_aca x (f_bc y))
(ensures forall (x: a). fold_left f_aba x l == fold_left f_aca x (map f_bc l))
let rec fold_left_map
(#a #b #c: Type)
(f_aba: (a -> b -> Tot a))
(f_bc: (b -> Tot c))
(f_aca: (a -> c -> Tot a))
(l: list b)
: Lemma (requires forall (x: a) (y: b). f_aba x y == f_aca x (f_bc y))
(ensures forall (x: a). fold_left f_aba x l == fold_left f_aca x (map f_bc l)) = | false | null | true | match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.fold_left_map",
"Prims.unit",
"Prims.l_Forall",
"Prims.eq2",
"Prims.squash",
"FStar.List.Tot.Base.fold_left",
"FStar.List.Tot.Base.map",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) ) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fold_left_map
(#a #b #c: Type)
(f_aba: (a -> b -> Tot a))
(f_bc: (b -> Tot c))
(f_aca: (a -> c -> Tot a))
(l: list b)
: Lemma (requires forall (x: a) (y: b). f_aba x y == f_aca x (f_bc y))
(ensures forall (x: a). fold_left f_aba x l == fold_left f_aca x (map f_bc l)) | [
"recursion"
] | FStar.List.Tot.Properties.fold_left_map | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f_aba: (_: a -> _: b -> a) -> f_bc: (_: b -> c) -> f_aca: (_: a -> _: c -> a) -> l: Prims.list b
-> FStar.Pervasives.Lemma (requires forall (x: a) (y: b). f_aba x y == f_aca x (f_bc y))
(ensures
forall (x: a).
FStar.List.Tot.Base.fold_left f_aba x l ==
FStar.List.Tot.Base.fold_left f_aca x (FStar.List.Tot.Base.map f_bc l)) | {
"end_col": 46,
"end_line": 827,
"start_col": 2,
"start_line": 825
} |
FStar.Pervasives.Lemma | val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2)))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl | val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = | false | null | true | match l with
| [] -> ()
| hd :: tl -> partition_mem_forall f tl | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"Prims.bool",
"Prims.list",
"FStar.List.Tot.Properties.partition_mem_forall",
"Prims.unit"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2)))) | [
"recursion"
] | FStar.List.Tot.Properties.partition_mem_forall | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> Prims.bool) -> l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
(let _ = FStar.List.Tot.Base.partition f l in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in
forall (x: a).
FStar.List.Tot.Base.mem x l =
(FStar.List.Tot.Base.mem x l1 || FStar.List.Tot.Base.mem x l2))
<:
Type0)) | {
"end_col": 39,
"end_line": 540,
"start_col": 38,
"start_line": 538
} |
FStar.Pervasives.Lemma | val index_extensionality (#a: Type) (l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\ (forall (i: nat). i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ()) | val index_extensionality (#a: Type) (l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\ (forall (i: nat). i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
let index_extensionality (#a: Type) (l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\ (forall (i: nat). i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2)) = | false | null | true | index_extensionality_aux l1 l2 () (fun i -> ()) | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.index_extensionality_aux",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.List.Tot.Base.length",
"Prims.unit",
"Prims.eq2",
"FStar.List.Tot.Base.index",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i))) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val index_extensionality (#a: Type) (l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\ (forall (i: nat). i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2)) | [] | FStar.List.Tot.Properties.index_extensionality | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.length l1 == FStar.List.Tot.Base.length l2 /\
(forall (i: Prims.nat).
i < FStar.List.Tot.Base.length l1 ==>
FStar.List.Tot.Base.index l1 i == FStar.List.Tot.Base.index l2 i)) (ensures l1 == l2) | {
"end_col": 49,
"end_line": 910,
"start_col": 2,
"start_line": 910
} |
FStar.Pervasives.Lemma | val fold_left_monoid (#a: Type) (opA: (a -> a -> Tot a)) (zeroA: a) (l: list a)
: Lemma
(requires
(forall u v w. (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x. (x `opA` zeroA) == x) /\ (forall x. (zeroA `opA` x) == x))
(ensures forall x. (fold_left opA x l) == (x `opA` (fold_left opA zeroA l))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q | val fold_left_monoid (#a: Type) (opA: (a -> a -> Tot a)) (zeroA: a) (l: list a)
: Lemma
(requires
(forall u v w. (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x. (x `opA` zeroA) == x) /\ (forall x. (zeroA `opA` x) == x))
(ensures forall x. (fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
let rec fold_left_monoid (#a: Type) (opA: (a -> a -> Tot a)) (zeroA: a) (l: list a)
: Lemma
(requires
(forall u v w. (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x. (x `opA` zeroA) == x) /\ (forall x. (zeroA `opA` x) == x))
(ensures forall x. (fold_left opA x l) == (x `opA` (fold_left opA zeroA l))) = | false | null | true | match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.fold_left_monoid",
"Prims.unit",
"Prims.l_and",
"Prims.l_Forall",
"Prims.eq2",
"Prims.squash",
"FStar.List.Tot.Base.fold_left",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x . | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fold_left_monoid (#a: Type) (opA: (a -> a -> Tot a)) (zeroA: a) (l: list a)
: Lemma
(requires
(forall u v w. (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x. (x `opA` zeroA) == x) /\ (forall x. (zeroA `opA` x) == x))
(ensures forall x. (fold_left opA x l) == (x `opA` (fold_left opA zeroA l))) | [
"recursion"
] | FStar.List.Tot.Properties.fold_left_monoid | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | opA: (_: a -> _: a -> a) -> zeroA: a -> l: Prims.list a
-> FStar.Pervasives.Lemma
(requires
(forall (u297: a) (v: a) (w: a). opA u297 (opA v w) == opA (opA u297 v) w) /\
(forall (x: a). opA x zeroA == x) /\ (forall (x: a). opA zeroA x == x))
(ensures
forall (x: a).
FStar.List.Tot.Base.fold_left opA x l == opA x (FStar.List.Tot.Base.fold_left opA zeroA l)
) | {
"end_col": 42,
"end_line": 866,
"start_col": 2,
"start_line": 864
} |
FStar.Pervasives.Lemma | val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x)))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl | val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = | false | null | true | match l with
| [] -> ()
| hd :: tl -> partition_mem_p_forall p tl | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"Prims.bool",
"Prims.list",
"FStar.List.Tot.Properties.partition_mem_p_forall",
"Prims.unit"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x)))) | [
"recursion"
] | FStar.List.Tot.Properties.partition_mem_p_forall | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | p: (_: a -> Prims.bool) -> l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
(let _ = FStar.List.Tot.Base.partition p l in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in
(forall (x: a). FStar.List.Tot.Base.mem x l1 ==> p x) /\
(forall (x: a). FStar.List.Tot.Base.mem x l2 ==> Prims.op_Negation (p x)))
<:
Type0)) | {
"end_col": 41,
"end_line": 551,
"start_col": 40,
"start_line": 549
} |
FStar.Pervasives.Lemma | val strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma (requires True) (ensures (strict_suffix_of [] (x :: l))) (decreases l) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q | val strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma (requires True) (ensures (strict_suffix_of [] (x :: l))) (decreases l)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma (requires True) (ensures (strict_suffix_of [] (x :: l))) (decreases l) = | false | null | true | match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.list",
"FStar.List.Tot.Properties.strict_suffix_of_nil",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.List.Tot.Base.strict_suffix_of",
"Prims.Nil",
"Prims.Cons",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l))) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma (requires True) (ensures (strict_suffix_of [] (x :: l))) (decreases l) | [
"recursion"
] | FStar.List.Tot.Properties.strict_suffix_of_nil | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> l: Prims.list a
-> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.strict_suffix_of [] (x :: l)) (decreases l) | {
"end_col": 40,
"end_line": 921,
"start_col": 2,
"start_line": 919
} |
FStar.Pervasives.Lemma | val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))] | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot | val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = | false | null | true | match l1 with
| [] -> ()
| hd :: tl -> append_sorted f tl l2 pivot | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"Prims.bool",
"Prims.list",
"Prims.b2t",
"FStar.List.Tot.Properties.sorted",
"FStar.List.Tot.Properties.append_sorted",
"Prims.unit"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2)))) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))] | [
"recursion"
] | FStar.List.Tot.Properties.append_sorted | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: a -> _: a -> Prims.bool) ->
l1: Prims.list a {FStar.List.Tot.Properties.sorted f l1} ->
l2: Prims.list a {FStar.List.Tot.Properties.sorted f l2} ->
pivot: a
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Properties.total_order f /\
(forall (y: a). FStar.List.Tot.Base.mem y l1 ==> Prims.op_Negation (f pivot y)) /\
(forall (y: a). FStar.List.Tot.Base.mem y l2 ==> f pivot y))
(ensures FStar.List.Tot.Properties.sorted f (l1 @ pivot :: l2))
[SMTPat (FStar.List.Tot.Properties.sorted f (l1 @ pivot :: l2))] | {
"end_col": 41,
"end_line": 636,
"start_col": 41,
"start_line": 634
} |
FStar.Pervasives.Lemma | val fold_left_append (#a #b: Type) (f: (a -> b -> Tot a)) (l1 l2: list b)
: Lemma (ensures forall x. fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2 | val fold_left_append (#a #b: Type) (f: (a -> b -> Tot a)) (l1 l2: list b)
: Lemma (ensures forall x. fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
let rec fold_left_append (#a #b: Type) (f: (a -> b -> Tot a)) (l1 l2: list b)
: Lemma (ensures forall x. fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2) = | false | null | true | match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.fold_left_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.eq2",
"FStar.List.Tot.Base.fold_left",
"FStar.List.Tot.Base.op_At",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fold_left_append (#a #b: Type) (f: (a -> b -> Tot a)) (l1 l2: list b)
: Lemma (ensures forall x. fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2) | [
"recursion"
] | FStar.List.Tot.Properties.fold_left_append | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> _: b -> a) -> l1: Prims.list b -> l2: Prims.list b
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.List.Tot.Base.fold_left f x (l1 @ l2) ==
FStar.List.Tot.Base.fold_left f (FStar.List.Tot.Base.fold_left f x l1) l2) | {
"end_col": 37,
"end_line": 849,
"start_col": 2,
"start_line": 847
} |
Prims.Tot | val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl) | val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = | false | null | false | function
| [] | [_] -> true
| x :: y :: tl -> f x y && sorted f (y :: tl) | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"total"
] | [
"Prims.bool",
"Prims.list",
"Prims.op_AmpAmp",
"FStar.List.Tot.Properties.sorted",
"Prims.Cons"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool | [
"recursion"
] | FStar.List.Tot.Properties.sorted | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: 'a -> _: 'a -> Prims.bool) -> _: Prims.list 'a -> Prims.bool | {
"end_col": 41,
"end_line": 613,
"start_col": 19,
"start_line": 610
} |
FStar.Pervasives.Lemma | val lemma_unsnoc_is_last (#t: Type) (l: list t)
: Lemma (requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l) | val lemma_unsnoc_is_last (#t: Type) (l: list t)
: Lemma (requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1)))
let rec lemma_unsnoc_is_last (#t: Type) (l: list t)
: Lemma (requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) = | false | null | true | match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l) | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.lemma_unsnoc_is_last",
"FStar.List.Tot.Base.tl",
"Prims.unit",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.snd",
"FStar.List.Tot.Base.unsnoc",
"FStar.List.Tot.Base.last",
"FStar.List.Tot.Base.index",
"Prims.op_Subtraction",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0)) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_unsnoc_is_last (#t: Type) (l: list t)
: Lemma (requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) | [
"recursion"
] | FStar.List.Tot.Properties.lemma_unsnoc_is_last | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list t
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.length l > 0)
(ensures
FStar.Pervasives.Native.snd (FStar.List.Tot.Base.unsnoc l) == FStar.List.Tot.Base.last l /\
FStar.Pervasives.Native.snd (FStar.List.Tot.Base.unsnoc l) ==
FStar.List.Tot.Base.index l (FStar.List.Tot.Base.length l - 1)) | {
"end_col": 36,
"end_line": 446,
"start_col": 2,
"start_line": 444
} |
FStar.Pervasives.Lemma | val index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit{length l1 == length l2}))
(l_index: (i: (i: nat{i < length l1}) -> Tot (l_index: unit{index l1 i == index l2 i})))
: Lemma (ensures (l1 == l2)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> () | val index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit{length l1 == length l2}))
(l_index: (i: (i: nat{i < length l1}) -> Tot (l_index: unit{index l1 i == index l2 i})))
: Lemma (ensures (l1 == l2))
let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit{length l1 == length l2}))
(l_index: (i: (i: nat{i < length l1}) -> Tot (l_index: unit{index l1 i == index l2 i})))
: Lemma (ensures (l1 == l2)) = | false | null | true | match (l1, l2) with
| a1 :: q1, a2 :: q2 ->
let a_eq:(a_eq: unit{a1 == a2}) = l_index 0 in
let q_len:(q_len: unit{length q1 == length q2}) = () in
let q_index (i: (i: nat{i < length q1})) : Tot (q_index: unit{index q1 i == index q2 i}) =
l_index (i + 1)
in
let q_eq:(q_eq: unit{l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> () | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"Prims.unit",
"Prims.eq2",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.List.Tot.Base.index",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Properties.index_extensionality_aux",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple2",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit{length l1 == length l2}))
(l_index: (i: (i: nat{i < length l1}) -> Tot (l_index: unit{index l1 i == index l2 i})))
: Lemma (ensures (l1 == l2)) | [
"recursion"
] | FStar.List.Tot.Properties.index_extensionality_aux | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
l1: Prims.list a ->
l2: Prims.list a ->
l_len: Prims.unit{FStar.List.Tot.Base.length l1 == FStar.List.Tot.Base.length l2} ->
l_index:
(i: Prims.nat{i < FStar.List.Tot.Base.length l1}
-> l_index: Prims.unit{FStar.List.Tot.Base.index l1 i == FStar.List.Tot.Base.index l2 i})
-> FStar.Pervasives.Lemma (ensures l1 == l2) | {
"end_col": 11,
"end_line": 900,
"start_col": 2,
"start_line": 892
} |
FStar.Pervasives.Lemma | val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot | val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = | false | null | true | match l with
| [] -> ()
| pivot :: tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot :: sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"Prims.int",
"Prims.list",
"FStar.List.Tot.Properties.append_sorted",
"FStar.List.Tot.Base.bool_of_compare",
"FStar.List.Tot.Base.sortWith",
"Prims.unit",
"FStar.List.Tot.Properties.append_mem_forall",
"Prims.Cons",
"FStar.List.Tot.Properties.sortWith_sorted",
"FStar.List.Tot.Properties.partition_mem_p_forall",
"FStar.List.Tot.Properties.partition_mem_forall",
"FStar.List.Tot.Base.partition_length",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.partition"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l)))) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l)) | [
"recursion"
] | FStar.List.Tot.Properties.sortWith_sorted | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> _: a -> Prims.int) -> l: Prims.list a
-> FStar.Pervasives.Lemma
(requires FStar.List.Tot.Properties.total_order (FStar.List.Tot.Base.bool_of_compare f))
(ensures
FStar.List.Tot.Properties.sorted (FStar.List.Tot.Base.bool_of_compare f)
(FStar.List.Tot.Base.sortWith f l) /\
(forall (x: a).
FStar.List.Tot.Base.mem x l =
FStar.List.Tot.Base.mem x (FStar.List.Tot.Base.sortWith f l)))
(decreases FStar.List.Tot.Base.length l) | {
"end_col": 78,
"end_line": 655,
"start_col": 33,
"start_line": 645
} |
FStar.Pervasives.Lemma | val lemma_unsnoc_append (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0))
(ensures
(let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2 | val lemma_unsnoc_append (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0))
(ensures
(let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b))
let rec lemma_unsnoc_append (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0))
(ensures
(let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) = | false | null | true | match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.lemma_unsnoc_append",
"Prims.unit",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.List.Tot.Base.op_At",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.unsnoc",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_unsnoc_append (#a: Type) (l1 l2: list a)
: Lemma (requires (length l2 > 0))
(ensures
(let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) | [
"recursion"
] | FStar.List.Tot.Properties.lemma_unsnoc_append | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.length l2 > 0)
(ensures
(let _ = FStar.List.Tot.Base.unsnoc (l1 @ l2) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ al a = _ in
let _ = FStar.List.Tot.Base.unsnoc l2 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ bl b = _ in
al == l1 @ bl /\ a == b)
<:
Type0)
<:
Type0)) | {
"end_col": 42,
"end_line": 437,
"start_col": 2,
"start_line": 435
} |
FStar.Pervasives.Lemma | val strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma (ensures (strict_suffix_of [] l \/ l == [])) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma
(ensures (strict_suffix_of [] l \/ l == []))
= match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q | val strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma (ensures (strict_suffix_of [] l \/ l == []))
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma (ensures (strict_suffix_of [] l \/ l == [])) = | false | null | true | match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.strict_suffix_of_nil",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"FStar.List.Tot.Base.strict_suffix_of",
"Prims.Nil",
"Prims.eq2",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma (ensures (strict_suffix_of [] l \/ l == [])) | [] | FStar.List.Tot.Properties.strict_suffix_of_or_eq_nil | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a
-> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.strict_suffix_of [] l \/ l == []) | {
"end_col": 38,
"end_line": 928,
"start_col": 2,
"start_line": 926
} |
FStar.Pervasives.Lemma | val precedes_append_cons_prod_r (#a #b: Type) (l1: list (a * b)) (x: a) (y: b) (l2: list (a * b))
: Lemma (ensures x << (append l1 ((x, y) :: l2)) /\ y << (append l1 ((x, y) :: l2))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let precedes_append_cons_prod_r
(#a #b: Type)
(l1: list (a * b))
(x: a)
(y: b)
(l2: list (a * b))
: Lemma
(ensures
x << (append l1 ((x, y) :: l2)) /\
y << (append l1 ((x, y) :: l2)))
= precedes_append_cons_r l1 (x, y) l2 | val precedes_append_cons_prod_r (#a #b: Type) (l1: list (a * b)) (x: a) (y: b) (l2: list (a * b))
: Lemma (ensures x << (append l1 ((x, y) :: l2)) /\ y << (append l1 ((x, y) :: l2)))
let precedes_append_cons_prod_r (#a #b: Type) (l1: list (a * b)) (x: a) (y: b) (l2: list (a * b))
: Lemma (ensures x << (append l1 ((x, y) :: l2)) /\ y << (append l1 ((x, y) :: l2))) = | false | null | true | precedes_append_cons_r l1 (x, y) l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Properties.precedes_append_cons_r",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Prims.precedes",
"FStar.List.Tot.Base.append",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma
(ensures (strict_suffix_of [] l \/ l == []))
= match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q
let strict_suffix_of_cons (#a: Type) (x: a) (l: list a) :
Lemma
(ensures (strict_suffix_of l (x::l)))
= ()
let rec strict_suffix_of_trans (#a: Type) (l1 l2 l3: list a)
: Lemma
(requires True)
(ensures ((strict_suffix_of l1 l2 /\ strict_suffix_of l2 l3) ==> strict_suffix_of l1 l3))
(decreases l3)
[SMTPat (strict_suffix_of l1 l2); SMTPat (strict_suffix_of l2 l3)]
= match l3 with
| [] -> ()
| _ :: q -> strict_suffix_of_trans l1 l2 q
let rec strict_suffix_of_correct (#a) (l1 l2: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> l1 << l2))
(decreases l2)
= match l2 with
| [] -> ()
| _ :: q ->
strict_suffix_of_correct l1 q
let rec map_strict_suffix_of (#a #b: Type) (f: a -> Tot b) (l1: list a) (l2: list a) :
Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> strict_suffix_of (map f l1) (map f l2)))
(decreases l2)
= match l2 with
| [] -> ()
| a::q ->
map_strict_suffix_of f l1 q
let rec mem_strict_suffix_of (#a: eqtype) (l1: list a) (m: a) (l2: list a)
: Lemma
(requires True)
(ensures ((mem m l1 /\ strict_suffix_of l1 l2) ==> mem m l2))
= match l2 with
| [] -> ()
| a :: q ->
mem_strict_suffix_of l1 m q
let rec strict_suffix_of_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures (strict_suffix_of l1 l2 ==> (exists l3 . l2 == append l3 l1)))
= match l2 with
| [] -> ()
| a :: q ->
FStar.Classical.or_elim
#(l1 == q)
#(strict_suffix_of l1 q)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: []))
(fun _ ->
FStar.Classical.exists_elim
(exists l3 . l2 == append l3 l1)
#_
#(fun l3 -> q == append l3 l1)
(strict_suffix_of_exists_append l1 q)
(fun l3 ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: l3)
))
let strict_suffix_of_or_eq_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures ((strict_suffix_of l1 l2 \/ l1 == l2) ==> (exists l3 . l2 == append l3 l1)))
= FStar.Classical.or_elim
#(strict_suffix_of l1 l2)
#(l1 == l2)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
strict_suffix_of_exists_append l1 l2)
(fun _ ->
FStar.Classical.exists_intro
(fun l3 -> l2 == append l3 l1)
[] )
(** Properties of << with lists *)
let precedes_tl
(#a: Type)
(l: list a {Cons? l})
: Lemma (ensures (tl l << l))
= ()
let rec precedes_append_cons_r
(#a: Type)
(l1: list a)
(x: a)
(l2: list a)
: Lemma
(requires True)
(ensures (x << append l1 (x :: l2)))
[SMTPat (x << append l1 (x :: l2))]
= match l1 with
| [] -> ()
| _ :: q -> precedes_append_cons_r q x l2
let precedes_append_cons_prod_r
(#a #b: Type)
(l1: list (a * b))
(x: a)
(y: b)
(l2: list (a * b))
: Lemma
(ensures
x << (append l1 ((x, y) :: l2)) /\ | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val precedes_append_cons_prod_r (#a #b: Type) (l1: list (a * b)) (x: a) (y: b) (l2: list (a * b))
: Lemma (ensures x << (append l1 ((x, y) :: l2)) /\ y << (append l1 ((x, y) :: l2))) | [] | FStar.List.Tot.Properties.precedes_append_cons_prod_r | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list (a * b) -> x: a -> y: b -> l2: Prims.list (a * b)
-> FStar.Pervasives.Lemma
(ensures
x << l1 @ FStar.Pervasives.Native.Mktuple2 x y :: l2 /\
y << l1 @ FStar.Pervasives.Native.Mktuple2 x y :: l2) | {
"end_col": 37,
"end_line": 1045,
"start_col": 2,
"start_line": 1045
} |
FStar.Pervasives.Lemma | val strict_suffix_of_exists_append (#a: Type) (l1 l2: list a)
: Lemma (ensures (strict_suffix_of l1 l2 ==> (exists l3. l2 == append l3 l1))) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec strict_suffix_of_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures (strict_suffix_of l1 l2 ==> (exists l3 . l2 == append l3 l1)))
= match l2 with
| [] -> ()
| a :: q ->
FStar.Classical.or_elim
#(l1 == q)
#(strict_suffix_of l1 q)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: []))
(fun _ ->
FStar.Classical.exists_elim
(exists l3 . l2 == append l3 l1)
#_
#(fun l3 -> q == append l3 l1)
(strict_suffix_of_exists_append l1 q)
(fun l3 ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: l3)
)) | val strict_suffix_of_exists_append (#a: Type) (l1 l2: list a)
: Lemma (ensures (strict_suffix_of l1 l2 ==> (exists l3. l2 == append l3 l1)))
let rec strict_suffix_of_exists_append (#a: Type) (l1 l2: list a)
: Lemma (ensures (strict_suffix_of l1 l2 ==> (exists l3. l2 == append l3 l1))) = | false | null | true | match l2 with
| [] -> ()
| a :: q ->
FStar.Classical.or_elim #(l1 == q)
#(strict_suffix_of l1 q)
#(fun _ -> exists l3. l2 == append l3 l1)
(fun _ -> FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) ([a]))
(fun _ ->
FStar.Classical.exists_elim (exists l3. l2 == append l3 l1)
#_
#(fun l3 -> q == append l3 l1)
(strict_suffix_of_exists_append l1 q)
(fun l3 -> FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: l3))) | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.Classical.or_elim",
"Prims.eq2",
"FStar.List.Tot.Base.strict_suffix_of",
"Prims.squash",
"Prims.l_or",
"Prims.l_Exists",
"FStar.List.Tot.Base.append",
"FStar.Classical.exists_intro",
"Prims.Cons",
"Prims.Nil",
"Prims.unit",
"FStar.Classical.exists_elim",
"FStar.List.Tot.Properties.strict_suffix_of_exists_append",
"Prims.l_True",
"Prims.l_imp",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma
(ensures (strict_suffix_of [] l \/ l == []))
= match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q
let strict_suffix_of_cons (#a: Type) (x: a) (l: list a) :
Lemma
(ensures (strict_suffix_of l (x::l)))
= ()
let rec strict_suffix_of_trans (#a: Type) (l1 l2 l3: list a)
: Lemma
(requires True)
(ensures ((strict_suffix_of l1 l2 /\ strict_suffix_of l2 l3) ==> strict_suffix_of l1 l3))
(decreases l3)
[SMTPat (strict_suffix_of l1 l2); SMTPat (strict_suffix_of l2 l3)]
= match l3 with
| [] -> ()
| _ :: q -> strict_suffix_of_trans l1 l2 q
let rec strict_suffix_of_correct (#a) (l1 l2: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> l1 << l2))
(decreases l2)
= match l2 with
| [] -> ()
| _ :: q ->
strict_suffix_of_correct l1 q
let rec map_strict_suffix_of (#a #b: Type) (f: a -> Tot b) (l1: list a) (l2: list a) :
Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> strict_suffix_of (map f l1) (map f l2)))
(decreases l2)
= match l2 with
| [] -> ()
| a::q ->
map_strict_suffix_of f l1 q
let rec mem_strict_suffix_of (#a: eqtype) (l1: list a) (m: a) (l2: list a)
: Lemma
(requires True)
(ensures ((mem m l1 /\ strict_suffix_of l1 l2) ==> mem m l2))
= match l2 with
| [] -> ()
| a :: q ->
mem_strict_suffix_of l1 m q
let rec strict_suffix_of_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val strict_suffix_of_exists_append (#a: Type) (l1 l2: list a)
: Lemma (ensures (strict_suffix_of l1 l2 ==> (exists l3. l2 == append l3 l1))) | [
"recursion"
] | FStar.List.Tot.Properties.strict_suffix_of_exists_append | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.strict_suffix_of l1 l2 ==> (exists (l3: Prims.list a). l2 == l3 @ l1)) | {
"end_col": 15,
"end_line": 996,
"start_col": 2,
"start_line": 979
} |
FStar.Pervasives.Lemma | val lemma_split_using (#t: Type) (l: list t) (x: t{x `memP` l})
: Lemma
(ensures
(let l1, l2 = split_using l x in
length l2 > 0 /\ ~(x `memP` l1) /\ hd l2 == x /\ append l1 l2 == l)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x) | val lemma_split_using (#t: Type) (l: list t) (x: t{x `memP` l})
: Lemma
(ensures
(let l1, l2 = split_using l x in
length l2 > 0 /\ ~(x `memP` l1) /\ hd l2 == x /\ append l1 l2 == l))
let rec lemma_split_using (#t: Type) (l: list t) (x: t{x `memP` l})
: Lemma
(ensures
(let l1, l2 = split_using l x in
length l2 > 0 /\ ~(x `memP` l1) /\ hd l2 == x /\ append l1 l2 == l)) = | false | null | true | match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\ ~(x `memP` l1) /\ hd l2 == x /\ append l1 l2 == l
in
FStar.Classical.or_elim #_
#_
#(fun () -> goal)
(fun (_: squash (a == x)) -> ())
(fun (_: squash (x `memP` rest)) -> lemma_split_using rest x) | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Base.memP",
"FStar.Classical.or_elim",
"Prims.eq2",
"Prims.unit",
"Prims.squash",
"FStar.List.Tot.Properties.lemma_split_using",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"Prims.l_not",
"FStar.List.Tot.Base.hd",
"FStar.List.Tot.Base.append",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Properties.split_using",
"Prims.l_True",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\ | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_split_using (#t: Type) (l: list t) (x: t{x `memP` l})
: Lemma
(ensures
(let l1, l2 = split_using l x in
length l2 > 0 /\ ~(x `memP` l1) /\ hd l2 == x /\ append l1 l2 == l)) | [
"recursion"
] | FStar.List.Tot.Properties.lemma_split_using | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list t -> x: t{FStar.List.Tot.Base.memP x l}
-> FStar.Pervasives.Lemma
(ensures
(let _ = FStar.List.Tot.Properties.split_using l x in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in
FStar.List.Tot.Base.length l2 > 0 /\ ~(FStar.List.Tot.Base.memP x l1) /\
FStar.List.Tot.Base.hd l2 == x /\ l1 @ l2 == l)
<:
Type0)) | {
"end_col": 66,
"end_line": 500,
"start_col": 2,
"start_line": 486
} |
FStar.Pervasives.Lemma | val init_last_def (#a: Type) (l: list a) (x: a)
: Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec init_last_def (#a: Type) (l: list a) (x: a) : Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x)
= match l with
| [] -> ()
| y :: q -> init_last_def q x | val init_last_def (#a: Type) (l: list a) (x: a)
: Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x)
let rec init_last_def (#a: Type) (l: list a) (x: a)
: Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x) = | false | null | true | match l with
| [] -> ()
| y :: q -> init_last_def q x | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.List.Tot.Properties.init_last_def",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.List.Tot.Base.init",
"FStar.List.Tot.Base.last",
"FStar.List.Tot.Base.append",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma
(ensures (strict_suffix_of [] l \/ l == []))
= match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q
let strict_suffix_of_cons (#a: Type) (x: a) (l: list a) :
Lemma
(ensures (strict_suffix_of l (x::l)))
= ()
let rec strict_suffix_of_trans (#a: Type) (l1 l2 l3: list a)
: Lemma
(requires True)
(ensures ((strict_suffix_of l1 l2 /\ strict_suffix_of l2 l3) ==> strict_suffix_of l1 l3))
(decreases l3)
[SMTPat (strict_suffix_of l1 l2); SMTPat (strict_suffix_of l2 l3)]
= match l3 with
| [] -> ()
| _ :: q -> strict_suffix_of_trans l1 l2 q
let rec strict_suffix_of_correct (#a) (l1 l2: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> l1 << l2))
(decreases l2)
= match l2 with
| [] -> ()
| _ :: q ->
strict_suffix_of_correct l1 q
let rec map_strict_suffix_of (#a #b: Type) (f: a -> Tot b) (l1: list a) (l2: list a) :
Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> strict_suffix_of (map f l1) (map f l2)))
(decreases l2)
= match l2 with
| [] -> ()
| a::q ->
map_strict_suffix_of f l1 q
let rec mem_strict_suffix_of (#a: eqtype) (l1: list a) (m: a) (l2: list a)
: Lemma
(requires True)
(ensures ((mem m l1 /\ strict_suffix_of l1 l2) ==> mem m l2))
= match l2 with
| [] -> ()
| a :: q ->
mem_strict_suffix_of l1 m q
let rec strict_suffix_of_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures (strict_suffix_of l1 l2 ==> (exists l3 . l2 == append l3 l1)))
= match l2 with
| [] -> ()
| a :: q ->
FStar.Classical.or_elim
#(l1 == q)
#(strict_suffix_of l1 q)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: []))
(fun _ ->
FStar.Classical.exists_elim
(exists l3 . l2 == append l3 l1)
#_
#(fun l3 -> q == append l3 l1)
(strict_suffix_of_exists_append l1 q)
(fun l3 ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: l3)
))
let strict_suffix_of_or_eq_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures ((strict_suffix_of l1 l2 \/ l1 == l2) ==> (exists l3 . l2 == append l3 l1)))
= FStar.Classical.or_elim
#(strict_suffix_of l1 l2)
#(l1 == l2)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
strict_suffix_of_exists_append l1 l2)
(fun _ ->
FStar.Classical.exists_intro
(fun l3 -> l2 == append l3 l1)
[] )
(** Properties of << with lists *)
let precedes_tl
(#a: Type)
(l: list a {Cons? l})
: Lemma (ensures (tl l << l))
= ()
let rec precedes_append_cons_r
(#a: Type)
(l1: list a)
(x: a)
(l2: list a)
: Lemma
(requires True)
(ensures (x << append l1 (x :: l2)))
[SMTPat (x << append l1 (x :: l2))]
= match l1 with
| [] -> ()
| _ :: q -> precedes_append_cons_r q x l2
let precedes_append_cons_prod_r
(#a #b: Type)
(l1: list (a * b))
(x: a)
(y: b)
(l2: list (a * b))
: Lemma
(ensures
x << (append l1 ((x, y) :: l2)) /\
y << (append l1 ((x, y) :: l2)))
= precedes_append_cons_r l1 (x, y) l2
let rec memP_precedes
(#a: Type)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> x << l))
(decreases l)
= match l with
| [] -> ()
| y :: q ->
FStar.Classical.or_elim
#(x == y)
#(memP x q)
#(fun _ -> x << l)
(fun _ -> ())
(fun _ -> memP_precedes x q)
let assoc_precedes
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
(y: b)
: Lemma
(requires (assoc x l == Some y))
(ensures (x << l /\ y << l))
= assoc_memP_some x y l;
memP_precedes (x, y) l
(** Properties about find *)
let rec find_none
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
(x: a)
: Lemma
(requires (find f l == None /\ memP x l))
(ensures (f x == false))
= let (x' :: l') = l in
Classical.or_elim
#(x == x')
#(~ (x == x'))
#(fun _ -> f x == false)
(fun h -> ())
(fun h -> find_none f l' x)
(** Properties of init and last *)
let rec append_init_last (#a: Type) (l: list a { Cons? l }) : Lemma
(l == append (init l) [last l])
= match l with
| a :: q ->
if Cons? q
then
append_init_last q
else
()
let rec init_last_def (#a: Type) (l: list a) (x: a) : Lemma
(let l' = append l [x] in | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val init_last_def (#a: Type) (l: list a) (x: a)
: Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x) | [
"recursion"
] | FStar.List.Tot.Properties.init_last_def | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a -> x: a
-> FStar.Pervasives.Lemma
(ensures
(let l' = l @ [x] in
FStar.List.Tot.Base.init l' == l /\ FStar.List.Tot.Base.last l' == x)) | {
"end_col": 31,
"end_line": 1112,
"start_col": 2,
"start_line": 1110
} |
FStar.Pervasives.Lemma | val init_last_inj (#a: Type) (l1: list a {Cons? l1}) (l2: list a {Cons? l2})
: Lemma (requires (init l1 == init l2 /\ last l1 == last l2)) (ensures (l1 == l2)) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let init_last_inj (#a: Type) (l1: list a { Cons? l1 } ) (l2: list a { Cons? l2 } ) : Lemma
(requires (init l1 == init l2 /\ last l1 == last l2))
(ensures (l1 == l2))
= append_init_last l1;
append_init_last l2 | val init_last_inj (#a: Type) (l1: list a {Cons? l1}) (l2: list a {Cons? l2})
: Lemma (requires (init l1 == init l2 /\ last l1 == last l2)) (ensures (l1 == l2))
let init_last_inj (#a: Type) (l1: list a {Cons? l1}) (l2: list a {Cons? l2})
: Lemma (requires (init l1 == init l2 /\ last l1 == last l2)) (ensures (l1 == l2)) = | false | null | true | append_init_last l1;
append_init_last l2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"Prims.b2t",
"Prims.uu___is_Cons",
"FStar.List.Tot.Properties.append_init_last",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"FStar.List.Tot.Base.init",
"FStar.List.Tot.Base.last",
"Prims.squash",
"Prims.l_or",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma
(ensures (strict_suffix_of [] l \/ l == []))
= match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q
let strict_suffix_of_cons (#a: Type) (x: a) (l: list a) :
Lemma
(ensures (strict_suffix_of l (x::l)))
= ()
let rec strict_suffix_of_trans (#a: Type) (l1 l2 l3: list a)
: Lemma
(requires True)
(ensures ((strict_suffix_of l1 l2 /\ strict_suffix_of l2 l3) ==> strict_suffix_of l1 l3))
(decreases l3)
[SMTPat (strict_suffix_of l1 l2); SMTPat (strict_suffix_of l2 l3)]
= match l3 with
| [] -> ()
| _ :: q -> strict_suffix_of_trans l1 l2 q
let rec strict_suffix_of_correct (#a) (l1 l2: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> l1 << l2))
(decreases l2)
= match l2 with
| [] -> ()
| _ :: q ->
strict_suffix_of_correct l1 q
let rec map_strict_suffix_of (#a #b: Type) (f: a -> Tot b) (l1: list a) (l2: list a) :
Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> strict_suffix_of (map f l1) (map f l2)))
(decreases l2)
= match l2 with
| [] -> ()
| a::q ->
map_strict_suffix_of f l1 q
let rec mem_strict_suffix_of (#a: eqtype) (l1: list a) (m: a) (l2: list a)
: Lemma
(requires True)
(ensures ((mem m l1 /\ strict_suffix_of l1 l2) ==> mem m l2))
= match l2 with
| [] -> ()
| a :: q ->
mem_strict_suffix_of l1 m q
let rec strict_suffix_of_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures (strict_suffix_of l1 l2 ==> (exists l3 . l2 == append l3 l1)))
= match l2 with
| [] -> ()
| a :: q ->
FStar.Classical.or_elim
#(l1 == q)
#(strict_suffix_of l1 q)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: []))
(fun _ ->
FStar.Classical.exists_elim
(exists l3 . l2 == append l3 l1)
#_
#(fun l3 -> q == append l3 l1)
(strict_suffix_of_exists_append l1 q)
(fun l3 ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: l3)
))
let strict_suffix_of_or_eq_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures ((strict_suffix_of l1 l2 \/ l1 == l2) ==> (exists l3 . l2 == append l3 l1)))
= FStar.Classical.or_elim
#(strict_suffix_of l1 l2)
#(l1 == l2)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
strict_suffix_of_exists_append l1 l2)
(fun _ ->
FStar.Classical.exists_intro
(fun l3 -> l2 == append l3 l1)
[] )
(** Properties of << with lists *)
let precedes_tl
(#a: Type)
(l: list a {Cons? l})
: Lemma (ensures (tl l << l))
= ()
let rec precedes_append_cons_r
(#a: Type)
(l1: list a)
(x: a)
(l2: list a)
: Lemma
(requires True)
(ensures (x << append l1 (x :: l2)))
[SMTPat (x << append l1 (x :: l2))]
= match l1 with
| [] -> ()
| _ :: q -> precedes_append_cons_r q x l2
let precedes_append_cons_prod_r
(#a #b: Type)
(l1: list (a * b))
(x: a)
(y: b)
(l2: list (a * b))
: Lemma
(ensures
x << (append l1 ((x, y) :: l2)) /\
y << (append l1 ((x, y) :: l2)))
= precedes_append_cons_r l1 (x, y) l2
let rec memP_precedes
(#a: Type)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> x << l))
(decreases l)
= match l with
| [] -> ()
| y :: q ->
FStar.Classical.or_elim
#(x == y)
#(memP x q)
#(fun _ -> x << l)
(fun _ -> ())
(fun _ -> memP_precedes x q)
let assoc_precedes
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
(y: b)
: Lemma
(requires (assoc x l == Some y))
(ensures (x << l /\ y << l))
= assoc_memP_some x y l;
memP_precedes (x, y) l
(** Properties about find *)
let rec find_none
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
(x: a)
: Lemma
(requires (find f l == None /\ memP x l))
(ensures (f x == false))
= let (x' :: l') = l in
Classical.or_elim
#(x == x')
#(~ (x == x'))
#(fun _ -> f x == false)
(fun h -> ())
(fun h -> find_none f l' x)
(** Properties of init and last *)
let rec append_init_last (#a: Type) (l: list a { Cons? l }) : Lemma
(l == append (init l) [last l])
= match l with
| a :: q ->
if Cons? q
then
append_init_last q
else
()
let rec init_last_def (#a: Type) (l: list a) (x: a) : Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x)
= match l with
| [] -> ()
| y :: q -> init_last_def q x
let init_last_inj (#a: Type) (l1: list a { Cons? l1 } ) (l2: list a { Cons? l2 } ) : Lemma
(requires (init l1 == init l2 /\ last l1 == last l2)) | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val init_last_inj (#a: Type) (l1: list a {Cons? l1}) (l2: list a {Cons? l2})
: Lemma (requires (init l1 == init l2 /\ last l1 == last l2)) (ensures (l1 == l2)) | [] | FStar.List.Tot.Properties.init_last_inj | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a {Cons? l1} -> l2: Prims.list a {Cons? l2}
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.init l1 == FStar.List.Tot.Base.init l2 /\
FStar.List.Tot.Base.last l1 == FStar.List.Tot.Base.last l2) (ensures l1 == l2) | {
"end_col": 21,
"end_line": 1118,
"start_col": 2,
"start_line": 1117
} |
FStar.Pervasives.Lemma | val for_all_append (#a: _) (f: (a -> Tot bool)) (s1 s2: list a)
: Lemma (ensures for_all f (s1 @ s2) <==> for_all f s1 && for_all f s2) | [
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec for_all_append #a (f: a -> Tot bool) (s1 s2: list a): Lemma
(ensures for_all f (s1 @ s2) <==> for_all f s1 && for_all f s2)
=
let _ = allow_inversion (list a) in
match s1 with
| [] -> ()
| hd1 :: tl1 -> for_all_append f tl1 s2 | val for_all_append (#a: _) (f: (a -> Tot bool)) (s1 s2: list a)
: Lemma (ensures for_all f (s1 @ s2) <==> for_all f s1 && for_all f s2)
let rec for_all_append #a (f: (a -> Tot bool)) (s1: list a) (s2: list a)
: Lemma (ensures for_all f (s1 @ s2) <==> for_all f s1 && for_all f s2) = | false | null | true | let _ = allow_inversion (list a) in
match s1 with
| [] -> ()
| hd1 :: tl1 -> for_all_append f tl1 s2 | {
"checked_file": "FStar.List.Tot.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.List.Tot.Properties.fst"
} | [
"lemma"
] | [
"Prims.bool",
"Prims.list",
"FStar.List.Tot.Properties.for_all_append",
"Prims.unit",
"FStar.Pervasives.allow_inversion",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Prims.b2t",
"FStar.List.Tot.Base.for_all",
"FStar.List.Tot.Base.op_At",
"Prims.op_AmpAmp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
This module states and proves some properties about pure and total
operations on lists.
@summary Properties of pure total operations on lists
*)
module FStar.List.Tot.Properties
open FStar.List.Tot.Base
(** A list indexed by its length **)
let llist a (n:nat) = l:list a {length l = n}
(** Properties about mem **)
(** Correctness of [mem] for types with decidable equality. TODO:
replace [mem] with [memP] in relevant lemmas and define the right
SMTPat to automatically recover lemmas about [mem] for types with
decidable equality *)
let rec mem_memP
(#a: eqtype)
(x: a)
(l: list a)
: Lemma (ensures (mem x l <==> memP x l))
[SMTPat (mem x l); SMTPat (memP x l)]
= match l with
| [] -> ()
| a :: q -> mem_memP x q
(** If an element can be [index]ed, then it is a [memP] of the list. *)
let rec lemma_index_memP (#t:Type) (l:list t) (i:nat{i < length l}) :
Lemma
(ensures (index l i `memP` l))
[SMTPat (index l i `memP` l)] =
match i with
| 0 -> ()
| _ -> lemma_index_memP (tl l) (i - 1)
(** The empty list has no elements. *)
val memP_empty : #a: Type -> x:a ->
Lemma (requires (memP x []))
(ensures False)
let memP_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val memP_existsb: #a: Type -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ memP x xs))))
let rec memP_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> memP_existsb f tl
let rec memP_map_intro
(#a #b: Type)
(f: a -> Tot b)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> memP (f x) (map f l)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_intro f x q (* NOTE: would fail if [requires memP x l] instead of [ ==> ] *)
let rec memP_map_elim
(#a #b: Type)
(f: a -> Tot b)
(y: b)
(l: list a)
: Lemma
(requires True)
(ensures (memP y (map f l) ==> (exists (x : a) . memP x l /\ f x == y)))
(decreases l)
= match l with
| [] -> ()
| _ :: q -> memP_map_elim f y q
(** The empty list has no elements *)
val mem_empty : #a:eqtype -> x:a ->
Lemma (requires (mem x []))
(ensures False)
let mem_empty #a x = ()
(** Full specification for [existsb]: [existsb f xs] holds if, and
only if, there exists an element [x] of [xs] such that [f x] holds. *)
val mem_existsb: #a:eqtype -> f:(a -> Tot bool) -> xs:list a ->
Lemma(ensures (existsb f xs <==> (exists (x:a). (f x = true /\ mem x xs))))
let rec mem_existsb #a f xs =
match xs with
| [] -> ()
| hd::tl -> mem_existsb f tl
let rec mem_count
(#a: eqtype)
(l: list a)
(x: a)
: Lemma
(mem x l <==> count x l > 0)
= match l with
| [] -> ()
| x' :: l' -> mem_count l' x
(** Properties about rev **)
val rev_acc_length : l:list 'a -> acc:list 'a ->
Lemma (requires True)
(ensures (length (rev_acc l acc) = length l + length acc))
let rec rev_acc_length l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_length tl (hd::acc)
val rev_length : l:list 'a ->
Lemma (requires True)
(ensures (length (rev l) = length l))
let rev_length l = rev_acc_length l []
val rev_acc_memP : #a:Type -> l:list a -> acc:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev_acc l acc) <==> (memP x l \/ memP x acc)))
let rec rev_acc_memP #a l acc x = match l with
| [] -> ()
| hd::tl -> rev_acc_memP tl (hd::acc) x
(** A list and its reversed have the same elements *)
val rev_memP : #a:Type -> l:list a -> x:a ->
Lemma (requires True)
(ensures (memP x (rev l) <==> memP x l))
let rev_memP #a l x = rev_acc_memP l [] x
val rev_mem : #a:eqtype -> l:list a -> x:a ->
Lemma (requires True)
(ensures (mem x (rev l) <==> mem x l))
let rev_mem l x = rev_memP l x
(** Properties about append **)
val append_nil_l: l:list 'a ->
Lemma (requires True)
(ensures ([]@l == l))
let append_nil_l l = ()
val append_l_nil: l:list 'a ->
Lemma (requires True)
(ensures (l@[] == l)) [SMTPat (l@[])]
let rec append_l_nil = function
| [] -> ()
| hd::tl -> append_l_nil tl
val append_cons_l: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures (((hd::tl)@l) == (hd::(tl@l))))
let append_cons_l hd tl l = ()
val append_l_cons: hd:'a -> tl:list 'a -> l:list 'a ->
Lemma (requires True)
(ensures ((l@(hd::tl)) == ((l@[hd])@tl)))
let rec append_l_cons hd tl l = match l with
| [] -> ()
| hd'::tl' -> append_l_cons hd tl tl'
val append_assoc: l1:list 'a -> l2:list 'a -> l3:list 'a ->
Lemma (requires True)
(ensures ((l1@(l2@l3)) == ((l1@l2)@l3)))
let rec append_assoc l1 l2 l3 = match l1 with
| [] -> ()
| hd::tl -> append_assoc tl l2 l3
val append_length: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures (length (l1@l2) = length l1 + length l2)) [SMTPat (length (l1 @ l2))]
let rec append_length l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_length tl l2
val append_mem: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (mem a (l1@l2) = (mem a l1 || mem a l2)))
(* [SMTPat (mem a (l1@l2))] *)
let rec append_mem #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_mem tl l2 a
val append_mem_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. mem a (l1@l2) = (mem a l1 || mem a l2)))
let rec append_mem_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_mem_forall tl l2
val append_count: #t:eqtype -> l1:list t
-> l2:list t
-> a:t
-> Lemma (requires True)
(ensures (count a (l1@l2) = (count a l1 + count a l2)))
let rec append_count #t l1 l2 a = match l1 with
| [] -> ()
| hd::tl -> append_count tl l2 a
val append_count_forall: #a:eqtype -> l1:list a
-> l2:list a
-> Lemma (requires True)
(ensures (forall a. count a (l1@l2) = (count a l1 + count a l2)))
(* [SMTPat (l1@l2)] *)
let rec append_count_forall #a l1 l2 = match l1 with
| [] -> ()
| hd::tl -> append_count_forall tl l2
val append_eq_nil: l1:list 'a -> l2:list 'a ->
Lemma (requires (l1@l2 == []))
(ensures (l1 == [] /\ l2 == []))
let append_eq_nil l1 l2 = ()
val append_eq_singl: l1:list 'a -> l2:list 'a -> x:'a ->
Lemma (requires (l1@l2 == [x]))
(ensures ((l1 == [x] /\ l2 == []) \/ (l1 == [] /\ l2 == [x])))
let append_eq_singl l1 l2 x = ()
val append_inv_head: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l@l1) == (l@l2)))
(ensures (l1 == l2))
let rec append_inv_head l l1 l2 = match l with
| [] -> ()
| hd::tl -> append_inv_head tl l1 l2
val append_inv_tail: l:list 'a -> l1:list 'a -> l2:list 'a ->
Lemma (requires ((l1@l) == (l2@l)))
(ensures (l1 == l2))
let rec append_inv_tail l l1 l2 = match l1, l2 with
| [], [] -> ()
| hd1::tl1, hd2::tl2 -> append_inv_tail l tl1 tl2
| [], hd2::tl2 ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl2; append_inv_tail tl [] (tl2@[hd])
(* We can here apply the induction hypothesis thanks to termination on a lexicographical ordering of the arguments! *)
)
| hd1::tl1, [] ->
(match l with
| [] -> ()
| hd::tl -> append_l_cons hd tl tl1; append_inv_tail tl (tl1@[hd]) []
(* Idem *)
)
let rec append_length_inv_head
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length left1 == length left2))
(ensures (left1 == left2 /\ right1 == right2))
(decreases left1)
= match left1 with
| [] -> ()
| _ :: left1' ->
append_length_inv_head left1' right1 (tl left2) right2
let append_length_inv_tail
(#a: Type)
(left1 right1 left2 right2: list a)
: Lemma
(requires (append left1 right1 == append left2 right2 /\ length right1 == length right2))
(ensures (left1 == left2 /\ right1 == right2))
= append_length left1 right1;
append_length left2 right2;
append_length_inv_head left1 right1 left2 right2
let append_injective #a (l0 l0':list a)
(l1 l1':list a)
: Lemma
(ensures
(length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1' ==>
l0 == l0' /\ l1 == l1')
= introduce
((length l0 == length l0' \/ length l1 == length l1') /\
append l0 l1 == append l0' l1')
==>
(l0 == l0' /\ l1 == l1')
with _. eliminate (length l0 == length l0') \/
(length l1 == length l1')
returns _
with _. append_length_inv_head l0 l1 l0' l1'
and _. append_length_inv_tail l0 l1 l0' l1'
(** The [last] element of a list remains the same, even after that list is
[append]ed to another list. *)
let rec lemma_append_last (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0))
(ensures (last (l1 @ l2) == last l2)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_append_last l1' l2
(** Properties mixing rev and append **)
val rev': list 'a -> Tot (list 'a)
let rec rev' = function
| [] -> []
| hd::tl -> (rev' tl)@[hd]
let rev'T = rev'
val rev_acc_rev': l:list 'a -> acc:list 'a ->
Lemma (requires (True))
(ensures ((rev_acc l acc) == ((rev' l)@acc)))
let rec rev_acc_rev' l acc = match l with
| [] -> ()
| hd::tl -> rev_acc_rev' tl (hd::acc); append_l_cons hd acc (rev' tl)
val rev_rev': l:list 'a ->
Lemma (requires True)
(ensures ((rev l) == (rev' l)))
let rev_rev' l = rev_acc_rev' l []; append_l_nil (rev' l)
val rev'_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev' (l1@l2)) == ((rev' l2)@(rev' l1))))
let rec rev'_append l1 l2 = match l1 with
| [] -> append_l_nil (rev' l2)
| hd::tl -> rev'_append tl l2; append_assoc (rev' l2) (rev' tl) [hd]
val rev_append: l1:list 'a -> l2:list 'a ->
Lemma (requires True)
(ensures ((rev (l1@l2)) == ((rev l2)@(rev l1))))
let rev_append l1 l2 = rev_rev' l1; rev_rev' l2; rev_rev' (l1@l2); rev'_append l1 l2
val rev'_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev' (rev' l) == l))
let rec rev'_involutive = function
| [] -> ()
| hd::tl -> rev'_append (rev' tl) [hd]; rev'_involutive tl
val rev_involutive : l:list 'a ->
Lemma (requires True)
(ensures (rev (rev l) == l))
let rev_involutive l = rev_rev' l; rev_rev' (rev' l); rev'_involutive l
(** Properties about snoc *)
val lemma_snoc_length : (lx:(list 'a * 'a)) ->
Lemma (requires True)
(ensures (length (snoc lx) = length (fst lx) + 1))
let lemma_snoc_length (l, x) = append_length l [x]
(** Reverse induction principle **)
val rev'_list_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p (rev' tl) ==> p (rev' (hd::tl)))))
(ensures (p (rev' l)))
let rec rev'_list_ind p = function
| [] -> ()
| hd::tl -> rev'_list_ind p tl
val rev_ind: p:(list 'a -> Tot bool) -> l:list 'a ->
Lemma (requires ((p []) /\ (forall hd tl. p hd ==> p (hd@[tl]))))
(ensures (p l))
let rev_ind p l = rev'_involutive l; rev'_list_ind p (rev' l)
(** Properties about iterators **)
val map_lemma: f:('a -> Tot 'b)
-> l:(list 'a)
-> Lemma (requires True)
(ensures (length (map f l)) = length l)
[SMTPat (map f l)]
let rec map_lemma f l =
match l with
| [] -> ()
| h::t -> map_lemma f t
(** Properties about unsnoc *)
(** [unsnoc] is the inverse of [snoc] *)
val lemma_unsnoc_snoc: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (snoc (unsnoc l) == l))
[SMTPat (snoc (unsnoc l))]
let lemma_unsnoc_snoc #a l =
let l', x = unsnoc l in
let l1, l2 = l', [x] in
lemma_splitAt_snd_length (length l - 1) l;
// assert ((l1, l2) == splitAt (length l - 1) l);
let rec aux (l:list a{length l > 0}) :
Lemma (let l1, l2 = splitAt (length l - 1) l in
append l1 l2 == l) =
if length l = 1 then () else aux (tl l) in
aux l
(** [snoc] is the inverse of [unsnoc] *)
val lemma_snoc_unsnoc: #a:Type -> lx:(list a * a) ->
Lemma (requires True)
(ensures (unsnoc (snoc lx) == lx))
(decreases (length (fst (lx))))
[SMTPat (unsnoc (snoc lx))]
let rec lemma_snoc_unsnoc #a lx =
let l, x = lx in
match l with
| [] -> ()
| _ -> lemma_snoc_unsnoc (tl l, x)
(** Doing an [unsnoc] gives us a list that is shorter in length by 1 *)
val lemma_unsnoc_length: #a:Type -> l:list a{length l > 0} ->
Lemma (requires True)
(ensures (length (fst (unsnoc l)) == length l - 1))
let lemma_unsnoc_length #a l =
lemma_snoc_length (unsnoc l)
(** [unsnoc] followed by [append] can be connected to the same vice-versa. *)
let rec lemma_unsnoc_append (#a:Type) (l1 l2:list a) :
Lemma
(requires (length l2 > 0)) // the [length l2 = 0] is trivial
(ensures (
let al, a = unsnoc (l1 @ l2) in
let bl, b = unsnoc l2 in
al == l1 @ bl /\ a == b)) =
match l1 with
| [] -> ()
| _ :: l1' -> lemma_unsnoc_append l1' l2
(** [unsnoc] gives you [last] element, which is [index]ed at [length l - 1] *)
let rec lemma_unsnoc_is_last (#t:Type) (l:list t) :
Lemma
(requires (length l > 0))
(ensures (snd (unsnoc l) == last l /\ snd (unsnoc l) == index l (length l - 1))) =
match l with
| [_] -> ()
| _ -> lemma_unsnoc_is_last (tl l)
(** [index]ing on the left part of an [unsnoc]d list is the same as indexing
the original list. *)
let rec lemma_unsnoc_index (#t:Type) (l:list t) (i:nat) :
Lemma
(requires (length l > 0 /\ i < length l - 1))
(ensures (
i < length (fst (unsnoc l)) /\
index (fst (unsnoc l)) i == index l i)) =
match i with
| 0 -> ()
| _ -> lemma_unsnoc_index (tl l) (i - 1)
(** Definition and properties about [split_using] *)
(** [split_using] splits a list at the first instance of finding an
element in it.
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (list t * list t) =
match l with
| [_] -> [], l
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
[], l
) else (
let l1', l2' = split_using rest x in
a :: l1', l2'
)
let rec lemma_split_using (#t:Type) (l:list t) (x:t{x `memP` l}) :
Lemma
(ensures (
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l)) =
match l with
| [_] -> ()
| a :: rest ->
let goal =
let l1, l2 = split_using l x in
length l2 > 0 /\
~(x `memP` l1) /\
hd l2 == x /\
append l1 l2 == l
in
FStar.Classical.or_elim
#_ #_
#(fun () -> goal)
(fun (_:squash (a == x)) -> ())
(fun (_:squash (x `memP` rest)) -> lemma_split_using rest x)
(** Definition of [index_of] *)
(** [index_of l x] gives the index of the leftmost [x] in [l].
NOTE: Uses [strong_excluded_middle] axiom. *)
let rec index_of (#t:Type) (l:list t) (x:t{x `memP` l}) :
GTot (i:nat{i < length l /\ index l i == x}) =
match l with
| [_] -> 0
| a :: rest ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (a == x) then (
0
) else (
1 + index_of rest x
)
(** Properties about partition **)
(** If [partition f l = (l1, l2)], then for any [x], [x] is in [l] if
and only if [x] is in either one of [l1] or [l2] *)
val partition_mem: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
mem x l = (mem x l1 || mem x l2)))
let rec partition_mem #a f l x = match l with
| [] -> ()
| hd::tl -> partition_mem f tl x
(** Same as [partition_mem], but using [forall] *)
val partition_mem_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition f l in
(forall x. mem x l = (mem x l1 || mem x l2))))
let rec partition_mem_forall #a f l = match l with
| [] -> ()
| hd::tl -> partition_mem_forall f tl
(** If [partition f l = (l1, l2)], then for any [x], if [x] is in [l1]
(resp. [l2]), then [f x] holds (resp. does not hold) *)
val partition_mem_p_forall: #a:eqtype -> p:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (let l1, l2 = partition p l in
(forall x. mem x l1 ==> p x) /\ (forall x. mem x l2 ==> not (p x))))
let rec partition_mem_p_forall #a p l = match l with
| [] -> ()
| hd::tl -> partition_mem_p_forall p tl
(** If [partition f l = (l1, l2)], then the number of occurrences of
any [x] in [l] is the same as the sum of the number of occurrences in
[l1] and [l2]. *)
val partition_count: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> x:a
-> Lemma (requires True)
(ensures (count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
let rec partition_count #a f l x = match l with
| [] -> ()
| hd::tl -> partition_count f tl x
(** Same as [partition_count], but using [forall] *)
val partition_count_forall: #a:eqtype -> f:(a -> Tot bool)
-> l:list a
-> Lemma (requires True)
(ensures (forall x. count x l = (count x (fst (partition f l)) + count x (snd (partition f l)))))
(* [SMTPat (partitionT f l)] *)
let rec partition_count_forall #a f l= match l with
| [] -> ()
| hd::tl -> partition_count_forall f tl
(** Properties about subset **)
let rec mem_subset (#a: eqtype) (la lb: list a)
: Lemma (requires (forall x. mem x la ==> mem x lb))
(ensures (subset la lb)) =
match la with
| [] -> ()
| hd :: tl -> mem_subset tl lb
let subset_reflexive (#a: eqtype) (l: list a)
: Lemma (subset l l) [SMTPat (subset l l)] = mem_subset l l
(** Correctness of quicksort **)
(** Correctness of [sortWith], part 1/2: the number of occurrences of
any [x] in [sortWith f l] is the same as the number of occurrences in
[l]. *)
val sortWith_permutation: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires True)
(ensures (forall x. count x l = count x (sortWith f l)))
(decreases (length l))
let rec sortWith_permutation #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_count_forall (bool_of_compare f pivot) tl;
sortWith_permutation f lo;
sortWith_permutation f hi;
append_count_forall (sortWith f lo) (pivot::sortWith f hi)
(** [sorted f l] holds if, and only if, any two consecutive elements
[x], [y] of [l] are such that [f x y] holds
*)
val sorted: ('a -> 'a -> Tot bool) -> list 'a -> Tot bool
let rec sorted f = function
| []
| [_] -> true
| x::y::tl -> f x y && sorted f (y::tl)
(** [f] is a total order if, and only if, it is reflexive,
anti-symmetric, transitive and total. *)
type total_order (#a:Type) (f: (a -> a -> Tot bool)) =
(forall a. f a a) (* reflexivity *)
/\ (forall a1 a2. f a1 a2 /\ f a2 a1 ==> a1 == a2) (* anti-symmetry *)
/\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *)
/\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
(** Correctness of the merging of two sorted lists around a pivot. *)
val append_sorted: #a:eqtype
-> f:(a -> a -> Tot bool)
-> l1:list a{sorted f l1}
-> l2:list a{sorted f l2}
-> pivot:a
-> Lemma (requires (total_order #a f
/\ (forall y. mem y l1 ==> not(f pivot y))
/\ (forall y. mem y l2 ==> f pivot y)))
(ensures (sorted f (l1@(pivot::l2))))
[SMTPat (sorted f (l1@(pivot::l2)))]
let rec append_sorted #a f l1 l2 pivot = match l1 with
| [] -> ()
| hd::tl -> append_sorted f tl l2 pivot
(** Correctness of [sortWith], part 2/2: the elements of [sortWith f
l] are sorted according to comparison function [f], and the elements
of [sortWith f l] are the elements of [l]. *)
val sortWith_sorted: #a:eqtype -> f:(a -> a -> Tot int) -> l:list a ->
Lemma (requires (total_order #a (bool_of_compare f)))
(ensures ((sorted (bool_of_compare f) (sortWith f l)) /\ (forall x. mem x l = mem x (sortWith f l))))
(decreases (length l))
let rec sortWith_sorted #a f l = match l with
| [] -> ()
| pivot::tl ->
let hi, lo = partition (bool_of_compare f pivot) tl in
partition_length (bool_of_compare f pivot) tl;
partition_mem_forall (bool_of_compare f pivot) tl;
partition_mem_p_forall (bool_of_compare f pivot) tl;
sortWith_sorted f lo;
sortWith_sorted f hi;
append_mem_forall (sortWith f lo) (pivot::sortWith f hi);
append_sorted (bool_of_compare f) (sortWith f lo) (sortWith f hi) pivot
(** Properties of [noRepeats] *)
let noRepeats_nil
(#a: eqtype)
: Lemma
(ensures (noRepeats #a []))
= ()
let noRepeats_cons
(#a: eqtype)
(h: a)
(tl: list a)
: Lemma
(requires ((~ (mem h tl)) /\ noRepeats tl))
(ensures (noRepeats #a (h::tl)))
= ()
let rec noRepeats_append_elim
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats (l1 @ l2)))
(ensures (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_elim q1 l2
let rec noRepeats_append_intro
(#a: eqtype)
(l1 l2: list a)
: Lemma
(requires (noRepeats l1 /\ noRepeats l2 /\ (forall x . mem x l1 ==> ~ (mem x l2))))
(ensures (noRepeats (l1 @ l2)))
(decreases l1)
= match l1 with
| [] -> ()
| x :: q1 ->
append_mem q1 l2 x;
noRepeats_append_intro q1 l2
(** Properties of [assoc] *)
let assoc_nil
(#a: eqtype)
(#b: Type)
(x: a)
: Lemma
(ensures (assoc #a #b x [] == None))
= ()
let assoc_cons_eq
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(q: list (a * b))
: Lemma
(ensures (assoc x ((x, y) :: q) == Some y))
= ()
let assoc_cons_not_eq
(#a: eqtype)
(#b: Type)
(x x': a)
(y: b)
(q: list (a * b))
: Lemma
(requires (x <> x'))
(ensures (assoc x' ((x, y) :: q) == assoc x' q))
= ()
let rec assoc_append_elim_r
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l2 == None \/ ~ (assoc x l1 == None)))
(ensures (assoc x (l1 @ l2) == assoc x l1))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_append_elim_r x q l2
let rec assoc_append_elim_l
(#a: eqtype)
(#b: Type)
(x: a)
(l1 l2: list (a * b))
: Lemma
(requires (assoc x l1 == None))
(ensures (assoc x (l1 @ l2) == assoc x l2))
(decreases l1)
= match l1 with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_append_elim_l x q l2
let rec assoc_memP_some
(#a: eqtype)
(#b: Type)
(x: a)
(y: b)
(l: list (a * b))
: Lemma
(requires (assoc x l == Some y))
(ensures (memP (x, y) l))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then () else assoc_memP_some x y q
let rec assoc_memP_none
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(requires (assoc x l == None))
(ensures (forall y . ~ (memP (x, y) l)))
(decreases l)
= match l with
| [] -> ()
| (x', _) :: q -> if x = x' then assert False else assoc_memP_none x q
let assoc_mem
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
: Lemma
(ensures (mem x (map fst l) <==> (exists y . assoc x l == Some y)))
= match assoc x l with
| None ->
assoc_memP_none x l;
mem_memP x (map fst l);
memP_map_elim fst x l
| Some y ->
assoc_memP_some x y l;
memP_map_intro fst (x, y) l;
mem_memP x (map fst l)
(** Properties of [fold_left] *)
let rec fold_left_invar
(#a #b: Type)
(f: (a -> b -> Tot a))
(l: list b)
(p: (a -> Tot Type0))
: Lemma
(requires forall (x: a) (y: b) . p x ==> memP y l ==> p (f x y) )
(ensures forall (x: a) . p x ==> p (fold_left f x l))
=
match l with
| [] -> ()
| y :: q -> fold_left_invar f q p
let rec fold_left_map
(#a #b #c: Type)
(f_aba: a -> b -> Tot a)
(f_bc: b -> Tot c)
(f_aca: a -> c -> Tot a)
(l: list b)
: Lemma
(requires forall (x: a) (y: b) . f_aba x y == f_aca x (f_bc y) )
(ensures forall (x : a) . fold_left f_aba x l == fold_left f_aca x (map f_bc l) )
=
match l with
| [] -> ()
| y :: q -> fold_left_map f_aba f_bc f_aca q
let rec map_append
(#a #b: Type)
(f: a -> Tot b)
(l1 l2: list a)
:
Lemma
(ensures map f (l1 @ l2) == map f l1 @ map f l2)
=
match l1 with
| [] -> ()
| x :: q -> map_append f q l2
let rec fold_left_append
(#a #b: Type)
(f: a -> b -> Tot a)
(l1 l2: list b)
: Lemma
(ensures forall x . fold_left f x (l1 @ l2) == fold_left f (fold_left f x l1) l2)
= match l1 with
| [] -> ()
| x :: q -> fold_left_append f q l2
let rec fold_left_monoid
(#a: Type)
(opA: (a -> a -> Tot a))
(zeroA: a)
(l: list a)
: Lemma
(requires
(forall u v w . (u `opA` (v `opA` w)) == ((u `opA` v) `opA` w)) /\
(forall x . (x `opA` zeroA) == x) /\
(forall x . (zeroA `opA` x) == x))
(ensures
forall x .
(fold_left opA x l) == (x `opA` (fold_left opA zeroA l)))
= match l with
| [] -> ()
| x :: q -> fold_left_monoid opA zeroA q
let fold_left_append_monoid
(#a: Type)
(f: (a -> a -> Tot a))
(z: a)
(l1 l2: list a)
: Lemma
(requires
(forall u v w . f u (f v w) == f (f u v) w) /\
(forall x . f x z == x) /\
(forall x . f z x == x))
(ensures
fold_left f z (l1 @ l2) == f (fold_left f z l1) (fold_left f z l2))
= fold_left_append f l1 l2;
fold_left_monoid f z l2
(* Properties of [index] *)
private let rec index_extensionality_aux
(#a: Type)
(l1 l2: list a)
(l_len: (l_len: unit { length l1 == length l2 } ))
(l_index: (i: (i: nat {i < length l1})) -> Tot (l_index: unit {index l1 i == index l2 i}))
: Lemma
(ensures (l1 == l2))
= match (l1, l2) with
| (a1::q1, a2::q2) ->
let a_eq : (a_eq : unit {a1 == a2}) = l_index 0 in
let q_len : (q_len: unit {length q1 == length q2}) = () in
let q_index (i: (i: nat {i < length q1})) : Tot (q_index: unit {index q1 i == index q2 i}) =
l_index (i + 1) in
let q_eq : (q_eq : unit {l1 == l2}) = index_extensionality_aux q1 q2 q_len q_index in
()
| _ -> ()
let index_extensionality
(#a: Type)
(l1 l2: list a)
: Lemma
(requires
(length l1 == length l2 /\
(forall (i: nat) . i < length l1 ==> index l1 i == index l2 i)))
(ensures (l1 == l2))
= index_extensionality_aux l1 l2 () (fun i -> ())
(** Properties of [strict_suffix_of] *)
let rec strict_suffix_of_nil (#a: Type) (x: a) (l: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of [] (x::l)))
(decreases l)
= match l with
| [] -> ()
| a' :: q -> strict_suffix_of_nil a' q
let strict_suffix_of_or_eq_nil (#a: Type) (l: list a)
: Lemma
(ensures (strict_suffix_of [] l \/ l == []))
= match l with
| [] -> ()
| a :: q -> strict_suffix_of_nil a q
let strict_suffix_of_cons (#a: Type) (x: a) (l: list a) :
Lemma
(ensures (strict_suffix_of l (x::l)))
= ()
let rec strict_suffix_of_trans (#a: Type) (l1 l2 l3: list a)
: Lemma
(requires True)
(ensures ((strict_suffix_of l1 l2 /\ strict_suffix_of l2 l3) ==> strict_suffix_of l1 l3))
(decreases l3)
[SMTPat (strict_suffix_of l1 l2); SMTPat (strict_suffix_of l2 l3)]
= match l3 with
| [] -> ()
| _ :: q -> strict_suffix_of_trans l1 l2 q
let rec strict_suffix_of_correct (#a) (l1 l2: list a)
: Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> l1 << l2))
(decreases l2)
= match l2 with
| [] -> ()
| _ :: q ->
strict_suffix_of_correct l1 q
let rec map_strict_suffix_of (#a #b: Type) (f: a -> Tot b) (l1: list a) (l2: list a) :
Lemma
(requires True)
(ensures (strict_suffix_of l1 l2 ==> strict_suffix_of (map f l1) (map f l2)))
(decreases l2)
= match l2 with
| [] -> ()
| a::q ->
map_strict_suffix_of f l1 q
let rec mem_strict_suffix_of (#a: eqtype) (l1: list a) (m: a) (l2: list a)
: Lemma
(requires True)
(ensures ((mem m l1 /\ strict_suffix_of l1 l2) ==> mem m l2))
= match l2 with
| [] -> ()
| a :: q ->
mem_strict_suffix_of l1 m q
let rec strict_suffix_of_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures (strict_suffix_of l1 l2 ==> (exists l3 . l2 == append l3 l1)))
= match l2 with
| [] -> ()
| a :: q ->
FStar.Classical.or_elim
#(l1 == q)
#(strict_suffix_of l1 q)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: []))
(fun _ ->
FStar.Classical.exists_elim
(exists l3 . l2 == append l3 l1)
#_
#(fun l3 -> q == append l3 l1)
(strict_suffix_of_exists_append l1 q)
(fun l3 ->
FStar.Classical.exists_intro (fun l3 -> l2 == append l3 l1) (a :: l3)
))
let strict_suffix_of_or_eq_exists_append
(#a: Type)
(l1 l2: list a)
: Lemma
(ensures ((strict_suffix_of l1 l2 \/ l1 == l2) ==> (exists l3 . l2 == append l3 l1)))
= FStar.Classical.or_elim
#(strict_suffix_of l1 l2)
#(l1 == l2)
#(fun _ -> exists l3 . l2 == append l3 l1)
(fun _ ->
strict_suffix_of_exists_append l1 l2)
(fun _ ->
FStar.Classical.exists_intro
(fun l3 -> l2 == append l3 l1)
[] )
(** Properties of << with lists *)
let precedes_tl
(#a: Type)
(l: list a {Cons? l})
: Lemma (ensures (tl l << l))
= ()
let rec precedes_append_cons_r
(#a: Type)
(l1: list a)
(x: a)
(l2: list a)
: Lemma
(requires True)
(ensures (x << append l1 (x :: l2)))
[SMTPat (x << append l1 (x :: l2))]
= match l1 with
| [] -> ()
| _ :: q -> precedes_append_cons_r q x l2
let precedes_append_cons_prod_r
(#a #b: Type)
(l1: list (a * b))
(x: a)
(y: b)
(l2: list (a * b))
: Lemma
(ensures
x << (append l1 ((x, y) :: l2)) /\
y << (append l1 ((x, y) :: l2)))
= precedes_append_cons_r l1 (x, y) l2
let rec memP_precedes
(#a: Type)
(x: a)
(l: list a)
: Lemma
(requires True)
(ensures (memP x l ==> x << l))
(decreases l)
= match l with
| [] -> ()
| y :: q ->
FStar.Classical.or_elim
#(x == y)
#(memP x q)
#(fun _ -> x << l)
(fun _ -> ())
(fun _ -> memP_precedes x q)
let assoc_precedes
(#a: eqtype)
(#b: Type)
(x: a)
(l: list (a * b))
(y: b)
: Lemma
(requires (assoc x l == Some y))
(ensures (x << l /\ y << l))
= assoc_memP_some x y l;
memP_precedes (x, y) l
(** Properties about find *)
let rec find_none
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
(x: a)
: Lemma
(requires (find f l == None /\ memP x l))
(ensures (f x == false))
= let (x' :: l') = l in
Classical.or_elim
#(x == x')
#(~ (x == x'))
#(fun _ -> f x == false)
(fun h -> ())
(fun h -> find_none f l' x)
(** Properties of init and last *)
let rec append_init_last (#a: Type) (l: list a { Cons? l }) : Lemma
(l == append (init l) [last l])
= match l with
| a :: q ->
if Cons? q
then
append_init_last q
else
()
let rec init_last_def (#a: Type) (l: list a) (x: a) : Lemma
(let l' = append l [x] in
init l' == l /\ last l' == x)
= match l with
| [] -> ()
| y :: q -> init_last_def q x
let init_last_inj (#a: Type) (l1: list a { Cons? l1 } ) (l2: list a { Cons? l2 } ) : Lemma
(requires (init l1 == init l2 /\ last l1 == last l2))
(ensures (l1 == l2))
= append_init_last l1;
append_init_last l2
(* Properties of for_all *)
#push-options "--fuel 1"
let rec for_all_append #a (f: a -> Tot bool) (s1 s2: list a): Lemma | false | false | FStar.List.Tot.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val for_all_append (#a: _) (f: (a -> Tot bool)) (s1 s2: list a)
: Lemma (ensures for_all f (s1 @ s2) <==> for_all f s1 && for_all f s2) | [
"recursion"
] | FStar.List.Tot.Properties.for_all_append | {
"file_name": "ulib/FStar.List.Tot.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> Prims.bool) -> s1: Prims.list a -> s2: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.for_all f (s1 @ s2) <==>
FStar.List.Tot.Base.for_all f s1 && FStar.List.Tot.Base.for_all f s2) | {
"end_col": 41,
"end_line": 1129,
"start_col": 1,
"start_line": 1125
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } ) | let vlarray (t: Type) (min max: nat) = | false | null | false | (l: list t {min <= L.length l /\ L.length l <= max}) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.list",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction | false | true | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray : t: Type -> min: Prims.nat -> max: Prims.nat -> Type | [] | LowParse.Spec.Array.vlarray | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t: Type -> min: Prims.nat -> max: Prims.nat -> Type | {
"end_col": 57,
"end_line": 371,
"start_col": 2,
"start_line": 371
} |
|
Prims.GTot | val array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n | val array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 = | false | null | false | L.length s == n | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"sometrivial"
] | [
"Prims.nat",
"Prims.list",
"Prims.eq2",
"FStar.List.Tot.Base.length"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false" | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 | [] | LowParse.Spec.Array.array_pred | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | n: Prims.nat -> s: Prims.list t -> Prims.GTot Type0 | {
"end_col": 17,
"end_line": 18,
"start_col": 2,
"start_line": 18
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array (t: Type) (n: nat) = (l: list t { array_pred n l } ) | let array (t: Type) (n: nat) = | false | null | false | (l: list t {array_pred n l}) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.list",
"LowParse.Spec.Array.array_pred"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low | false | true | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array : t: Type -> n: Prims.nat -> Type | [] | LowParse.Spec.Array.array | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t: Type -> n: Prims.nat -> Type | {
"end_col": 62,
"end_line": 53,
"start_col": 31,
"start_line": 53
} |
|
Prims.GTot | val vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max | val vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 = | false | null | false | let l = L.length s in
min <= l /\ l <= max | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"sometrivial"
] | [
"Prims.nat",
"Prims.list",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 | [] | LowParse.Spec.Array.vlarray_pred | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | min: Prims.nat -> max: Prims.nat -> s: Prims.list t -> Prims.GTot Type0 | {
"end_col": 24,
"end_line": 302,
"start_col": 69,
"start_line": 300
} |
Prims.Tot | val fldata_array_precond (k: parser_kind) (array_byte_size elem_count: nat) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size | val fldata_array_precond (k: parser_kind) (array_byte_size elem_count: nat) : Tot bool
let fldata_array_precond (k: parser_kind) (array_byte_size elem_count: nat) : Tot bool = | false | null | false | serialize_list_precond k && k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.nat",
"Prims.op_AmpAmp",
"LowParse.Spec.List.serialize_list_precond",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.bool"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat) | false | true | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fldata_array_precond (k: parser_kind) (array_byte_size elem_count: nat) : Tot bool | [] | LowParse.Spec.Array.fldata_array_precond | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | k: LowParse.Spec.Base.parser_kind -> array_byte_size: Prims.nat -> elem_count: Prims.nat
-> Prims.bool | {
"end_col": 50,
"end_line": 28,
"start_col": 2,
"start_line": 26
} |
Prims.Tot | val parse_array_kind' (array_byte_size: nat) : Tot parser_kind | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind | val parse_array_kind' (array_byte_size: nat) : Tot parser_kind
let parse_array_kind' (array_byte_size: nat) : Tot parser_kind = | false | null | false | parse_fldata_kind array_byte_size parse_list_kind | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.Base.parser_kind"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat) | false | true | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_array_kind' (array_byte_size: nat) : Tot parser_kind | [] | LowParse.Spec.Array.parse_array_kind' | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | array_byte_size: Prims.nat -> LowParse.Spec.Base.parser_kind | {
"end_col": 51,
"end_line": 95,
"start_col": 2,
"start_line": 95
} |
Prims.Tot | val parse_array_kind (k: parser_kind) (array_byte_size elem_count: nat) : Tot parser_kind | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size | val parse_array_kind (k: parser_kind) (array_byte_size elem_count: nat) : Tot parser_kind
let parse_array_kind (k: parser_kind) (array_byte_size elem_count: nat) : Tot parser_kind = | false | null | false | if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then total_constant_size_parser_kind array_byte_size
else parse_array_kind' array_byte_size | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.nat",
"Prims.op_AmpAmp",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserKindMetadataTotal",
"LowParse.Spec.Base.total_constant_size_parser_kind",
"Prims.bool",
"LowParse.Spec.Array.parse_array_kind'"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat) | false | true | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_array_kind (k: parser_kind) (array_byte_size elem_count: nat) : Tot parser_kind | [] | LowParse.Spec.Array.parse_array_kind | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | k: LowParse.Spec.Base.parser_kind -> array_byte_size: Prims.nat -> elem_count: Prims.nat
-> LowParse.Spec.Base.parser_kind | {
"end_col": 37,
"end_line": 149,
"start_col": 2,
"start_line": 143
} |
Prims.Tot | val parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max:
nat
{ array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\
array_byte_size_max < 4294967296 })
: Tot parser_kind | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind | val parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max:
nat
{ array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\
array_byte_size_max < 4294967296 })
: Tot parser_kind
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max:
nat
{ array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\
array_byte_size_max < 4294967296 })
: Tot parser_kind = | false | null | false | parse_bounded_vldata_strong_kind array_byte_size_min
array_byte_size_max
(log256' array_byte_size_max)
parse_list_kind | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.Base.parser_kind"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } ) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max:
nat
{ array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\
array_byte_size_max < 4294967296 })
: Tot parser_kind | [] | LowParse.Spec.Array.parse_vlarray_kind | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max:
Prims.nat
{ array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\
array_byte_size_max < 4294967296 }
-> LowParse.Spec.Base.parser_kind | {
"end_col": 120,
"end_line": 421,
"start_col": 2,
"start_line": 421
} |
Prims.GTot | val vldata_vlarray_precond
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: GTot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low | val vldata_vlarray_precond
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: GTot bool
let vldata_vlarray_precond
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: GTot bool = | false | null | false | serialize_list_precond k && k.parser_kind_high = Some k.parser_kind_low &&
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"sometrivial"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.op_AmpAmp",
"LowParse.Spec.List.serialize_list_precond",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Prims.bool"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vldata_vlarray_precond
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: GTot bool | [] | LowParse.Spec.Array.vldata_vlarray_precond | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
p: LowParse.Spec.Base.parser k t ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat
-> Prims.GTot Prims.bool | {
"end_col": 81,
"end_line": 328,
"start_col": 5,
"start_line": 314
} |
Prims.Pure | val parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count) | val parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True))
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True)) = | false | null | false | parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count)
(parse_array' s array_byte_size elem_count) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"LowParse.Spec.Base.strengthen",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array'",
"Prims.unit",
"LowParse.Spec.Array.parse_array_kind_correct",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.l_True"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
)) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True)) | [] | LowParse.Spec.Array.parse_array | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s: LowParse.Spec.Base.serializer p -> array_byte_size: Prims.nat -> elem_count: Prims.nat
-> Prims.Pure
(LowParse.Spec.Base.parser (LowParse.Spec.Array.parse_array_kind k array_byte_size elem_count)
(LowParse.Spec.Array.array t elem_count)) | {
"end_col": 104,
"end_line": 185,
"start_col": 2,
"start_line": 184
} |
Prims.Pure | val parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u) | val parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True))
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True)) = | false | null | false | let u:u: unit{fldata_array_precond k array_byte_size elem_count == true} = () in
fldata_to_array_inj s array_byte_size elem_count u;
(parse_fldata_strong (serialize_list _ s) array_byte_size)
`parse_synth`
(fldata_to_array s array_byte_size elem_count u) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.array",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.Array.fldata_to_array",
"Prims.unit",
"LowParse.Spec.Array.fldata_to_array_inj",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.Array.parse_array_kind'",
"Prims.l_True"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
)) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures (fun _ -> True)) | [] | LowParse.Spec.Array.parse_array' | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s: LowParse.Spec.Base.serializer p -> array_byte_size: Prims.nat -> elem_count: Prims.nat
-> Prims.Pure
(LowParse.Spec.Base.parser (LowParse.Spec.Array.parse_array_kind' array_byte_size)
(LowParse.Spec.Array.array t elem_count)) | {
"end_col": 121,
"end_line": 111,
"start_col": 1,
"start_line": 109
} |
FStar.Pervasives.Lemma | val vldata_vlarray_precond_parser_kind_low
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[
SMTPat (k.parser_kind_low);
SMTPat
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max)
] | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max | val vldata_vlarray_precond_parser_kind_low
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[
SMTPat (k.parser_kind_low);
SMTPat
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max)
]
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[
SMTPat (k.parser_kind_low);
SMTPat
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max)
] = | false | null | true | M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Math.Lemmas.lemma_mult_le_right",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"Prims.b2t",
"LowParse.Spec.Array.vldata_vlarray_precond",
"Prims.squash",
"Prims.op_LessThan",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.bool",
"Prims.Nil"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296)) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vldata_vlarray_precond_parser_kind_low
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min elem_count_max: nat)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[
SMTPat (k.parser_kind_low);
SMTPat
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max)
] | [] | LowParse.Spec.Array.vldata_vlarray_precond_parser_kind_low | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
p: LowParse.Spec.Base.parser k t ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max)
(ensures Mkparser_kind'?.parser_kind_low k < 4294967296)
[
SMTPat (Mkparser_kind'?.parser_kind_low k);
SMTPat (LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max)
] | {
"end_col": 58,
"end_line": 342,
"start_col": 2,
"start_line": 342
} |
Prims.Tot | val array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x' | val array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size) = | false | null | false | [@@ inline_let ]let x':list t = x in
[@@ inline_let ]let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x' | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.array_to_fldata_correct",
"Prims.list",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size) | [] | LowParse.Spec.Array.array_to_fldata | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
u80:
u82: Prims.unit{LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true} ->
x: LowParse.Spec.Array.array t elem_count
-> LowParse.Spec.FLData.parse_fldata_strong_t (LowParse.Spec.List.serialize_list p s)
array_byte_size | {
"end_col": 4,
"end_line": 223,
"start_col": 2,
"start_line": 219
} |
FStar.Pervasives.Lemma | val array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\ array_pred elem_count x))
(ensures (parse_fldata_strong_pred (serialize_list _ s) array_byte_size x)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y | val array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\ array_pred elem_count x))
(ensures (parse_fldata_strong_pred (serialize_list _ s) array_byte_size x))
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\ array_pred elem_count x))
(ensures (parse_fldata_strong_pred (serialize_list _ s) array_byte_size x)) = | false | null | true | let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.list",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.Array.array_pred",
"Prims.squash",
"LowParse.Spec.FLData.parse_fldata_strong_pred",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\ array_pred elem_count x))
(ensures (parse_fldata_strong_pred (serialize_list _ s) array_byte_size x)) | [] | LowParse.Spec.Array.array_to_fldata_correct | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
x: Prims.list t
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
LowParse.Spec.Array.array_pred elem_count x)
(ensures
LowParse.Spec.FLData.parse_fldata_strong_pred (LowParse.Spec.List.serialize_list p s)
array_byte_size
x) | {
"end_col": 46,
"end_line": 204,
"start_col": 1,
"start_line": 203
} |
Prims.Tot | val serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array s array_byte_size elem_count)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x | val serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array s array_byte_size elem_count))
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array s array_byte_size elem_count)) = | false | null | false | fun x -> serialize (serialize_array' s array_byte_size elem_count u) x | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.Array.array",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.parse_array'",
"LowParse.Spec.Array.serialize_array'",
"LowParse.Bytes.bytes",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.parse_array"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
}) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array s array_byte_size elem_count)) | [] | LowParse.Spec.Array.serialize_array | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
u104:
u105:
Prims.unit{LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true}
-> LowParse.Spec.Base.serializer (LowParse.Spec.Array.parse_array s array_byte_size elem_count) | {
"end_col": 72,
"end_line": 271,
"start_col": 2,
"start_line": 271
} |
Prims.Tot | val vlarray_to_vldata
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Tot
(parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_to_vldata
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: vlarray t elem_count_min elem_count_max)
: Tot (parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x' | val vlarray_to_vldata
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Tot
(parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
let vlarray_to_vldata
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Tot
(parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) = | false | null | false | [@@ inline_let ]let x':list t = x in
[@@ inline_let ]let _ =
vlarray_to_vldata_correct array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
x'
in
x' | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.vlarray_to_vldata_correct",
"Prims.list",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind
let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (parser (parse_vlarray_kind array_byte_size_min array_byte_size_max) (vlarray t elem_count_min elem_count_max))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)
`parse_synth`
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
let parse_vlarray_eq_some
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (
Some? (parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input)
))
(ensures (
let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\ (
let Some (len, c_len) = pi in
c_len == sz /\
array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\ (
let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\ (
let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\ (
let Some (l, c_l) = pl in
c_l == U32.v len /\
vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input == Some (l, c_len + c_l)
))))))
=
parser_kind_prop_equiv k p;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) input;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) input;
parser_kind_prop_equiv parse_list_kind (parse_list p)
let vlarray_to_vldata_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
vlarray_pred elem_count_min elem_count_max x
))
(ensures (
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lemma_mult_le_right k.parser_kind_low elem_count_min l;
M.lemma_mult_le_right k.parser_kind_low l elem_count_max
inline_for_extraction
let vlarray_to_vldata
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: vlarray t elem_count_min elem_count_max) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_to_vldata
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Tot
(parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) | [] | LowParse.Spec.Array.vlarray_to_vldata | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u203:
u205:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
x: LowParse.Spec.Array.vlarray t elem_count_min elem_count_max
-> LowParse.Spec.VLData.parse_bounded_vldata_strong_t array_byte_size_min
array_byte_size_max
(LowParse.Spec.List.serialize_list p s) | {
"end_col": 4,
"end_line": 526,
"start_col": 2,
"start_line": 522
} |
Prims.Tot | val serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array' s array_byte_size elem_count)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
() | val serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array' s array_byte_size elem_count))
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array' s array_byte_size elem_count)) = | false | null | false | fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth _
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
() | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.array",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Spec.FLData.serialize_fldata_strong",
"LowParse.Spec.Array.array_to_fldata",
"LowParse.Spec.Array.array_to_fldata_to_array",
"LowParse.Spec.Array.fldata_to_array_inj",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.parse_array'"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
}) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
: Tot (serializer (parse_array' s array_byte_size elem_count)) | [] | LowParse.Spec.Array.serialize_array' | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
u97:
u98: Prims.unit{LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true}
-> LowParse.Spec.Base.serializer (LowParse.Spec.Array.parse_array' s array_byte_size elem_count) | {
"end_col": 6,
"end_line": 258,
"start_col": 2,
"start_line": 251
} |
FStar.Pervasives.Lemma | val fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x))
(ensures (array_pred elem_count x)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low | val fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x))
(ensures (array_pred elem_count x))
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x))
(ensures (array_pred elem_count x)) = | false | null | true | let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.list",
"LowParse.Math.mul_reg_r",
"FStar.List.Tot.Base.length",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.List.parse_list",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.serialize_list",
"Prims.l_and",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.FLData.parse_fldata_strong_pred",
"Prims.squash",
"LowParse.Spec.Array.array_pred",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: list t)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x))
(ensures (array_pred elem_count x)) | [] | LowParse.Spec.Array.fldata_to_array_correct | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
x: Prims.list t
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
LowParse.Spec.FLData.parse_fldata_strong_pred (LowParse.Spec.List.serialize_list p s)
array_byte_size
x) (ensures LowParse.Spec.Array.array_pred elem_count x) | {
"end_col": 55,
"end_line": 50,
"start_col": 1,
"start_line": 46
} |
FStar.Pervasives.Lemma | val length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) ==
(L.length x)
`FStar.Mul.op_Star`
k.parser_kind_low) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x) | val length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) ==
(L.length x)
`FStar.Mul.op_Star`
k.parser_kind_low)
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) ==
(L.length x)
`FStar.Mul.op_Star`
k.parser_kind_low) = | false | null | true | fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq _
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.Array.array",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Spec.FLData.serialize_fldata_strong",
"LowParse.Spec.Array.array_to_fldata",
"LowParse.Spec.Array.array_to_fldata_to_array",
"LowParse.Spec.Array.fldata_to_array_inj",
"Prims.l_True",
"Prims.squash",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.parse_array",
"LowParse.Spec.Array.serialize_array",
"FStar.Mul.op_Star",
"FStar.List.Tot.Base.length",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) ==
(L.length x)
`FStar.Mul.op_Star`
k.parser_kind_low) | [] | LowParse.Spec.Array.length_serialize_array | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
u112:
u116:
Prims.unit{LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true} ->
x: LowParse.Spec.Array.array t elem_count
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.length (LowParse.Spec.Base.serialize (LowParse.Spec.Array.serialize_array s
array_byte_size
elem_count
u112)
x) ==
FStar.List.Tot.Base.length x * Mkparser_kind'?.parser_kind_low k) | {
"end_col": 79,
"end_line": 297,
"start_col": 2,
"start_line": 287
} |
FStar.Pervasives.Lemma | val parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: bytes)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\ Seq.length x >= array_byte_size)
) (ensures (Some? (parse (parse_array' s array_byte_size elem_count) x))) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p) | val parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: bytes)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\ Seq.length x >= array_byte_size)
) (ensures (Some? (parse (parse_array' s array_byte_size elem_count) x)))
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: bytes)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\ Seq.length x >= array_byte_size)
) (ensures (Some? (parse (parse_array' s array_byte_size elem_count) x))) = | false | null | true | let u:u: unit{fldata_array_precond k array_byte_size elem_count == true} = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size)
(fldata_to_array s array_byte_size elem_count u)
x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"Prims.list",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.parse_list",
"Prims.unit",
"LowParse.Spec.List.parse_list_total_constant_size",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.array",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Spec.Array.fldata_to_array_inj",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.l_and",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserKindMetadataTotal",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"Prims.squash",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Array.parse_array'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(x: bytes)
: Lemma
(requires
(fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\ Seq.length x >= array_byte_size)
) (ensures (Some? (parse (parse_array' s array_byte_size elem_count) x))) | [] | LowParse.Spec.Array.parse_array_total_constant_size | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
x: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
Mkparser_kind'?.parser_kind_metadata k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserKindMetadataTotal /\
FStar.Seq.Base.length x >= array_byte_size)
(ensures
Some? (LowParse.Spec.Base.parse (LowParse.Spec.Array.parse_array' s
array_byte_size
elem_count)
x)) | {
"end_col": 55,
"end_line": 135,
"start_col": 1,
"start_line": 130
} |
FStar.Pervasives.Lemma | val parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Lemma (requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures
(parser_kind_prop (parse_array_kind k array_byte_size elem_count)
(parse_array' s array_byte_size elem_count))) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end | val parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Lemma (requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures
(parser_kind_prop (parse_array_kind k array_byte_size elem_count)
(parse_array' s array_byte_size elem_count)))
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Lemma (requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures
(parser_kind_prop (parse_array_kind k array_byte_size elem_count)
(parse_array' s array_byte_size elem_count))) = | false | null | true | if k.parser_kind_metadata = Some ParserKindMetadataTotal
then
(parser_kind_prop_equiv (parse_array_kind' array_byte_size)
(parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count)
(parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s
array_byte_size
elem_count))) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserKindMetadataTotal",
"FStar.Classical.forall_intro",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Array.array",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Array.parse_array'",
"FStar.Classical.move_requires",
"LowParse.Spec.Array.parse_array_total_constant_size",
"Prims.unit",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.parse_array_kind'",
"Prims.squash",
"LowParse.Spec.Base.parser_kind_prop",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
: Lemma (requires (fldata_array_precond k array_byte_size elem_count == true))
(ensures
(parser_kind_prop (parse_array_kind k array_byte_size elem_count)
(parse_array' s array_byte_size elem_count))) | [] | LowParse.Spec.Array.parse_array_kind_correct | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s: LowParse.Spec.Base.serializer p -> array_byte_size: Prims.nat -> elem_count: Prims.nat
-> FStar.Pervasives.Lemma
(requires LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true)
(ensures
LowParse.Spec.Base.parser_kind_prop (LowParse.Spec.Array.parse_array_kind k
array_byte_size
elem_count)
(LowParse.Spec.Array.parse_array' s array_byte_size elem_count)) | {
"end_col": 5,
"end_line": 170,
"start_col": 2,
"start_line": 165
} |
Prims.Tot | val serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(serializer (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (serializer (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
vlarray_to_vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
serialize_synth
_
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
(serialize_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
() | val serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(serializer (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u))
let serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(serializer (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)) = | false | null | false | vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
vlarray_to_vldata_to_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u;
serialize_synth _
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
(serialize_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
() | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.VLData.serialize_bounded_vldata_strong",
"LowParse.Spec.Array.vlarray_to_vldata",
"LowParse.Spec.Array.vlarray_to_vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.parse_vlarray"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind
let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (parser (parse_vlarray_kind array_byte_size_min array_byte_size_max) (vlarray t elem_count_min elem_count_max))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)
`parse_synth`
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
let parse_vlarray_eq_some
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (
Some? (parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input)
))
(ensures (
let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\ (
let Some (len, c_len) = pi in
c_len == sz /\
array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\ (
let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\ (
let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\ (
let Some (l, c_l) = pl in
c_l == U32.v len /\
vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input == Some (l, c_len + c_l)
))))))
=
parser_kind_prop_equiv k p;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) input;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) input;
parser_kind_prop_equiv parse_list_kind (parse_list p)
let vlarray_to_vldata_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
vlarray_pred elem_count_min elem_count_max x
))
(ensures (
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lemma_mult_le_right k.parser_kind_low elem_count_min l;
M.lemma_mult_le_right k.parser_kind_low l elem_count_max
inline_for_extraction
let vlarray_to_vldata
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: vlarray t elem_count_min elem_count_max)
: Tot (parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vlarray_to_vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x: vlarray t elem_count_min elem_count_max) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x))
}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x)
== x)
= ()
let serialize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
}) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(serializer (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)) | [] | LowParse.Spec.Array.serialize_vlarray | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u221:
u222:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true }
-> LowParse.Spec.Base.serializer (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u221) | {
"end_col": 6,
"end_line": 571,
"start_col": 2,
"start_line": 564
} |
Prims.Tot | val parse_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(parser (parse_vlarray_kind array_byte_size_min array_byte_size_max)
(vlarray t elem_count_min elem_count_max)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (parser (parse_vlarray_kind array_byte_size_min array_byte_size_max) (vlarray t elem_count_min elem_count_max))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)
`parse_synth`
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u | val parse_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(parser (parse_vlarray_kind array_byte_size_min array_byte_size_max)
(vlarray t elem_count_min elem_count_max))
let parse_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(parser (parse_vlarray_kind array_byte_size_min array_byte_size_max)
(vlarray t elem_count_min elem_count_max)) = | false | null | false | vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
`parse_synth`
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"LowParse.Spec.Array.parse_vlarray_kind"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind
let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
}) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(parser (parse_vlarray_kind array_byte_size_min array_byte_size_max)
(vlarray t elem_count_min elem_count_max)) | [] | LowParse.Spec.Array.parse_vlarray | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u174:
u175:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true }
-> LowParse.Spec.Base.parser (LowParse.Spec.Array.parse_vlarray_kind array_byte_size_min
array_byte_size_max)
(LowParse.Spec.Array.vlarray t elem_count_min elem_count_max) | {
"end_col": 93,
"end_line": 439,
"start_col": 2,
"start_line": 436
} |
Prims.Tot | val fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x' | val fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count) = | false | null | false | [@@ inline_let ]let x':list t = x in
[@@ inline_let ]let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x' | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.fldata_to_array_correct",
"LowParse.Spec.Array.array"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(u: unit{fldata_array_precond k array_byte_size elem_count == true})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count) | [] | LowParse.Spec.Array.fldata_to_array | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
u29:
u31: Prims.unit{LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true} ->
x:
LowParse.Spec.FLData.parse_fldata_strong_t (LowParse.Spec.List.serialize_list p s)
array_byte_size
-> LowParse.Spec.Array.array t elem_count | {
"end_col": 4,
"end_line": 72,
"start_col": 2,
"start_line": 68
} |
FStar.Pervasives.Lemma | val vldata_to_vlarray_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) (ensures (vlarray_pred elem_count_min elem_count_max x)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low | val vldata_to_vlarray_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) (ensures (vlarray_pred elem_count_min elem_count_max x))
let vldata_to_vlarray_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) (ensures (vlarray_pred elem_count_min elem_count_max x)) = | false | null | true | let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.list",
"LowParse.Math.lt_mul_add_reg_r",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.List.parse_list",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.List.Tot.Base.length",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.serialize_list",
"Prims.l_and",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"Prims.squash",
"LowParse.Spec.Array.vlarray_pred",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vldata_to_vlarray_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) (ensures (vlarray_pred elem_count_min elem_count_max x)) | [] | LowParse.Spec.Array.vldata_to_vlarray_correct | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
x: Prims.list t
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
LowParse.Spec.VLData.parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(LowParse.Spec.List.serialize_list p s)
x) (ensures LowParse.Spec.Array.vlarray_pred elem_count_min elem_count_max x) | {
"end_col": 55,
"end_line": 367,
"start_col": 1,
"start_line": 362
} |
FStar.Pervasives.Lemma | val vlarray_to_vldata_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\ vlarray_pred elem_count_min elem_count_max x))
(ensures
(parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_to_vldata_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
vlarray_pred elem_count_min elem_count_max x
))
(ensures (
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lemma_mult_le_right k.parser_kind_low elem_count_min l;
M.lemma_mult_le_right k.parser_kind_low l elem_count_max | val vlarray_to_vldata_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\ vlarray_pred elem_count_min elem_count_max x))
(ensures
(parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x))
let vlarray_to_vldata_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\ vlarray_pred elem_count_min elem_count_max x))
(ensures
(parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) = | false | null | true | let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lemma_mult_le_right k.parser_kind_low elem_count_min l;
M.lemma_mult_le_right k.parser_kind_low l elem_count_max | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.list",
"FStar.Math.Lemmas.lemma_mult_le_right",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.List.parse_list",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.List.Tot.Base.length",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.serialize_list",
"Prims.l_and",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.Array.vlarray_pred",
"Prims.squash",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind
let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (parser (parse_vlarray_kind array_byte_size_min array_byte_size_max) (vlarray t elem_count_min elem_count_max))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)
`parse_synth`
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
let parse_vlarray_eq_some
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (
Some? (parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input)
))
(ensures (
let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\ (
let Some (len, c_len) = pi in
c_len == sz /\
array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\ (
let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\ (
let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\ (
let Some (l, c_l) = pl in
c_l == U32.v len /\
vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input == Some (l, c_len + c_l)
))))))
=
parser_kind_prop_equiv k p;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) input;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) input;
parser_kind_prop_equiv parse_list_kind (parse_list p)
let vlarray_to_vldata_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
vlarray_pred elem_count_min elem_count_max x
))
(ensures (
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_to_vldata_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(x: list t)
: Lemma
(requires
(vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\ vlarray_pred elem_count_min elem_count_max x))
(ensures
(parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(serialize_list _ s)
x)) | [] | LowParse.Spec.Array.vlarray_to_vldata_correct | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
x: Prims.list t
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\ LowParse.Spec.Array.vlarray_pred elem_count_min elem_count_max x)
(ensures
LowParse.Spec.VLData.parse_bounded_vldata_strong_pred array_byte_size_min
array_byte_size_max
(LowParse.Spec.List.serialize_list p s)
x) | {
"end_col": 58,
"end_line": 505,
"start_col": 1,
"start_line": 500
} |
Prims.Tot | val vldata_to_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)
)
: Tot (vlarray t elem_count_min elem_count_max) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x' | val vldata_to_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)
)
: Tot (vlarray t elem_count_min elem_count_max)
let vldata_to_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x:
parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)
)
: Tot (vlarray t elem_count_min elem_count_max) = | false | null | false | [@@ inline_let ]let x':list t = x in
[@@ inline_let ]let _ =
vldata_to_vlarray_correct array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
x'
in
x' | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vldata_to_vlarray_correct",
"LowParse.Spec.Array.vlarray"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vldata_to_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)
)
: Tot (vlarray t elem_count_min elem_count_max) | [] | LowParse.Spec.Array.vldata_to_vlarray | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u154:
u156:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
x:
LowParse.Spec.VLData.parse_bounded_vldata_strong_t array_byte_size_min
array_byte_size_max
(LowParse.Spec.List.serialize_list p s)
-> LowParse.Spec.Array.vlarray t elem_count_min elem_count_max | {
"end_col": 4,
"end_line": 392,
"start_col": 2,
"start_line": 388
} |
FStar.Pervasives.Lemma | val length_serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Lemma
(Seq.length (serialize (serialize_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
x) ==
log256' array_byte_size_max + ((L.length x) `FStar.Mul.op_Star` k.parser_kind_low)) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_serialize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: vlarray t elem_count_min elem_count_max)
: Lemma
(Seq.length (serialize (serialize_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) x) == log256' array_byte_size_max + (L.length x `FStar.Mul.op_Star` k.parser_kind_low))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
vlarray_to_vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
serialize_synth_eq
_
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
(serialize_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x) | val length_serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Lemma
(Seq.length (serialize (serialize_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
x) ==
log256' array_byte_size_max + ((L.length x) `FStar.Mul.op_Star` k.parser_kind_low))
let length_serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Lemma
(Seq.length (serialize (serialize_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
x) ==
log256' array_byte_size_max + ((L.length x) `FStar.Mul.op_Star` k.parser_kind_low)) = | false | null | true | vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
vlarray_to_vldata_to_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u;
serialize_synth_eq _
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
(serialize_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
()
x;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.VLData.serialize_bounded_vldata_strong",
"LowParse.Spec.Array.vlarray_to_vldata",
"LowParse.Spec.Array.vlarray_to_vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"Prims.l_True",
"Prims.squash",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Spec.Array.serialize_vlarray",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"FStar.List.Tot.Base.length",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind
let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (parser (parse_vlarray_kind array_byte_size_min array_byte_size_max) (vlarray t elem_count_min elem_count_max))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)
`parse_synth`
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
let parse_vlarray_eq_some
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (
Some? (parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input)
))
(ensures (
let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\ (
let Some (len, c_len) = pi in
c_len == sz /\
array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\ (
let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\ (
let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\ (
let Some (l, c_l) = pl in
c_l == U32.v len /\
vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input == Some (l, c_len + c_l)
))))))
=
parser_kind_prop_equiv k p;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) input;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) input;
parser_kind_prop_equiv parse_list_kind (parse_list p)
let vlarray_to_vldata_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
vlarray_pred elem_count_min elem_count_max x
))
(ensures (
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lemma_mult_le_right k.parser_kind_low elem_count_min l;
M.lemma_mult_le_right k.parser_kind_low l elem_count_max
inline_for_extraction
let vlarray_to_vldata
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: vlarray t elem_count_min elem_count_max)
: Tot (parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vlarray_to_vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x: vlarray t elem_count_min elem_count_max) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x))
}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x)
== x)
= ()
let serialize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (serializer (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
vlarray_to_vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
serialize_synth
_
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
(serialize_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vlarray_to_vldata array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u)
()
let length_serialize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: vlarray t elem_count_min elem_count_max)
: Lemma | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_serialize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: vlarray t elem_count_min elem_count_max)
: Lemma
(Seq.length (serialize (serialize_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
x) ==
log256' array_byte_size_max + ((L.length x) `FStar.Mul.op_Star` k.parser_kind_low)) | [] | LowParse.Spec.Array.length_serialize_vlarray | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u231:
u235:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
x: LowParse.Spec.Array.vlarray t elem_count_min elem_count_max
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.length (LowParse.Spec.Base.serialize (LowParse.Spec.Array.serialize_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u231)
x) ==
LowParse.Spec.BoundedInt.log256' array_byte_size_max +
FStar.List.Tot.Base.length x * Mkparser_kind'?.parser_kind_low k) | {
"end_col": 79,
"end_line": 598,
"start_col": 2,
"start_line": 588
} |
FStar.Pervasives.Lemma | val parse_vlarray_eq_some
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(Some? (parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input)))
(ensures
(let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\
(let Some (len, c_len) = pi in
c_len == sz /\ array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\
(let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\
(let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\
(let Some (l, c_l) = pl in
c_l == U32.v len /\ vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input ==
Some (l, c_len + c_l))))))) | [
{
"abbrev": false,
"full_module": "FStar.Mul // for Prims.op_Multiply",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vlarray_eq_some
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (
Some? (parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input)
))
(ensures (
let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\ (
let Some (len, c_len) = pi in
c_len == sz /\
array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\ (
let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\ (
let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\ (
let Some (l, c_l) = pl in
c_l == U32.v len /\
vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input == Some (l, c_len + c_l)
))))))
=
parser_kind_prop_equiv k p;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) input;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) input;
parser_kind_prop_equiv parse_list_kind (parse_list p) | val parse_vlarray_eq_some
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(Some? (parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input)))
(ensures
(let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\
(let Some (len, c_len) = pi in
c_len == sz /\ array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\
(let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\
(let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\
(let Some (l, c_l) = pl in
c_l == U32.v len /\ vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input ==
Some (l, c_len + c_l)))))))
let parse_vlarray_eq_some
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(Some? (parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input)))
(ensures
(let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\
(let Some (len, c_len) = pi in
c_len == sz /\ array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\
(let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\
(let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\
(let Some (l, c_l) = pl in
c_l == U32.v len /\ vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input ==
Some (l, c_len + c_l))))))) = | false | null | true | parser_kind_prop_equiv k p;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min
array_byte_size_max
(serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
input;
parse_vldata_gen_eq (log256' array_byte_size_max)
(in_bounds array_byte_size_min array_byte_size_max)
(parse_list p)
input;
parser_kind_prop_equiv parse_list_kind (parse_list p) | {
"checked_file": "LowParse.Spec.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"Prims.list",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.BoundedInt.in_bounds",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Array.parse_vlarray",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.UInt32.v",
"Prims.int",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.Array.vlarray_pred",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"Prims.logical",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.BoundedInt.integer_size",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.Array
include LowParse.Spec.FLData
include LowParse.Spec.VLData
include LowParse.Spec.List
module Seq = FStar.Seq
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
open FStar.Mul // for Prims.op_Multiply
// arith lemmas must be called explicitly
#reset-options "--z3cliopt smt.arith.nl=false"
let array_pred (#t: Type) (n: nat) (s: list t) : GTot Type0 =
L.length s == n
inline_for_extraction
let fldata_array_precond
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot bool
= serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
elem_count * k.parser_kind_low = array_byte_size
let fldata_to_array_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
(ensures (
array_pred elem_count x
))
= let y = serialize (serialize_list _ s) x in
assert (parse (parse_list p) y == Some (x, array_byte_size));
assert (Seq.length y == array_byte_size);
list_length_constant_size_parser_correct p y;
M.mul_reg_r elem_count (L.length x) k.parser_kind_low
inline_for_extraction
let array (t: Type) (n: nat) = (l: list t { array_pred n l } )
inline_for_extraction
let fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: parse_fldata_strong_t (serialize_list _ s) array_byte_size)
: Tot (array t elem_count)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = fldata_to_array_correct s array_byte_size elem_count x' in
x'
let fldata_to_array_inj
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x1 x2: parse_fldata_strong_t (serialize_list _ s) array_byte_size) . {:pattern (fldata_to_array s array_byte_size elem_count u x1); (fldata_to_array s array_byte_size elem_count u x2)}
fldata_to_array s array_byte_size elem_count u x1 ==
fldata_to_array s array_byte_size elem_count u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_array_kind'
(array_byte_size: nat)
: Tot parser_kind
= parse_fldata_kind array_byte_size parse_list_kind
let parse_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind' array_byte_size) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_fldata_strong (serialize_list _ s) array_byte_size `parse_synth` (fldata_to_array s array_byte_size elem_count u)
let parse_array_total_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: bytes)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= array_byte_size
))
(ensures (
Some? (parse (parse_array' s array_byte_size elem_count) x)
))
= let (u : unit { fldata_array_precond k array_byte_size elem_count == true } ) = () in
fldata_to_array_inj s array_byte_size elem_count u;
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count u) x;
let x' = Seq.slice x 0 array_byte_size in
parse_list_total_constant_size p elem_count x';
parser_kind_prop_equiv parse_list_kind (parse_list p)
inline_for_extraction
let parse_array_kind
(k: parser_kind)
(array_byte_size: nat)
(elem_count: nat)
: Tot parser_kind
= if
fldata_array_precond k array_byte_size elem_count &&
k.parser_kind_metadata = Some ParserKindMetadataTotal
then
total_constant_size_parser_kind array_byte_size
else
parse_array_kind' array_byte_size
let parse_array_kind_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (
parser_kind_prop (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then begin
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array' s array_byte_size elem_count);
parser_kind_prop_equiv (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count);
Classical.forall_intro (Classical.move_requires (parse_array_total_constant_size s array_byte_size elem_count))
end
let parse_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
: Pure (parser (parse_array_kind k array_byte_size elem_count) (array t elem_count))
(requires (
fldata_array_precond k array_byte_size elem_count == true
))
(ensures (fun _ -> True))
= parse_array_kind_correct s array_byte_size elem_count;
strengthen (parse_array_kind k array_byte_size elem_count) (parse_array' s array_byte_size elem_count)
let array_to_fldata_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(x: list t)
: Lemma
(requires (
fldata_array_precond k array_byte_size elem_count == true /\
array_pred elem_count x
))
(ensures (
parse_fldata_strong_pred (serialize_list _ s) array_byte_size x
))
= let y = serialize (serialize_list _ s) x in
list_length_constant_size_parser_correct p y
inline_for_extraction
let array_to_fldata
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Tot (parse_fldata_strong_t (serialize_list _ s) array_byte_size)
= [@inline_let]
let (x' : list t) = x in
[@inline_let]
let _ = array_to_fldata_correct s array_byte_size elem_count x' in
x'
let array_to_fldata_to_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u1 u2: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Lemma
(forall (x: array t elem_count) . {:pattern (fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x))}
fldata_to_array s array_byte_size elem_count u1 (array_to_fldata s array_byte_size elem_count u2 x) == x)
= ()
let serialize_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array' s array_byte_size elem_count))
= fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
let serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
: Tot (serializer (parse_array s array_byte_size elem_count))
= fun x -> serialize (serialize_array' s array_byte_size elem_count u) x
let length_serialize_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true
})
(x: array t elem_count)
: Lemma
(Seq.length (serialize (serialize_array s array_byte_size elem_count u) x) == L.length x `FStar.Mul.op_Star` k.parser_kind_low)
=
fldata_to_array_inj s array_byte_size elem_count u;
array_to_fldata_to_array s array_byte_size elem_count u u;
serialize_synth_eq
_
(fldata_to_array s array_byte_size elem_count u)
(serialize_fldata_strong (serialize_list _ s) array_byte_size)
(array_to_fldata s array_byte_size elem_count u)
()
x
;
list_length_constant_size_parser_correct p (serialize (serialize_list _ s) x)
let vlarray_pred (#t: Type) (min max: nat) (s: list t) : GTot Type0 =
let l = L.length s in
min <= l /\ l <= max
let vldata_vlarray_precond
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: GTot bool
= (* constant-size serializable parser for elements *)
serialize_list_precond k &&
k.parser_kind_high = Some k.parser_kind_low &&
(* vldata *)
array_byte_size_min <= array_byte_size_max &&
array_byte_size_max > 0 &&
array_byte_size_max < 4294967296 &&
(* vlarray *)
elem_count_min <= elem_count_max &&
0 < elem_count_max &&
(* ceil (array_byte_size_min / k.parser_kind_low) = elem_count_min *)
elem_count_min * k.parser_kind_low < array_byte_size_min + k.parser_kind_low &&
array_byte_size_min <= elem_count_min * k.parser_kind_low &&
(* floor (array_byte_size_max / k.parser_kind_low) = elem_count_max *)
elem_count_max * k.parser_kind_low <= array_byte_size_max &&
array_byte_size_max < elem_count_max * k.parser_kind_low + k.parser_kind_low
let vldata_vlarray_precond_parser_kind_low
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(elem_count_min: nat)
(elem_count_max: nat)
: Lemma
(requires (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max))
(ensures (k.parser_kind_low < 4294967296))
[SMTPat (k.parser_kind_low); SMTPat (vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max)]
= M.lemma_mult_le_right k.parser_kind_low 1 elem_count_max
let vldata_to_vlarray_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(x: list t)
: Lemma
(requires (
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
parse_bounded_vldata_strong_pred array_byte_size_min array_byte_size_max (serialize_list _ s) x
))
(ensures (
vlarray_pred elem_count_min elem_count_max x
))
= let y = serialize (serialize_list _ s) x in
let l = L.length x in
assert (parse (parse_list p) y == Some (x, Seq.length y));
list_length_constant_size_parser_correct p y;
M.lt_mul_add_reg_r elem_count_min l k.parser_kind_low;
M.lt_mul_add_reg_r l elem_count_max k.parser_kind_low
inline_for_extraction
let vlarray (t: Type) (min max: nat) =
(l: list t { min <= L.length l /\ L.length l <= max } )
inline_for_extraction
let vldata_to_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s))
: Tot (vlarray t elem_count_min elem_count_max)
= [@inline_let]
let x' : list t = x in
[@inline_let]
let _ = vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max x' in
x'
let vldata_to_vlarray_inj
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Lemma
(forall (x1 x2: parse_bounded_vldata_strong_t array_byte_size_min array_byte_size_max (serialize_list _ s)) .
{:pattern
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1);
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2)}
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x1 ==
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u x2 ==>
x1 == x2)
= ()
inline_for_extraction
let parse_vlarray_kind
(array_byte_size_min: nat)
(array_byte_size_max: nat { array_byte_size_min <= array_byte_size_max /\ array_byte_size_max > 0 /\ array_byte_size_max < 4294967296 } )
: Tot parser_kind
= parse_bounded_vldata_strong_kind array_byte_size_min array_byte_size_max (log256' array_byte_size_max) parse_list_kind
let parse_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (parser (parse_vlarray_kind array_byte_size_min array_byte_size_max) (vlarray t elem_count_min elem_count_max))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)
`parse_synth`
vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
let parse_vlarray_eq_some
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (
Some? (parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input)
))
(ensures (
let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\ (
let Some (len, c_len) = pi in
c_len == sz /\
array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\ (
let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\ (
let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\ (
let Some (l, c_l) = pl in
c_l == U32.v len /\
vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u) input == Some (l, c_len + c_l)
)))))) | false | false | LowParse.Spec.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_vlarray_eq_some
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(Some? (parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input)))
(ensures
(let sz = log256' array_byte_size_max in
let pi = parse (parse_bounded_integer sz) input in
Some? pi /\
(let Some (len, c_len) = pi in
c_len == sz /\ array_byte_size_min <= U32.v len /\ U32.v len <= array_byte_size_max /\
(let input1 = Seq.slice input c_len (Seq.length input) in
U32.v len <= Seq.length input1 /\
(let input2 = Seq.slice input1 0 (U32.v len) in
let pl = parse (parse_list p) input2 in
Some? pl /\
(let Some (l, c_l) = pl in
c_l == U32.v len /\ vlarray_pred elem_count_min elem_count_max l /\
parse (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)
input ==
Some (l, c_len + c_l))))))) | [] | LowParse.Spec.Array.parse_vlarray_eq_some | {
"file_name": "src/lowparse/LowParse.Spec.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u184:
u210:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Some? (LowParse.Spec.Base.parse (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u184)
input))
(ensures
(let sz = LowParse.Spec.BoundedInt.log256' array_byte_size_max in
let pi =
LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer sz) input
in
Some? pi /\
(let _ = pi in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ len c_len)
=
_
in
c_len == sz /\ array_byte_size_min <= FStar.UInt32.v len /\
FStar.UInt32.v len <= array_byte_size_max /\
(let input1 = FStar.Seq.Base.slice input c_len (FStar.Seq.Base.length input) in
FStar.UInt32.v len <= FStar.Seq.Base.length input1 /\
(let input2 = FStar.Seq.Base.slice input1 0 (FStar.UInt32.v len) in
let pl = LowParse.Spec.Base.parse (LowParse.Spec.List.parse_list p) input2 in
Some? pl /\
(let _ = pl in
(let
FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ l c_l)
=
_
in
c_l == FStar.UInt32.v len /\
LowParse.Spec.Array.vlarray_pred elem_count_min elem_count_max l /\
LowParse.Spec.Base.parse (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u184)
input ==
FStar.Pervasives.Native.Some (l, c_len + c_l))
<:
Prims.logical))))
<:
Prims.logical))) | {
"end_col": 55,
"end_line": 480,
"start_col": 2,
"start_line": 476
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
} | let stack_bq = | false | null | false | { modified = true; taint = Public; strict_disjointness = true } | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.Mkbuffer_qualifiers",
"Vale.Arch.HeapTypes_s.Public"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val stack_bq : Vale.Interop.Base.buffer_qualifiers | [] | Vale.Interop.Base.stack_bq | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.Base.buffer_qualifiers | {
"end_col": 28,
"end_line": 67,
"start_col": 2,
"start_line": 65
} |
|
Prims.Tot | val normal (#a: Type) (x: a) : a | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x | val normal (#a: Type) (x: a) : a
let normal (#a: Type) (x: a) : a = | false | null | false | FStar.Pervasives.norm [
iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [
`%TD_Buffer?; `%BS.Mkmachine_state?.ms_ok; `%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags; `%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack; `%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace; `%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on; `%List.Tot.fold_right_gtot; `%List.Tot.map_gtot;
`%List.Tot.length; `%fst; `%snd; `%Mktuple2?._1; `%Mktuple2?._2
];
primops;
simplify
]
x | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.primops",
"FStar.Pervasives.simplify"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val normal (#a: Type) (x: a) : a | [] | Vale.Interop.Base.normal | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: a -> a | {
"end_col": 6,
"end_line": 105,
"start_col": 2,
"start_line": 81
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args | let mem_roots_p (h0: HS.mem) (args: list arg) = | false | null | false | disjoint_or_eq args /\ all_live h0 args | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.list",
"Vale.Interop.Base.arg",
"Prims.l_and",
"Vale.Interop.Base.disjoint_or_eq",
"Vale.Interop.Base.all_live",
"Prims.logical"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mem_roots_p : h0: FStar.Monotonic.HyperStack.mem -> args: Prims.list Vale.Interop.Base.arg -> Prims.logical | [] | Vale.Interop.Base.mem_roots_p | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h0: FStar.Monotonic.HyperStack.mem -> args: Prims.list Vale.Interop.Base.arg -> Prims.logical | {
"end_col": 18,
"end_line": 252,
"start_col": 2,
"start_line": 251
} |
|
Prims.Tot | val intro_n_arrow_nil (a: Type) (x: a) : n_arrow [] a | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x | val intro_n_arrow_nil (a: Type) (x: a) : n_arrow [] a
let intro_n_arrow_nil (a: Type) (x: a) : n_arrow [] a = | false | null | false | x | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.n_arrow",
"Prims.Nil",
"Vale.Interop.Base.td"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_n_arrow_nil (a: Type) (x: a) : n_arrow [] a | [] | Vale.Interop.Base.intro_n_arrow_nil | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Type -> x: a -> Vale.Interop.Base.n_arrow [] a | {
"end_col": 5,
"end_line": 149,
"start_col": 4,
"start_line": 149
} |
Prims.Tot | val __test:n_dep_arrow [TD_Base TUInt8] (fun (x: UInt8.t) -> y: UInt8.t{x == y}) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x | val __test:n_dep_arrow [TD_Base TUInt8] (fun (x: UInt8.t) -> y: UInt8.t{x == y})
let __test:n_dep_arrow [TD_Base TUInt8] (fun (x: UInt8.t) -> y: UInt8.t{x == y}) = | false | null | false | fun (x: UInt8.t) -> intro_dep_arrow_nil (y: UInt8.t{x == y}) x | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"FStar.UInt8.t",
"Vale.Interop.Base.intro_dep_arrow_nil",
"Prims.eq2",
"Vale.Interop.Base.n_dep_arrow",
"Prims.Nil",
"Vale.Interop.Base.td",
"Vale.Interop.Base.elim_1",
"Prims.Cons",
"Vale.Interop.Base.TD_Base",
"Vale.Arch.HeapTypes_s.TUInt8",
"Vale.Interop.Base.n_arrow"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val __test:n_dep_arrow [TD_Base TUInt8] (fun (x: UInt8.t) -> y: UInt8.t{x == y}) | [] | Vale.Interop.Base.__test | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.Base.n_dep_arrow [Vale.Interop.Base.TD_Base Vale.Arch.HeapTypes_s.TUInt8]
(fun x -> y: FStar.UInt8.t{x == y}) | {
"end_col": 62,
"end_line": 205,
"start_col": 2,
"start_line": 205
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_base_type = x:base_typ{x <> TUInt128} | let valid_base_type = | false | null | false | x: base_typ{x <> TUInt128} | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.b2t",
"Prims.op_disEquality",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
} | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_base_type : Type0 | [] | Vale.Interop.Base.valid_base_type | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 47,
"end_line": 70,
"start_col": 22,
"start_line": 70
} |
|
Prims.Tot | val arg_of_lb (#src #t: _) (x: buf_t src t) : arg | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arg_of_lb #src #t (x:buf_t src t) : arg = (| TD_Buffer src t default_bq, x |) | val arg_of_lb (#src #t: _) (x: buf_t src t) : arg
let arg_of_lb #src #t (x: buf_t src t) : arg = | false | null | false | (| TD_Buffer src t default_bq, x |) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"Prims.Mkdtuple2",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"Vale.Interop.Base.default_bq",
"Vale.Interop.Base.arg"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args
let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h
let mk_mem_injective (args:list arg) (h:mem_roots args)
: Lemma (hs_of_mem (mk_mem args h) == h /\
ptrs_of_mem (mk_mem args h) == args_b8 args)
= ()
let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures
mem_roots_p h1 args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _, _ |) -> ()
| (| TD_Buffer _ _ _, x |)
| (| TD_ImmBuffer _ _ _, x |) -> assert (B.live h1 x) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arg_of_lb (#src #t: _) (x: buf_t src t) : arg | [] | Vale.Interop.Base.arg_of_lb | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Interop.Base.buf_t src t -> Vale.Interop.Base.arg | {
"end_col": 81,
"end_line": 425,
"start_col": 46,
"start_line": 425
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arg = t:td & td_as_type t | let arg = | false | null | false | t: td & td_as_type t | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.dtuple2",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arg : Type0 | [] | Vale.Interop.Base.arg | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 29,
"end_line": 117,
"start_col": 10,
"start_line": 117
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
} | let default_bq = | false | null | false | { modified = true; taint = Secret; strict_disjointness = false } | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.Mkbuffer_qualifiers",
"Vale.Arch.HeapTypes_s.Secret"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val default_bq : Vale.Interop.Base.buffer_qualifiers | [] | Vale.Interop.Base.default_bq | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.Base.buffer_qualifiers | {
"end_col": 29,
"end_line": 60,
"start_col": 2,
"start_line": 58
} |
|
Prims.GTot | val mut_to_b8 (src: base_typ) (b: B.buffer (base_typ_as_type src)) : GTot b8 | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b | val mut_to_b8 (src: base_typ) (b: B.buffer (base_typ_as_type src)) : GTot b8
let mut_to_b8 (src: base_typ) (b: B.buffer (base_typ_as_type src)) : GTot b8 = | false | null | false | Buffer true b | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"LowStar.Buffer.buffer",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.Buffer",
"Vale.Interop.Types.b8"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mut_to_b8 (src: base_typ) (b: B.buffer (base_typ_as_type src)) : GTot b8 | [] | Vale.Interop.Base.mut_to_b8 | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
src: Vale.Arch.HeapTypes_s.base_typ ->
b: LowStar.Buffer.buffer (Vale.Interop.Types.base_typ_as_type src)
-> Prims.GTot Vale.Interop.Types.b8 | {
"end_col": 15,
"end_line": 43,
"start_col": 2,
"start_line": 43
} |
Prims.GTot | val imm_to_b8 (src: base_typ) (b: IB.ibuffer (base_typ_as_type src)) : GTot b8 | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b | val imm_to_b8 (src: base_typ) (b: IB.ibuffer (base_typ_as_type src)) : GTot b8
let imm_to_b8 (src: base_typ) (b: IB.ibuffer (base_typ_as_type src)) : GTot b8 = | false | null | false | Buffer false b | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"LowStar.ImmutableBuffer.ibuffer",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.Buffer",
"Vale.Interop.Types.b8"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0 | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val imm_to_b8 (src: base_typ) (b: IB.ibuffer (base_typ_as_type src)) : GTot b8 | [] | Vale.Interop.Base.imm_to_b8 | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
src: Vale.Arch.HeapTypes_s.base_typ ->
b: LowStar.ImmutableBuffer.ibuffer (Vale.Interop.Types.base_typ_as_type src)
-> Prims.GTot Vale.Interop.Types.b8 | {
"end_col": 16,
"end_line": 40,
"start_col": 2,
"start_line": 40
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arr (dom:Type) (codom:Type) = dom -> codom | let arr (dom codom: Type) = | false | null | false | dom -> codom | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arr : dom: Type -> codom: Type -> Type | [] | Vale.Interop.Base.arr | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | dom: Type -> codom: Type -> Type | {
"end_col": 46,
"end_line": 130,
"start_col": 34,
"start_line": 130
} |
|
Prims.GTot | val modified_arg_loc (x: arg) : GTot B.loc | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none | val modified_arg_loc (x: arg) : GTot B.loc
let modified_arg_loc (x: arg) : GTot B.loc = | false | null | false | match x with
| (| TD_Buffer _ _ { modified = true } , x |) -> B.loc_buffer x
| _ -> B.loc_none | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Vale.Interop.Base.arg",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.taint",
"Prims.bool",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"Vale.Interop.Base.Mkbuffer_qualifiers",
"LowStar.Monotonic.Buffer.loc_buffer",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Prims.dtuple2",
"Vale.Interop.Base.td",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.loc"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__] | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modified_arg_loc (x: arg) : GTot B.loc | [] | Vale.Interop.Base.modified_arg_loc | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Interop.Base.arg -> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 21,
"end_line": 272,
"start_col": 4,
"start_line": 270
} |
Prims.Tot | val intro_dep_arrow_nil (b: Type) (f: b) : n_dep_arrow [] b | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f | val intro_dep_arrow_nil (b: Type) (f: b) : n_dep_arrow [] b
let intro_dep_arrow_nil (b: Type) (f: b) : n_dep_arrow [] b = | false | null | false | f | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.n_dep_arrow",
"Prims.Nil",
"Vale.Interop.Base.td"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_dep_arrow_nil (b: Type) (f: b) : n_dep_arrow [] b | [] | Vale.Interop.Base.intro_dep_arrow_nil | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Type -> f: b -> Vale.Interop.Base.n_dep_arrow [] b | {
"end_col": 5,
"end_line": 171,
"start_col": 4,
"start_line": 171
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l | let disjoint_or_eq (l: list arg) = | false | null | false | BigOps.pairwise_and' disjoint_or_eq_1 l | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.BigOps.pairwise_and'",
"Vale.Interop.Base.disjoint_or_eq_1"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_or_eq : l: Prims.list Vale.Interop.Base.arg -> Type0 | [] | Vale.Interop.Base.disjoint_or_eq | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | l: Prims.list Vale.Interop.Base.arg -> Type0 | {
"end_col": 42,
"end_line": 236,
"start_col": 2,
"start_line": 236
} |
|
Prims.GTot | val loc_modified_args (args: list arg) : GTot B.loc | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none | val loc_modified_args (args: list arg) : GTot B.loc
let loc_modified_args (args: list arg) : GTot B.loc = | false | null | false | let maybe_union_loc (x: arg) l =
match x with
| (| TD_Buffer _ _ { modified = true } , x |) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.List.Tot.Base.fold_right_gtot",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_none",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.taint",
"Prims.bool",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"Vale.Interop.Base.Mkbuffer_qualifiers",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_buffer",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Prims.dtuple2",
"Vale.Interop.Base.td"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val loc_modified_args (args: list arg) : GTot B.loc | [] | Vale.Interop.Base.loc_modified_args | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg -> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 60,
"end_line": 281,
"start_col": 52,
"start_line": 275
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs | let all_live (h: HS.mem) (bs: list arg) = | false | null | false | BigOps.big_and' (live_arg h) bs | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.BigOps.big_and'",
"Vale.Interop.Base.live_arg"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_live : h: FStar.Monotonic.HyperStack.mem -> bs: Prims.list Vale.Interop.Base.arg -> Type0 | [] | Vale.Interop.Base.all_live | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> bs: Prims.list Vale.Interop.Base.arg -> Type0 | {
"end_col": 33,
"end_line": 247,
"start_col": 2,
"start_line": 247
} |
|
Prims.Tot | val intro_n_arrow_cons (hd: td) (b: Type) (tl: list td) (x: (td_as_type hd -> n_arrow tl b))
: n_arrow (hd :: tl) b | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x | val intro_n_arrow_cons (hd: td) (b: Type) (tl: list td) (x: (td_as_type hd -> n_arrow tl b))
: n_arrow (hd :: tl) b
let intro_n_arrow_cons (hd: td) (b: Type) (tl: list td) (x: (td_as_type hd -> n_arrow tl b))
: n_arrow (hd :: tl) b = | false | null | false | x | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.td",
"Prims.list",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.n_arrow",
"Prims.Cons"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_n_arrow_cons (hd: td) (b: Type) (tl: list td) (x: (td_as_type hd -> n_arrow tl b))
: n_arrow (hd :: tl) b | [] | Vale.Interop.Base.intro_n_arrow_cons | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
hd: Vale.Interop.Base.td ->
b: Type ->
tl: Prims.list Vale.Interop.Base.td ->
x: (_: Vale.Interop.Base.td_as_type hd -> Vale.Interop.Base.n_arrow tl b)
-> Vale.Interop.Base.n_arrow (hd :: tl) b | {
"end_col": 5,
"end_line": 155,
"start_col": 4,
"start_line": 155
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True | let disjoint_or_eq_1 (a b: arg) = | false | null | false | match a, b with
| (| TD_Buffer _ _ { strict_disjointness = true } , xb |), (| TD_Buffer _ _ _ , yb |)
| (| TD_ImmBuffer _ _ { strict_disjointness = true } , xb |), (| TD_ImmBuffer _ _ _ , yb |)
| (| TD_Buffer _ _ _ , xb |), (| TD_Buffer _ _ { strict_disjointness = true } , yb |)
| (| TD_ImmBuffer _ _ _ , xb |), (| TD_ImmBuffer _ _ { strict_disjointness = true } , yb |)
| (| TD_ImmBuffer _ _ _ , xb |), (| TD_Buffer _ _ _ , yb |)
| (| TD_Buffer _ _ _ , xb |), (| TD_ImmBuffer _ _ _ , yb |) -> disjoint_not_eq xb yb
| (| TD_Buffer srcx tx { taint = tntx } , xb |), (| TD_Buffer srcy ty { taint = tnty } , yb |)
| (| TD_ImmBuffer srcx tx { taint = tntx } , xb |), (| TD_ImmBuffer srcy ty { taint = tnty } , yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.arg",
"FStar.Pervasives.Native.Mktuple2",
"Prims.dtuple2",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.bool",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Interop.Base.TD_Buffer",
"Vale.Interop.Base.Mkbuffer_qualifiers",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.disjoint_not_eq",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Base.TD_ImmBuffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Prims.l_or",
"Prims.l_and",
"Prims.op_Equals_Equals_Equals",
"Prims.eq2",
"FStar.Pervasives.Native.tuple2",
"Prims.l_True",
"Prims.logical"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_or_eq_1 : a: Vale.Interop.Base.arg -> b: Vale.Interop.Base.arg -> Prims.logical | [] | Vale.Interop.Base.disjoint_or_eq_1 | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Vale.Interop.Base.arg -> b: Vale.Interop.Base.arg -> Prims.logical | {
"end_col": 15,
"end_line": 232,
"start_col": 4,
"start_line": 220
} |
|
Prims.GTot | val loc_all_args (args: list arg) : GTot B.loc | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none | val loc_all_args (args: list arg) : GTot B.loc
let loc_all_args (args: list arg) : GTot B.loc = | false | null | false | let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.List.Tot.Base.fold_right_gtot",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.List.Tot.Base.map_gtot",
"Vale.Interop.Base.arg_loc"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val loc_all_args (args: list arg) : GTot B.loc | [] | Vale.Interop.Base.loc_all_args | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg -> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 53,
"end_line": 293,
"start_col": 47,
"start_line": 291
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args } | let mem_roots (args: list arg) = | false | null | false | h0: HS.mem{mem_roots_p h0 args} | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.mem_roots_p"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mem_roots : args: Prims.list Vale.Interop.Base.arg -> Type | [] | Vale.Interop.Base.mem_roots | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg -> Type | {
"end_col": 36,
"end_line": 256,
"start_col": 4,
"start_line": 256
} |
|
Prims.Tot | val arg_of_sb (#t: _) (x: buf_t TUInt64 t) : arg | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arg_of_sb #t (x:buf_t TUInt64 t) :arg = (| TD_Buffer TUInt64 t stack_bq, x |) | val arg_of_sb (#t: _) (x: buf_t TUInt64 t) : arg
let arg_of_sb #t (x: buf_t TUInt64 t) : arg = | false | null | false | (| TD_Buffer TUInt64 t stack_bq, x |) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.Mkdtuple2",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"Vale.Interop.Base.stack_bq",
"Vale.Interop.Base.arg"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args
let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h
let mk_mem_injective (args:list arg) (h:mem_roots args)
: Lemma (hs_of_mem (mk_mem args h) == h /\
ptrs_of_mem (mk_mem args h) == args_b8 args)
= ()
let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures
mem_roots_p h1 args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _, _ |) -> ()
| (| TD_Buffer _ _ _, x |)
| (| TD_ImmBuffer _ _ _, x |) -> assert (B.live h1 x)
[@__reduce__]
let arg_of_lb #src #t (x:buf_t src t) : arg = (| TD_Buffer src t default_bq, x |) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arg_of_sb (#t: _) (x: buf_t TUInt64 t) : arg | [] | Vale.Interop.Base.arg_of_sb | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Interop.Base.buf_t Vale.Arch.HeapTypes_s.TUInt64 t -> Vale.Interop.Base.arg | {
"end_col": 81,
"end_line": 428,
"start_col": 44,
"start_line": 428
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0} | let buf_t src t = | false | null | false | b: B.buffer (base_typ_as_type src) {(B.length b * view_n_unfold src) % view_n_unfold t = 0} | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"LowStar.Buffer.buffer",
"Vale.Interop.Types.base_typ_as_type",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Types.view_n_unfold"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buf_t : src: Vale.Arch.HeapTypes_s.base_typ -> t: Vale.Arch.HeapTypes_s.base_typ -> Type0 | [] | Vale.Interop.Base.buf_t | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | src: Vale.Arch.HeapTypes_s.base_typ -> t: Vale.Arch.HeapTypes_s.base_typ -> Type0 | {
"end_col": 107,
"end_line": 21,
"start_col": 18,
"start_line": 21
} |
|
Prims.Tot | val coerce (x: 'a{'a == 'b}) : 'b | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let coerce (x:'a{'a == 'b}) : 'b = x | val coerce (x: 'a{'a == 'b}) : 'b
let coerce (x: 'a{'a == 'b}) : 'b = | false | null | false | x | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.eq2"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val coerce (x: 'a{'a == 'b}) : 'b | [] | Vale.Interop.Base.coerce | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: 'a{'a == 'b} -> 'b | {
"end_col": 36,
"end_line": 46,
"start_col": 35,
"start_line": 46
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x) | let rec n_dep_arrow (dom: list td) (codom: n_arrow dom Type) = | false | null | false | match dom with
| [] -> codom
| hd :: tl -> x: td_as_type hd -> n_dep_arrow tl (elim_1 codom x) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.Interop.Base.td",
"Vale.Interop.Base.n_arrow",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.n_dep_arrow",
"Vale.Interop.Base.elim_1"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)] | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val n_dep_arrow : dom: Prims.list Vale.Interop.Base.td -> codom: Vale.Interop.Base.n_arrow dom Type -> Type | [
"recursion"
] | Vale.Interop.Base.n_dep_arrow | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | dom: Prims.list Vale.Interop.Base.td -> codom: Vale.Interop.Base.n_arrow dom Type -> Type | {
"end_col": 64,
"end_line": 165,
"start_col": 2,
"start_line": 163
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom | let rec n_arrow (dom: list td) (codom: Type) = | false | null | false | match dom with
| [] -> codom
| hd :: tl -> td_as_type hd -> n_arrow tl codom | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.n_arrow"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val n_arrow : dom: Prims.list Vale.Interop.Base.td -> codom: Type -> Type | [
"recursion"
] | Vale.Interop.Base.n_arrow | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | dom: Prims.list Vale.Interop.Base.td -> codom: Type -> Type | {
"end_col": 47,
"end_line": 127,
"start_col": 2,
"start_line": 125
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0} | let ibuf_t src t = | false | null | false | b: IB.ibuffer (base_typ_as_type src) {(B.length b * view_n_unfold src) % view_n_unfold t = 0} | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"LowStar.ImmutableBuffer.ibuffer",
"Vale.Interop.Types.base_typ_as_type",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"LowStar.Monotonic.Buffer.length",
"LowStar.ImmutableBuffer.immutable_preorder",
"Vale.Interop.Types.view_n_unfold"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0} | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ibuf_t : src: Vale.Arch.HeapTypes_s.base_typ -> t: Vale.Arch.HeapTypes_s.base_typ -> Type0 | [] | Vale.Interop.Base.ibuf_t | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | src: Vale.Arch.HeapTypes_s.base_typ -> t: Vale.Arch.HeapTypes_s.base_typ -> Type0 | {
"end_col": 110,
"end_line": 24,
"start_col": 19,
"start_line": 24
} |
|
Prims.Tot | val elim_nil (#dom: list td {Nil? dom}) (#r: Type) (f: n_arrow dom r) : r | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f | val elim_nil (#dom: list td {Nil? dom}) (#r: Type) (f: n_arrow dom r) : r
let elim_nil (#dom: list td {Nil? dom}) (#r: Type) (f: n_arrow dom r) : r = | false | null | false | f | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.Interop.Base.td",
"Prims.b2t",
"Prims.uu___is_Nil",
"Vale.Interop.Base.n_arrow"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_nil (#dom: list td {Nil? dom}) (#r: Type) (f: n_arrow dom r) : r | [] | Vale.Interop.Base.elim_nil | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Vale.Interop.Base.n_arrow dom r -> r | {
"end_col": 5,
"end_line": 144,
"start_col": 4,
"start_line": 144
} |
Prims.Tot | val elim_dep_arrow_nil (#codom: n_arrow [] Type) (f: n_dep_arrow [] codom) : elim_nil codom | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f | val elim_dep_arrow_nil (#codom: n_arrow [] Type) (f: n_dep_arrow [] codom) : elim_nil codom
let elim_dep_arrow_nil (#codom: n_arrow [] Type) (f: n_dep_arrow [] codom) : elim_nil codom = | false | null | false | f | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.n_arrow",
"Prims.Nil",
"Vale.Interop.Base.td",
"Vale.Interop.Base.n_dep_arrow",
"Vale.Interop.Base.elim_nil"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_dep_arrow_nil (#codom: n_arrow [] Type) (f: n_dep_arrow [] codom) : elim_nil codom | [] | Vale.Interop.Base.elim_dep_arrow_nil | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Vale.Interop.Base.n_dep_arrow [] codom -> Vale.Interop.Base.elim_nil codom | {
"end_col": 6,
"end_line": 192,
"start_col": 5,
"start_line": 192
} |
Prims.GTot | val args_b8 (args: list arg) : GTot (list b8) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer [] | val args_b8 (args: list arg) : GTot (list b8)
let args_b8 (args: list arg) : GTot (list b8) = | false | null | false | let maybe_cons_buffer (x: arg) (args: list b8) : GTot (list b8) =
match x with
| (| TD_Buffer src _ _ , x |) -> mut_to_b8 src x :: args
| (| TD_ImmBuffer src _ _ , x |) -> imm_to_b8 src x :: args
| (| TD_Base _ , _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer [] | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.List.Tot.Base.fold_right_gtot",
"Vale.Interop.Types.b8",
"Prims.Nil",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"Prims.Cons",
"Vale.Interop.Base.mut_to_b8",
"Vale.Interop.Base.TD_ImmBuffer",
"Vale.Interop.Base.imm_to_b8",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.TD_Base"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args } | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val args_b8 (args: list arg) : GTot (list b8) | [] | Vale.Interop.Base.args_b8 | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg -> Prims.GTot (Prims.list Vale.Interop.Types.b8) | {
"end_col": 52,
"end_line": 266,
"start_col": 46,
"start_line": 259
} |
Prims.GTot | val write_taint
(i: nat)
(mem: interop_heap)
(ts: (b8 -> GTot taint))
(b: b8{i <= DV.length (get_downview b.bsrc)})
(accu: MS.memTaint_t)
: GTot MS.memTaint_t (decreases %[DV.length (get_downview b.bsrc) - i]) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec write_taint
(i:nat)
(mem:interop_heap)
(ts:b8 -> GTot taint)
(b:b8{i <= DV.length (get_downview b.bsrc)})
(accu:MS.memTaint_t)
: GTot MS.memTaint_t
(decreases %[DV.length (get_downview b.bsrc) - i]) =
if i = DV.length (get_downview b.bsrc) then accu
else write_taint (i + 1) mem ts b (Map.upd accu (InteropHeap?.addrs mem b + i) (ts b)) | val write_taint
(i: nat)
(mem: interop_heap)
(ts: (b8 -> GTot taint))
(b: b8{i <= DV.length (get_downview b.bsrc)})
(accu: MS.memTaint_t)
: GTot MS.memTaint_t (decreases %[DV.length (get_downview b.bsrc) - i])
let rec write_taint
(i: nat)
(mem: interop_heap)
(ts: (b8 -> GTot taint))
(b: b8{i <= DV.length (get_downview b.bsrc)})
(accu: MS.memTaint_t)
: GTot MS.memTaint_t (decreases %[DV.length (get_downview b.bsrc) - i]) = | false | null | false | if i = DV.length (get_downview b.bsrc)
then accu
else write_taint (i + 1) mem ts b (Map.upd accu (InteropHeap?.addrs mem b + i) (ts b)) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial",
""
] | [
"Prims.nat",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Interop.Types.b8",
"Vale.Arch.HeapTypes_s.taint",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Prims.op_Equality",
"Prims.bool",
"Vale.Interop.Base.write_taint",
"Prims.op_Addition",
"FStar.Map.upd",
"Prims.int",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args
let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h
let mk_mem_injective (args:list arg) (h:mem_roots args)
: Lemma (hs_of_mem (mk_mem args h) == h /\
ptrs_of_mem (mk_mem args h) == args_b8 args)
= ()
let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures
mem_roots_p h1 args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _, _ |) -> ()
| (| TD_Buffer _ _ _, x |)
| (| TD_ImmBuffer _ _ _, x |) -> assert (B.live h1 x)
[@__reduce__]
let arg_of_lb #src #t (x:buf_t src t) : arg = (| TD_Buffer src t default_bq, x |)
[@__reduce__]
let arg_of_sb #t (x:buf_t TUInt64 t) :arg = (| TD_Buffer TUInt64 t stack_bq, x |)
let rec disjoint_or_eq_fresh
#t
(x:buf_t TUInt64 t)
(args:list arg)
(h0:HS.mem)
: Lemma
(requires
all_live h0 args /\
x `B.unused_in` h0)
(ensures
BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
disjoint_or_eq_fresh x tl h0;
match hd with
| (|TD_ImmBuffer _ _ _, y|) -> ()
| _ -> ()
// Everything here should be expressed in terms of the downview, which can be considered as a buffer of bytes
let rec write_taint
(i:nat)
(mem:interop_heap)
(ts:b8 -> GTot taint)
(b:b8{i <= DV.length (get_downview b.bsrc)})
(accu:MS.memTaint_t)
: GTot MS.memTaint_t | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write_taint
(i: nat)
(mem: interop_heap)
(ts: (b8 -> GTot taint))
(b: b8{i <= DV.length (get_downview b.bsrc)})
(accu: MS.memTaint_t)
: GTot MS.memTaint_t (decreases %[DV.length (get_downview b.bsrc) - i]) | [
"recursion"
] | Vale.Interop.Base.write_taint | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Prims.nat ->
mem: Vale.Interop.Heap_s.interop_heap ->
ts: (_: Vale.Interop.Types.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint) ->
b:
Vale.Interop.Types.b8
{i <= LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))} ->
accu: Vale.Arch.HeapTypes_s.memTaint_t
-> Prims.GTot Vale.Arch.HeapTypes_s.memTaint_t | {
"end_col": 88,
"end_line": 461,
"start_col": 2,
"start_line": 460
} |
FStar.Pervasives.Lemma | val disjoint_or_eq_cons (hd: arg) (tl: list arg)
: Lemma
(disjoint_or_eq (hd :: tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl | val disjoint_or_eq_cons (hd: arg) (tl: list arg)
: Lemma
(disjoint_or_eq (hd :: tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
let disjoint_or_eq_cons (hd: arg) (tl: list arg)
: Lemma
(disjoint_or_eq (hd :: tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl)) = | false | null | true | BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"Vale.Interop.Base.arg",
"Prims.list",
"FStar.BigOps.pairwise_and'_cons",
"Vale.Interop.Base.disjoint_or_eq_1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Vale.Interop.Base.disjoint_or_eq",
"Prims.Cons",
"Prims.l_and",
"FStar.BigOps.big_and'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_or_eq_cons (hd: arg) (tl: list arg)
: Lemma
(disjoint_or_eq (hd :: tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl)) | [] | Vale.Interop.Base.disjoint_or_eq_cons | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | hd: Vale.Interop.Base.arg -> tl: Prims.list Vale.Interop.Base.arg
-> FStar.Pervasives.Lemma
(ensures
Vale.Interop.Base.disjoint_or_eq (hd :: tl) <==>
FStar.BigOps.big_and' (Vale.Interop.Base.disjoint_or_eq_1 hd) tl /\
Vale.Interop.Base.disjoint_or_eq tl) | {
"end_col": 52,
"end_line": 306,
"start_col": 4,
"start_line": 306
} |
Prims.Tot | val elim_1: #dom: list td {Cons? dom} -> #r: Type -> f: n_arrow dom r -> td_as_type (Cons?.hd dom)
-> n_arrow (Cons?.tl dom) r | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f | val elim_1: #dom: list td {Cons? dom} -> #r: Type -> f: n_arrow dom r -> td_as_type (Cons?.hd dom)
-> n_arrow (Cons?.tl dom) r
let elim_1 (#dom: list td {Cons? dom}) (#r: Type) (f: n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r = | false | null | false | f | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.Interop.Base.td",
"Prims.b2t",
"Prims.uu___is_Cons",
"Vale.Interop.Base.n_arrow",
"Vale.Interop.Base.td_as_type",
"Prims.__proj__Cons__item__hd",
"Prims.__proj__Cons__item__tl"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_1: #dom: list td {Cons? dom} -> #r: Type -> f: n_arrow dom r -> td_as_type (Cons?.hd dom)
-> n_arrow (Cons?.tl dom) r | [] | Vale.Interop.Base.elim_1 | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Vale.Interop.Base.n_arrow dom r -> _: Vale.Interop.Base.td_as_type (Cons?.hd dom)
-> Vale.Interop.Base.n_arrow (Cons?.tl dom) r | {
"end_col": 5,
"end_line": 137,
"start_col": 4,
"start_line": 137
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True | let live_arg (h: HS.mem) (x: arg) = | false | null | false | match x with
| (| TD_Buffer _ _ _ , x |) | (| TD_ImmBuffer _ _ _ , x |) -> B.live h x
| (| TD_Base _ , _ |) -> True | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.arg",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"LowStar.Monotonic.Buffer.live",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Base.TD_ImmBuffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.TD_Base",
"Prims.l_True"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__] | false | true | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val live_arg : h: FStar.Monotonic.HyperStack.mem -> x: Vale.Interop.Base.arg -> Type0 | [] | Vale.Interop.Base.live_arg | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> x: Vale.Interop.Base.arg -> Type0 | {
"end_col": 31,
"end_line": 243,
"start_col": 4,
"start_line": 240
} |
|
Prims.GTot | val create_memtaint (mem: interop_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : GTot MS.memTaint_t | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let create_memtaint
(mem:interop_heap)
(ps:list b8)
(ts:b8 -> GTot taint)
: GTot MS.memTaint_t
= List.Tot.fold_right_gtot ps (write_taint 0 mem ts) (FStar.Map.const Public) | val create_memtaint (mem: interop_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : GTot MS.memTaint_t
let create_memtaint (mem: interop_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : GTot MS.memTaint_t = | false | null | false | List.Tot.fold_right_gtot ps (write_taint 0 mem ts) (FStar.Map.const Public) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Vale.Interop.Heap_s.interop_heap",
"Prims.list",
"Vale.Interop.Types.b8",
"Vale.Arch.HeapTypes_s.taint",
"FStar.List.Tot.Base.fold_right_gtot",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Interop.Base.write_taint",
"FStar.Map.const",
"Prims.int",
"Vale.Arch.HeapTypes_s.Public"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args
let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h
let mk_mem_injective (args:list arg) (h:mem_roots args)
: Lemma (hs_of_mem (mk_mem args h) == h /\
ptrs_of_mem (mk_mem args h) == args_b8 args)
= ()
let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures
mem_roots_p h1 args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _, _ |) -> ()
| (| TD_Buffer _ _ _, x |)
| (| TD_ImmBuffer _ _ _, x |) -> assert (B.live h1 x)
[@__reduce__]
let arg_of_lb #src #t (x:buf_t src t) : arg = (| TD_Buffer src t default_bq, x |)
[@__reduce__]
let arg_of_sb #t (x:buf_t TUInt64 t) :arg = (| TD_Buffer TUInt64 t stack_bq, x |)
let rec disjoint_or_eq_fresh
#t
(x:buf_t TUInt64 t)
(args:list arg)
(h0:HS.mem)
: Lemma
(requires
all_live h0 args /\
x `B.unused_in` h0)
(ensures
BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
disjoint_or_eq_fresh x tl h0;
match hd with
| (|TD_ImmBuffer _ _ _, y|) -> ()
| _ -> ()
// Everything here should be expressed in terms of the downview, which can be considered as a buffer of bytes
let rec write_taint
(i:nat)
(mem:interop_heap)
(ts:b8 -> GTot taint)
(b:b8{i <= DV.length (get_downview b.bsrc)})
(accu:MS.memTaint_t)
: GTot MS.memTaint_t
(decreases %[DV.length (get_downview b.bsrc) - i]) =
if i = DV.length (get_downview b.bsrc) then accu
else write_taint (i + 1) mem ts b (Map.upd accu (InteropHeap?.addrs mem b + i) (ts b))
let create_memtaint
(mem:interop_heap)
(ps:list b8)
(ts:b8 -> GTot taint) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val create_memtaint (mem: interop_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : GTot MS.memTaint_t | [] | Vale.Interop.Base.create_memtaint | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mem: Vale.Interop.Heap_s.interop_heap ->
ps: Prims.list Vale.Interop.Types.b8 ->
ts: (_: Vale.Interop.Types.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint)
-> Prims.GTot Vale.Arch.HeapTypes_s.memTaint_t | {
"end_col": 79,
"end_line": 468,
"start_col": 4,
"start_line": 468
} |
Prims.GTot | val mk_mem (args: list arg) (h: mem_roots args) : GTot interop_heap | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h | val mk_mem (args: list arg) (h: mem_roots args) : GTot interop_heap
let mk_mem (args: list arg) (h: mem_roots args) : GTot interop_heap = | false | null | false | liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.Interop.Base.mem_roots",
"Vale.Interop.Heap_s.mem_of_hs_roots",
"Vale.Interop.Base.args_b8",
"Prims.unit",
"Vale.Interop.Base.liveness_disjointness",
"Vale.Interop.Heap_s.interop_heap"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_mem (args: list arg) (h: mem_roots args) : GTot interop_heap | [] | Vale.Interop.Base.mk_mem | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg -> h: Vale.Interop.Base.mem_roots args
-> Prims.GTot Vale.Interop.Heap_s.interop_heap | {
"end_col": 34,
"end_line": 400,
"start_col": 2,
"start_line": 399
} |
Prims.GTot | val arg_loc (x: arg) : GTot B.loc | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none | val arg_loc (x: arg) : GTot B.loc
let arg_loc (x: arg) : GTot B.loc = | false | null | false | match x with
| (| TD_Buffer _ _ _ , x |) -> B.loc_buffer x
| (| TD_ImmBuffer _ _ _ , x |) -> B.loc_buffer x
| (| TD_Base _ , _ |) -> B.loc_none | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"sometrivial"
] | [
"Vale.Interop.Base.arg",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Buffer",
"LowStar.Monotonic.Buffer.loc_buffer",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Base.TD_ImmBuffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.TD_Base",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.loc"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__] | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arg_loc (x: arg) : GTot B.loc | [] | Vale.Interop.Base.arg_loc | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Interop.Base.arg -> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 36,
"end_line": 288,
"start_col": 4,
"start_line": 285
} |
FStar.Pervasives.Lemma | val liveness_disjointness (args: list arg) (h: mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\ list_live h (args_b8 args)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args | val liveness_disjointness (args: list arg) (h: mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\ list_live h (args_b8 args))
let liveness_disjointness (args: list arg) (h: mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\ list_live h (args_b8 args)) = | false | null | true | args_b8_disjoint_or_eq args;
args_b8_live h args | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.Interop.Base.mem_roots",
"Vale.Interop.Base.args_b8_live",
"Prims.unit",
"Vale.Interop.Base.args_b8_disjoint_or_eq",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Vale.Interop.Base.args_b8",
"Vale.Interop.Heap_s.list_live",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\ | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val liveness_disjointness (args: list arg) (h: mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\ list_live h (args_b8 args)) | [] | Vale.Interop.Base.liveness_disjointness | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg -> h: Vale.Interop.Base.mem_roots args
-> FStar.Pervasives.Lemma
(ensures
Vale.Interop.Heap_s.list_disjoint_or_eq (Vale.Interop.Base.args_b8 args) /\
Vale.Interop.Heap_s.list_live h (Vale.Interop.Base.args_b8 args)) | {
"end_col": 23,
"end_line": 396,
"start_col": 4,
"start_line": 395
} |
Prims.Tot | val default_v_of_typ (t: base_typ) : (base_typ_as_type t) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0 | val default_v_of_typ (t: base_typ) : (base_typ_as_type t)
let default_v_of_typ (t: base_typ) : (base_typ_as_type t) = | false | null | false | match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0 | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"FStar.UInt8.uint_to_t",
"FStar.UInt16.uint_to_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt64.uint_to_t",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Words_s.nat32",
"Vale.Interop.Types.base_typ_as_type"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= () | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val default_v_of_typ (t: base_typ) : (base_typ_as_type t) | [] | Vale.Interop.Base.default_v_of_typ | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Vale.Arch.HeapTypes_s.base_typ -> Vale.Interop.Types.base_typ_as_type t | {
"end_col": 56,
"end_line": 36,
"start_col": 59,
"start_line": 31
} |
FStar.Pervasives.Lemma | val mem_roots_p_modifies_none (args: list arg) (h0 h1: HS.mem)
: Lemma (requires mem_roots_p h0 args /\ B.modifies B.loc_none h0 h1)
(ensures mem_roots_p h1 args) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures
mem_roots_p h1 args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _, _ |) -> ()
| (| TD_Buffer _ _ _, x |)
| (| TD_ImmBuffer _ _ _, x |) -> assert (B.live h1 x) | val mem_roots_p_modifies_none (args: list arg) (h0 h1: HS.mem)
: Lemma (requires mem_roots_p h0 args /\ B.modifies B.loc_none h0 h1)
(ensures mem_roots_p h1 args)
let rec mem_roots_p_modifies_none (args: list arg) (h0 h1: HS.mem)
: Lemma (requires mem_roots_p h0 args /\ B.modifies B.loc_none h0 h1)
(ensures mem_roots_p h1 args) = | false | null | true | match args with
| [] -> ()
| hd :: tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _ , _ |) -> ()
| (| TD_Buffer _ _ _ , x |) | (| TD_ImmBuffer _ _ _ , x |) -> assert (B.live h1 x) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Base",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.TD_Buffer",
"Prims._assert",
"LowStar.Monotonic.Buffer.live",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Base.TD_ImmBuffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Prims.unit",
"Vale.Interop.Base.mem_roots_p_modifies_none",
"Vale.Interop.Base.all_live_cons",
"Prims.l_and",
"Vale.Interop.Base.mem_roots_p",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args
let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h
let mk_mem_injective (args:list arg) (h:mem_roots args)
: Lemma (hs_of_mem (mk_mem args h) == h /\
ptrs_of_mem (mk_mem args h) == args_b8 args)
= ()
let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mem_roots_p_modifies_none (args: list arg) (h0 h1: HS.mem)
: Lemma (requires mem_roots_p h0 args /\ B.modifies B.loc_none h0 h1)
(ensures mem_roots_p h1 args) | [
"recursion"
] | Vale.Interop.Base.mem_roots_p_modifies_none | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
args: Prims.list Vale.Interop.Base.arg ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
Vale.Interop.Base.mem_roots_p h0 args /\
LowStar.Monotonic.Buffer.modifies LowStar.Monotonic.Buffer.loc_none h0 h1)
(ensures Vale.Interop.Base.mem_roots_p h1 args) | {
"end_col": 59,
"end_line": 422,
"start_col": 4,
"start_line": 414
} |
Prims.Tot | val intro_dep_arrow_1 (a: td) (b: n_arrow [a] Type) (f: (x: td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f | val intro_dep_arrow_1 (a: td) (b: n_arrow [a] Type) (f: (x: td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
let intro_dep_arrow_1 (a: td) (b: n_arrow [a] Type) (f: (x: td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b = | false | null | false | f | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"total"
] | [
"Vale.Interop.Base.td",
"Vale.Interop.Base.n_arrow",
"Prims.Cons",
"Prims.Nil",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.elim_1",
"Vale.Interop.Base.n_dep_arrow"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x)) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_dep_arrow_1 (a: td) (b: n_arrow [a] Type) (f: (x: td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b | [] | Vale.Interop.Base.intro_dep_arrow_1 | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Vale.Interop.Base.td ->
b: Vale.Interop.Base.n_arrow [a] Type ->
f: (x: Vale.Interop.Base.td_as_type a -> Vale.Interop.Base.elim_1 b x)
-> Vale.Interop.Base.n_dep_arrow [a] b | {
"end_col": 5,
"end_line": 178,
"start_col": 4,
"start_line": 178
} |
FStar.Pervasives.Lemma | val args_b8_live (hs: HS.mem) (args: list arg {all_live hs args})
: Lemma (list_live hs (args_b8 args)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl) | val args_b8_live (hs: HS.mem) (args: list arg {all_live hs args})
: Lemma (list_live hs (args_b8 args))
let rec args_b8_live (hs: HS.mem) (args: list arg {all_live hs args})
: Lemma (list_live hs (args_b8 args)) = | false | null | true | match args with
| [] -> ()
| hd :: tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) -> assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _ , x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _ , x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.Interop.Base.all_live",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Base",
"Prims._assert",
"Prims.eq2",
"Vale.Interop.Types.b8",
"Vale.Interop.Base.args_b8",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.TD_Buffer",
"Prims.Cons",
"Vale.Interop.Types.Buffer",
"Prims.unit",
"LowStar.Monotonic.Buffer.live",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Base.TD_ImmBuffer",
"Vale.Interop.Base.imm_to_b8",
"LowStar.ImmutableBuffer.immutable_preorder",
"Vale.Interop.Base.args_b8_live",
"Vale.Interop.Base.live_arg",
"Vale.Interop.Base.all_live_cons",
"Prims.l_True",
"Prims.squash",
"Vale.Interop.Heap_s.list_live",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args}) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val args_b8_live (hs: HS.mem) (args: list arg {all_live hs args})
: Lemma (list_live hs (args_b8 args)) | [
"recursion"
] | Vale.Interop.Base.args_b8_live | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
hs: FStar.Monotonic.HyperStack.mem ->
args: Prims.list Vale.Interop.Base.arg {Vale.Interop.Base.all_live hs args}
-> FStar.Pervasives.Lemma
(ensures Vale.Interop.Heap_s.list_live hs (Vale.Interop.Base.args_b8 args)) | {
"end_col": 60,
"end_line": 390,
"start_col": 4,
"start_line": 375
} |
FStar.Pervasives.Lemma | val disjoint_or_eq_fresh (#t: _) (x: buf_t TUInt64 t) (args: list arg) (h0: HS.mem)
: Lemma (requires all_live h0 args /\ x `B.unused_in` h0)
(ensures BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec disjoint_or_eq_fresh
#t
(x:buf_t TUInt64 t)
(args:list arg)
(h0:HS.mem)
: Lemma
(requires
all_live h0 args /\
x `B.unused_in` h0)
(ensures
BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
disjoint_or_eq_fresh x tl h0;
match hd with
| (|TD_ImmBuffer _ _ _, y|) -> ()
| _ -> () | val disjoint_or_eq_fresh (#t: _) (x: buf_t TUInt64 t) (args: list arg) (h0: HS.mem)
: Lemma (requires all_live h0 args /\ x `B.unused_in` h0)
(ensures BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args)
let rec disjoint_or_eq_fresh #t (x: buf_t TUInt64 t) (args: list arg) (h0: HS.mem)
: Lemma (requires all_live h0 args /\ x `B.unused_in` h0)
(ensures BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args) = | false | null | true | match args with
| [] -> ()
| hd :: tl ->
all_live_cons hd tl h0;
disjoint_or_eq_fresh x tl h0;
match hd with
| (| TD_ImmBuffer _ _ _ , y |) -> ()
| _ -> () | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_ImmBuffer",
"Prims.dtuple2",
"Vale.Interop.Base.td",
"Prims.unit",
"Vale.Interop.Base.disjoint_or_eq_fresh",
"Vale.Interop.Base.all_live_cons",
"Prims.l_and",
"Vale.Interop.Base.all_live",
"LowStar.Monotonic.Buffer.unused_in",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Prims.squash",
"FStar.BigOps.big_and'",
"Vale.Interop.Base.disjoint_or_eq_1",
"Vale.Interop.Base.arg_of_sb",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl)
let rec args_b8_live (hs:HS.mem) (args:list arg{all_live hs args})
: Lemma (list_live hs (args_b8 args))
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl hs;
assert (live_arg hs hd);
assert (all_live hs tl);
args_b8_live hs tl;
match hd with
| (| TD_Base _ , _ |) ->
assert (args_b8 args == args_b8 tl)
| (| TD_Buffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == Buffer true x :: args_b8 tl)
| (| TD_ImmBuffer t _ _, x |) ->
assert (B.live hs x);
assert (args_b8 args == imm_to_b8 t x :: args_b8 tl)
let liveness_disjointness (args:list arg) (h:mem_roots args)
: Lemma (list_disjoint_or_eq (args_b8 args) /\
list_live h (args_b8 args))
= args_b8_disjoint_or_eq args;
args_b8_live h args
let mk_mem (args:list arg) (h:mem_roots args) : GTot interop_heap =
liveness_disjointness args h;
mem_of_hs_roots (args_b8 args) h
let mk_mem_injective (args:list arg) (h:mem_roots args)
: Lemma (hs_of_mem (mk_mem args h) == h /\
ptrs_of_mem (mk_mem args h) == args_b8 args)
= ()
let rec mem_roots_p_modifies_none (args:list arg) (h0:HS.mem) (h1:HS.mem)
: Lemma
(requires
mem_roots_p h0 args /\
B.modifies B.loc_none h0 h1)
(ensures
mem_roots_p h1 args)
= match args with
| [] -> ()
| hd::tl ->
all_live_cons hd tl h0;
mem_roots_p_modifies_none tl h0 h1;
match hd with
| (| TD_Base _, _ |) -> ()
| (| TD_Buffer _ _ _, x |)
| (| TD_ImmBuffer _ _ _, x |) -> assert (B.live h1 x)
[@__reduce__]
let arg_of_lb #src #t (x:buf_t src t) : arg = (| TD_Buffer src t default_bq, x |)
[@__reduce__]
let arg_of_sb #t (x:buf_t TUInt64 t) :arg = (| TD_Buffer TUInt64 t stack_bq, x |)
let rec disjoint_or_eq_fresh
#t
(x:buf_t TUInt64 t)
(args:list arg)
(h0:HS.mem)
: Lemma
(requires
all_live h0 args /\
x `B.unused_in` h0)
(ensures | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_or_eq_fresh (#t: _) (x: buf_t TUInt64 t) (args: list arg) (h0: HS.mem)
: Lemma (requires all_live h0 args /\ x `B.unused_in` h0)
(ensures BigOps.big_and' (disjoint_or_eq_1 (arg_of_sb x)) args) | [
"recursion"
] | Vale.Interop.Base.disjoint_or_eq_fresh | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
x: Vale.Interop.Base.buf_t Vale.Arch.HeapTypes_s.TUInt64 t ->
args: Prims.list Vale.Interop.Base.arg ->
h0: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires Vale.Interop.Base.all_live h0 args /\ LowStar.Monotonic.Buffer.unused_in x h0)
(ensures
FStar.BigOps.big_and' (Vale.Interop.Base.disjoint_or_eq_1 (Vale.Interop.Base.arg_of_sb x))
args) | {
"end_col": 15,
"end_line": 448,
"start_col": 4,
"start_line": 441
} |
FStar.Pervasives.Lemma | val args_b8_disjoint_or_eq (args: list arg)
: Lemma (requires (disjoint_or_eq args)) (ensures (list_disjoint_or_eq (args_b8 args))) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args)))
=
list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl) | val args_b8_disjoint_or_eq (args: list arg)
: Lemma (requires (disjoint_or_eq args)) (ensures (list_disjoint_or_eq (args_b8 args)))
let rec args_b8_disjoint_or_eq (args: list arg)
: Lemma (requires (disjoint_or_eq args)) (ensures (list_disjoint_or_eq (args_b8 args))) = | false | null | true | list_disjoint_or_eq_reveal ();
match args with
| [] -> ()
| hd :: tl ->
disjoint_or_eq_cons hd tl;
args_b8_disjoint_or_eq tl;
BigOps.big_and'_forall (disjoint_or_eq_1 hd) tl;
FStar.Classical.forall_intro (args_b8_mem tl) | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.Classical.forall_intro",
"Vale.Interop.Types.b8",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Base.args_b8",
"Prims.l_Exists",
"Prims.l_and",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Base",
"Prims.l_False",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.TD_Buffer",
"Prims.eq2",
"Vale.Interop.Base.mut_to_b8",
"Vale.Interop.Base.TD_ImmBuffer",
"Vale.Interop.Base.imm_to_b8",
"Prims.logical",
"Vale.Interop.Base.args_b8_mem",
"Prims.unit",
"FStar.BigOps.big_and'_forall",
"Vale.Interop.Base.disjoint_or_eq_1",
"Vale.Interop.Base.args_b8_disjoint_or_eq",
"Vale.Interop.Base.disjoint_or_eq_cons",
"Vale.Interop.Heap_s.list_disjoint_or_eq_reveal",
"Vale.Interop.Base.disjoint_or_eq",
"Prims.squash",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
let rec args_b8_disjoint_or_eq (args:list arg)
: Lemma
(requires (disjoint_or_eq args))
(ensures (list_disjoint_or_eq (args_b8 args))) | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val args_b8_disjoint_or_eq (args: list arg)
: Lemma (requires (disjoint_or_eq args)) (ensures (list_disjoint_or_eq (args_b8 args))) | [
"recursion"
] | Vale.Interop.Base.args_b8_disjoint_or_eq | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | args: Prims.list Vale.Interop.Base.arg
-> FStar.Pervasives.Lemma (requires Vale.Interop.Base.disjoint_or_eq args)
(ensures Vale.Interop.Heap_s.list_disjoint_or_eq (Vale.Interop.Base.args_b8 args)) | {
"end_col": 51,
"end_line": 371,
"start_col": 2,
"start_line": 364
} |
FStar.Pervasives.Lemma | val args_b8_mem (l: list arg) (y: b8)
: Lemma
(L.memP y (args_b8 l) <==>
(exists (a: arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _ , _ |) -> False
| (| TD_Buffer src _ _ , x |) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _ , x |) -> imm_to_b8 src x == y))) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Def.Prop_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)))
= let goal (l:list arg) (a:arg) =
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd::tl ->
match hd with
| (| TD_Base _, _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == mut_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q, x |) ->
let aux_1 ()
: Lemma (requires (y == imm_to_b8 bt x))
(ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 () | val args_b8_mem (l: list arg) (y: b8)
: Lemma
(L.memP y (args_b8 l) <==>
(exists (a: arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _ , _ |) -> False
| (| TD_Buffer src _ _ , x |) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _ , x |) -> imm_to_b8 src x == y)))
let rec args_b8_mem (l: list arg) (y: b8)
: Lemma
(L.memP y (args_b8 l) <==>
(exists (a: arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _ , _ |) -> False
| (| TD_Buffer src _ _ , x |) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _ , x |) -> imm_to_b8 src x == y))) = | false | null | true | let goal (l: list arg) (a: arg) =
L.memP a l /\
(match a with
| (| TD_Base _ , _ |) -> False
| (| TD_Buffer src _ _ , x |) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _ , x |) -> imm_to_b8 src x == y)
in
match l with
| [] -> ()
| hd :: tl ->
match hd with
| (| TD_Base _ , _ |) ->
args_b8_mem tl y;
assert ((exists a. goal tl a) ==> (exists a. goal l a))
| (| TD_Buffer bt _ q , x |) ->
let aux_1 () : Lemma (requires (y == mut_to_b8 bt x)) (ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (mut_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 ()
| (| TD_ImmBuffer bt _ q , x |) ->
let aux_1 () : Lemma (requires (y == imm_to_b8 bt x)) (ensures (exists a. goal l a)) =
FStar.Classical.exists_intro (goal l) hd
in
let aux_2 ()
: Lemma (requires (imm_to_b8 bt x =!= y))
(ensures (L.memP y (args_b8 l) <==> (exists a. goal l a))) =
args_b8_mem tl y
in
FStar.Classical.move_requires aux_1 ();
FStar.Classical.move_requires aux_2 () | {
"checked_file": "Vale.Interop.Base.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.BufferView.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Base.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.Interop.Types.b8",
"Vale.Interop.Base.valid_base_type",
"Vale.Interop.Base.td_as_type",
"Vale.Interop.Base.TD_Base",
"Prims._assert",
"Prims.l_imp",
"Prims.l_Exists",
"Prims.unit",
"Vale.Interop.Base.args_b8_mem",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.Interop.Base.TD_Buffer",
"FStar.Classical.move_requires",
"Prims.l_not",
"Prims.eq2",
"Vale.Interop.Base.mut_to_b8",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Base.args_b8",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.exists_intro",
"Vale.Interop.Base.TD_ImmBuffer",
"Vale.Interop.Base.imm_to_b8",
"Prims.logical",
"Prims.l_and",
"Prims.l_False",
"Prims.l_True"
] | [] | module Vale.Interop.Base
open Vale.Arch.HeapTypes_s
include Vale.Interop.Types
include Vale.Interop.Heap_s
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
include Vale.Arch.Heap
module BS = Vale.X64.Machine_Semantics_s
module BV = LowStar.BufferView
module HS = FStar.HyperStack
module MS = Vale.X64.Machine_s
module P = Vale.Def.Prop_s
module HS = FStar.HyperStack
module W = Vale.Def.Words_s
module L = FStar.List.Tot
open FStar.Mul
[@__reduce__]
let buf_t src t = b:B.buffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
[@__reduce__]
let ibuf_t src t = b:IB.ibuffer (base_typ_as_type src){(B.length b * view_n_unfold src) % view_n_unfold t = 0}
let lemma_seq_neq_intro (#a:Type) (s1:Seq.seq a) (s2:Seq.seq a)
: Lemma (requires (Seq.length s1 =!= Seq.length s2))
(ensures (~ (Seq.equal s1 s2)))
= ()
let default_v_of_typ (t:base_typ) : (base_typ_as_type t) = match t with
| TUInt8 -> UInt8.uint_to_t 0
| TUInt16 -> UInt16.uint_to_t 0
| TUInt32 -> UInt32.uint_to_t 0
| TUInt64 -> UInt64.uint_to_t 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #W.nat32 0 0 0 0
let imm_to_b8 (src:base_typ) (b:IB.ibuffer (base_typ_as_type src)) : GTot b8 =
Buffer false b
let mut_to_b8 (src:base_typ) (b:B.buffer (base_typ_as_type src)) : GTot b8 =
Buffer true b
[@__reduce__]
let coerce (x:'a{'a == 'b}) : 'b = x
////////////////////////////////////////////////////////////////////////////////
type buffer_qualifiers = {
modified:bool;
taint:taint;
strict_disjointness:bool
}
[@__reduce__]
let default_bq = {
modified = true;
taint = Secret;
strict_disjointness = false
}
[@__reduce__]
let stack_bq = {
modified = true;
taint = Public;
strict_disjointness = true
}
let valid_base_type = x:base_typ{x <> TUInt128}
//type descriptors
type td =
| TD_Base of valid_base_type
// The initial type of the buffer, and the final type we want in Vale
| TD_Buffer : base_typ -> base_typ -> buffer_qualifiers -> td
| TD_ImmBuffer : base_typ -> base_typ -> buffer_qualifiers -> td
unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%TD_Buffer?;
`%BS.Mkmachine_state?.ms_ok;
`%BS.Mkmachine_state?.ms_regs;
`%BS.Mkmachine_state?.ms_flags;
`%BS.Mkmachine_state?.ms_heap;
`%BS.Mkmachine_state?.ms_stack;
`%BS.Mkmachine_state?.ms_stackTaint;
`%BS.Mkmachine_state?.ms_trace;
`%FStar.FunctionalExtensionality.on_dom;
`%FStar.FunctionalExtensionality.on;
`%List.Tot.fold_right_gtot;
`%List.Tot.map_gtot;
`%List.Tot.length;
`%fst;
`%snd;
`%Mktuple2?._1;
`%Mktuple2?._2
];
primops;
simplify]
x
////////////////////////////////////////////////////////////////////////////////
#set-options "--initial_ifuel 1"
[@__reduce__]
let td_as_type : td -> Type =
function
| TD_Base bt -> base_typ_as_type bt
| TD_Buffer src bt _ -> buf_t src bt
| TD_ImmBuffer src bt _ -> ibuf_t src bt
let arg = t:td & td_as_type t
////////////////////////////////////////////////////////////////////////////////
// n_arrow: Arrows with a generic number of vale types as the domain
// and a result type `codom` that does not depend on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_arrow (dom:list td) (codom:Type) =
match dom with
| [] -> codom
| hd::tl -> td_as_type hd -> n_arrow tl codom
[@(unifier_hint_injective) (__reduce__)]
let arr (dom:Type) (codom:Type) = dom -> codom
[@__reduce__]
let elim_1 (#dom:list td{Cons? dom})
(#r:Type)
(f:n_arrow dom r)
: td_as_type (Cons?.hd dom) -> n_arrow (Cons?.tl dom) r =
f
[@__reduce__]
let elim_nil (#dom:list td{Nil? dom})
(#r:Type)
(f:n_arrow dom r)
: r =
f
[@__reduce__]
let intro_n_arrow_nil (a:Type) (x:a)
: n_arrow [] a
= x
[@__reduce__]
let intro_n_arrow_cons (hd:td) (b:Type) (tl:list td)
(x:td_as_type hd -> n_arrow tl b)
: n_arrow (hd::tl) b
= x
////////////////////////////////////////////////////////////////////////////////
// n_dep_arrow: Arrows with a generic number of vale types as the domain
// and a result type codom that depends on the domain
////////////////////////////////////////////////////////////////////////////////
[@(unifier_hint_injective) (__reduce__)]
let rec n_dep_arrow (dom:list td) (codom: n_arrow dom Type) =
match dom with
| [] -> codom
| hd::tl -> x:td_as_type hd -> n_dep_arrow tl (elim_1 codom x)
[@__reduce__]
let intro_dep_arrow_nil (b:Type)
(f:b)
: n_dep_arrow [] b
= f
[@__reduce__]
let intro_dep_arrow_1 (a:td)
(b:n_arrow [a] Type)
(f:(x:td_as_type a -> elim_1 b x))
: n_dep_arrow [a] b
= f
[@__reduce__]
let intro_dep_arrow_cons (hd:td)
(tl:list td)
(b: n_arrow (hd::tl) Type)
(f: (x:td_as_type hd -> n_dep_arrow tl (elim_1 b x)))
: n_dep_arrow (hd::tl) b
= f
[@__reduce__]
let elim_dep_arrow_nil (#codom:n_arrow [] Type)
(f:n_dep_arrow [] codom)
: elim_nil codom
= f
[@__reduce__]
let elim_dep_arrow_cons (hd:td)
(tl:list td)
(#codom:n_arrow (hd::tl) Type)
(f:n_dep_arrow (hd::tl) codom)
: x:td_as_type hd ->
n_dep_arrow tl (elim_1 codom x)
= f
//Just a small test function to see how these coercions work
let __test : n_dep_arrow [TD_Base TUInt8] (fun (x:UInt8.t) -> y:UInt8.t{x == y}) =
fun (x:UInt8.t) -> intro_dep_arrow_nil (y:UInt8.t{x == y}) x
////////////////////////////////////////////////////////////////////////////////
[@__reduce__]
let disjoint_not_eq
(#src1 #src2:base_typ)
(#rel1 #rrel1:MB.srel (base_typ_as_type src1))
(#rel2 #rrel2:MB.srel (base_typ_as_type src2))
(x:MB.mbuffer (base_typ_as_type src1) rel1 rrel1)
(y:MB.mbuffer (base_typ_as_type src2) rel2 rrel2) =
B.loc_disjoint (B.loc_buffer x) (B.loc_buffer y) /\
~ (src1 == src2 /\ rel1 == rel2 /\ rrel1 == rrel2 /\ x == y)
[@__reduce__]
let disjoint_or_eq_1 (a:arg) (b:arg) =
match a, b with
| (| TD_Buffer _ _ {strict_disjointness=true}, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_ImmBuffer _ _ {strict_disjointness=true}, xb |), (| TD_ImmBuffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_Buffer _ _ {strict_disjointness=true}, yb |)
| (| TD_ImmBuffer _ _ _, xb |), (| TD_ImmBuffer _ _ {strict_disjointness=true}, yb |)
// An immutable buffer and a trivial buffer should not be equal
| (| TD_ImmBuffer _ _ _, xb |), (| TD_Buffer _ _ _, yb |)
| (| TD_Buffer _ _ _, xb |), (| TD_ImmBuffer _ _ _, yb |) ->
disjoint_not_eq xb yb
| (| TD_Buffer srcx tx {taint=tntx}, xb |), (| TD_Buffer srcy ty {taint=tnty}, yb |)
| (| TD_ImmBuffer srcx tx {taint=tntx}, xb |), (| TD_ImmBuffer srcy ty {taint=tnty}, yb |) ->
disjoint_not_eq xb yb \/ (xb === yb /\ tntx == tnty /\ tx == ty /\ srcx == srcy)
| _ -> True
[@__reduce__]
let disjoint_or_eq (l:list arg) =
BigOps.pairwise_and' disjoint_or_eq_1 l
[@__reduce__]
let live_arg (h:HS.mem) (x:arg) =
match x with
| (|TD_Buffer _ _ _, x|)
| (|TD_ImmBuffer _ _ _, x|) -> B.live h x
| (|TD_Base _, _ |) -> True
[@__reduce__]
let all_live (h:HS.mem) (bs:list arg) =
BigOps.big_and' (live_arg h) bs
[@__reduce__]
let mem_roots_p (h0:HS.mem) (args:list arg) =
disjoint_or_eq args /\
all_live h0 args
[@__reduce__]
let mem_roots (args:list arg) =
h0:HS.mem{ mem_roots_p h0 args }
[@__reduce__]
let args_b8 (args:list arg) : GTot (list b8) =
let maybe_cons_buffer (x:arg) (args:list b8) : GTot (list b8) =
match x with
| (|TD_Buffer src _ _, x|) -> mut_to_b8 src x :: args
| (|TD_ImmBuffer src _ _, x|) -> imm_to_b8 src x :: args
| (|TD_Base _, _ |) -> args
in
List.Tot.fold_right_gtot args maybe_cons_buffer []
[@__reduce__]
let modified_arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_buffer x
| _ -> B.loc_none
[@__reduce__]
let loc_modified_args (args:list arg) : GTot B.loc =
let maybe_union_loc (x:arg) l =
match x with
| (|TD_Buffer _ _ {modified=true}, x|) -> B.loc_union (B.loc_buffer x) l
| _ -> l
in
List.Tot.fold_right_gtot args maybe_union_loc B.loc_none
[@__reduce__]
let arg_loc (x:arg) : GTot B.loc =
match x with
| (|TD_Buffer _ _ _, x|) -> B.loc_buffer x
| (|TD_ImmBuffer _ _ _, x|) -> B.loc_buffer x
| (|TD_Base _, _|) -> B.loc_none
[@__reduce__]
let loc_all_args (args:list arg) : GTot B.loc =
let l = List.Tot.map_gtot arg_loc args in
List.Tot.fold_right_gtot l B.loc_union B.loc_none
let all_live_cons (hd:arg) (tl:list arg) (h0:HS.mem)
: Lemma
(all_live h0 (hd :: tl) <==> (live_arg h0 hd /\ all_live h0 tl))
= ()
let disjoint_or_eq_def (l:list arg)
: Lemma (disjoint_or_eq l == BigOps.pairwise_and' disjoint_or_eq_1 l)
= ()
let disjoint_or_eq_cons (hd:arg) (tl:list arg)
: Lemma (disjoint_or_eq (hd::tl) <==> (BigOps.big_and' (disjoint_or_eq_1 hd) tl /\ disjoint_or_eq tl))
= BigOps.pairwise_and'_cons disjoint_or_eq_1 hd tl
#set-options "--initial_ifuel 2 --max_fuel 2"
let rec args_b8_mem (l:list arg) (y:b8)
: Lemma (L.memP y (args_b8 l) <==>
(exists (a:arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _, _|) -> False
| (| TD_Buffer src _ _, x|) -> mut_to_b8 src x == y | false | false | Vale.Interop.Base.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val args_b8_mem (l: list arg) (y: b8)
: Lemma
(L.memP y (args_b8 l) <==>
(exists (a: arg). {:pattern L.memP a l}
L.memP a l /\
(match a with
| (| TD_Base _ , _ |) -> False
| (| TD_Buffer src _ _ , x |) -> mut_to_b8 src x == y
| (| TD_ImmBuffer src _ _ , x |) -> imm_to_b8 src x == y))) | [
"recursion"
] | Vale.Interop.Base.args_b8_mem | {
"file_name": "vale/specs/interop/Vale.Interop.Base.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | l: Prims.list Vale.Interop.Base.arg -> y: Vale.Interop.Types.b8
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.memP y (Vale.Interop.Base.args_b8 l) <==>
(exists (a: Vale.Interop.Base.arg). {:pattern FStar.List.Tot.Base.memP a l}
FStar.List.Tot.Base.memP a l /\
(match a with
| Prims.Mkdtuple2 #_ #_ (Vale.Interop.Base.TD_Base _) _ -> Prims.l_False
| Prims.Mkdtuple2 #_ #_ (Vale.Interop.Base.TD_Buffer src _ _) x ->
Vale.Interop.Base.mut_to_b8 src x == y
| Prims.Mkdtuple2 #_ #_ (Vale.Interop.Base.TD_ImmBuffer src _ _) x ->
Vale.Interop.Base.imm_to_b8 src x == y))) | {
"end_col": 46,
"end_line": 357,
"start_col": 3,
"start_line": 318
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.