file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Binding.fst | Binding.initial_global_env | val initial_global_env (_:unit) : ML global_env | val initial_global_env (_:unit) : ML global_env | let initial_global_env () =
let cfg = Deps.get_config () in
let e =
{
ge_h = H.create 10;
ge_out_t = H.create 10;
ge_extern_t = H.create 10;
ge_extern_fn = H.create 10;
ge_probe_fn = H.create 10;
ge_cfg = cfg
}
in
let nullary_decl i =
let td_name =
{ typedef_name = i; typedef_abbrev = i; typedef_ptr_abbrev = i; typedef_attributes = [] }
in
mk_decl (Record td_name [] None []) dummy_range [] true
in
let _type_names =
[
("unit",
{
may_fail = false;
integral = None;
bit_order = None;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some false
});
("Bool",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT8",
{
may_fail = true;
integral = Some UInt8;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT16",
{
may_fail = true;
integral = Some UInt16;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT32",
{
may_fail = true;
integral = Some UInt32;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT64",
{
may_fail = true;
integral = Some UInt64;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT8BE",
{
may_fail = true;
integral = Some UInt8;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT16BE",
{
may_fail = true;
integral = Some UInt16;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT32BE",
{
may_fail = true;
integral = Some UInt32;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT64BE",
{
may_fail = true;
integral = Some UInt64;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("field_id",
{
may_fail = true;
integral = Some UInt32;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("all_bytes",
{
may_fail = false;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindConsumesAll;
parser_kind_nz = Some false
});
("all_zeros",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindConsumesAll;
parser_kind_nz = Some false
});
("PUINT8",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("EVERPARSE_COPY_BUFFER_T",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
] |>
List.iter (fun (i, attrs) ->
let i = with_dummy_range (to_ident' i) in
add_global e i (nullary_decl i) (Inl attrs))
in
let _operators =
[
("is_range_okay",
{
macro_arguments_t = [tuint32; tuint32; tuint32];
macro_result_t = tbool;
macro_defn_t = None
})
] |>
List.iter (fun (i, d) ->
let i = with_dummy_range (to_ident' i) in
add_global e i (nullary_decl i) (Inr d))
in
let _void =
let void_ident = with_dummy_range (to_ident' "void") in
add_extern_type e
void_ident
(mk_decl (ExternType
({
typedef_name = void_ident;
typedef_abbrev = void_ident;
typedef_ptr_abbrev = void_ident;
typedef_attributes = []
}))
dummy_range
[]
false)
in
let _ =
match cfg with
| None -> ()
| Some (cfg, module_name) ->
List.iter (fun flag ->
let ms = nullary_macro tbool None in
let i = with_dummy_range ({ to_ident' flag with modul_name = Some module_name }) in
let d = mk_decl (ExternFn i tbool []) dummy_range [] false in
add_global e i d (Inr ms))
cfg.compile_time_flags.flags
in
e | {
"file_name": "src/3d/Binding.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 2019,
"start_col": 0,
"start_line": 1820
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Binding
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
include GlobalEnv
/// Maps locally bound names, i.e., a field name to its type
/// -- the bool signifies that this identifier has been used, and is
/// therefore marked as a dependent field
///
/// The modul_name in these ident' must be None -- TODO: add a refinement?
let local_env = H.t ident' (ident' & typ & bool)
/// `env` includes both a global and local env, together with a
/// binding for the `this` variable (bound to the name of a type) in
/// the current scope
noeq
type env = {
this: option ident;
locals: local_env;
globals: global_env;
}
let mk_env (g:global_env) =
{ this = None;
locals = H.create 10;
globals = g }
let copy_env (e:env) =
let locals = H.create 10 in
H.iter (fun k v -> H.insert locals k v) e.locals;
{
this = e.this;
globals = e.globals;
locals = locals
}
#push-options "--warn_error -272" //intentional top-level effect
let env_of_global_env
: global_env -> env
= let locals = H.create 1 in
fun g -> { this = None; locals; globals = g }
#pop-options
let global_env_of_env e = e.globals
let params_of_decl (d:decl) : list param =
match d.d_decl.v with
| ModuleAbbrev _ _
| Define _ _ _
| TypeAbbrev _ _
| Enum _ _ _ -> []
| Record _ params _ _
| CaseType _ params _ -> params
| OutputType _ -> []
| ExternType _ -> []
| ExternFn _ _ ps -> ps
| ExternProbe _ -> []
let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) =
match H.try_find e i.v with
| Some j ->
let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in
error msg i.range
| _ -> ()
let typedef_names (d:decl) : option typedef_names =
match d.d_decl.v with
| Record td _ _ _
| CaseType td _ _ -> Some td
| _ -> None
let format_identifier (e:env) (i:ident) : ML ident =
let j =
match String.list_of_string i.v.name with
| [] ->
failwith "Impossible: empty identifier"
| c0::cs ->
if FStar.Char.lowercase c0 = c0
then i //it starts with a lowercase symbol; that's ok
else //otherwise, add an underscore
{i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}}
in
match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with
| None, None -> j
| _ ->
let msg = Printf.sprintf
"This name (%s) starts will clash with another name in scope (%s) as it is translated. \
Please rename it"
(ident_to_string i) (ident_to_string j) in
error msg i.range
let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit =
let insert k v = H.insert e.ge_h k v in
check_shadow e.ge_h i d.d_decl.range;
let env = mk_env e in
let i' = format_identifier env i in
insert i.v (d, t);
insert i'.v (d, t);
match typedef_names d with
| None -> ()
| Some td ->
if td.typedef_abbrev.v <> i.v
then begin
check_shadow e.ge_h td.typedef_abbrev d.d_decl.range;
let abbrev = format_identifier env td.typedef_abbrev in
insert td.typedef_abbrev.v (d, t);
insert abbrev.v (d, t)
end
let add_local (e:env) (i:ident) (t:typ) : ML unit =
check_shadow e.globals.ge_h i t.range;
check_shadow e.locals i t.range;
let i' = format_identifier e i in
H.insert e.locals i.v (i'.v, t, false);
H.insert e.locals i'.v (i'.v, t, false)
let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) =
match H.try_find e.locals i.v with
| Some (_, t, true) ->
Some (Inl t)
| Some (j, t, false) -> //mark it as used
H.remove e.locals i.v;
H.insert e.locals i.v (j, t, true);
Some (Inl t)
| None ->
match H.try_find e.globals.ge_h i.v with
| Some d -> Some (Inr d)
| None -> None
let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) =
match try_lookup e i with
| None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
| Some v -> v
let remove_local (e:env) (i:ident) : ML unit =
match H.try_find e.locals i.v with
| Some (j, _, _) ->
H.remove e.locals i.v;
H.remove e.locals j
| _ -> ()
let resolve_record_case_output_extern_type_name (env:env) (i:ident) =
match H.try_find (global_env_of_env env).ge_out_t i.v with
| Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev
| _ ->
(match H.try_find (global_env_of_env env).ge_extern_t i.v with
| Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev
| _ ->
(match lookup env i with
| Inr ({d_decl={v=Record names _ _ _}}, _)
| Inr ({d_decl={v=CaseType names _ _}}, _) ->
names.typedef_name
| _ -> i))
let lookup_expr_name (e:env) (i:ident) : ML typ =
match lookup e i with
| Inl t -> t
| Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t
| Inr _ ->
error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
let lookup_macro_name (e:env) (i:ident) : ML macro_signature =
match lookup e i with
| Inr (_, Inr m) -> m
| _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
let lookup_macro_definition (e:env) (i:ident) =
try
let m = lookup_macro_name e i in
m.macro_defn_t
with
| _ -> None
let try_lookup_enum_cases (e:env) (i:ident)
: ML (option (list ident & typ))
= match lookup e i with
| Inr ({d_decl={v=Enum t _ tags}}, _) ->
Some (Desugar.check_desugared_enum_cases tags, t)
| _ -> None
let lookup_enum_cases (e:env) (i:ident)
: ML (list ident & typ)
= match try_lookup_enum_cases e i with
| Some (tags, t) -> tags, t
| _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
let is_enum (e:env) (t:typ) =
match t.v with
| Type_app i KindSpec [] ->
Some? (try_lookup_enum_cases e i)
| _ -> false
let is_used (e:env) (i:ident) : ML bool =
match H.try_find e.locals i.v with
| Some (_, t, b) -> b
| _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
let type_of_integer_type = function
| UInt8 -> tuint8
| UInt16 -> tuint16
| UInt32 -> tuint32
| UInt64 -> tuint64
let check_integer_bounds t i =
match t with
| UInt8 -> FStar.UInt.fits i 8
| UInt16 -> FStar.UInt.fits i 16
| UInt32 -> FStar.UInt.fits i 32
| UInt64 -> FStar.UInt.fits i 64
let type_of_constant rng (c:constant) : ML typ =
match c with
| Unit -> tunit
| Int tag i ->
if check_integer_bounds tag i
then type_of_integer_type tag
else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng
| XInt tag _ -> //bounds checked by the syntax
type_of_integer_type tag
| Bool _ -> tbool
let parser_may_fail (env:env) (t:typ) : ML bool =
match t.v with
| Pointer _ -> true
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> attrs.may_fail
| _ -> false
let typ_is_integral env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> Some? attrs.integral
| _ -> false
let tag_of_integral_typ env (t:typ) : ML (option _) =
match t.v with
| Pointer _ -> None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral
| _ -> None
let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) =
match t.v with
| Pointer _ -> None, None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order
| _ -> None, None
let has_reader (env:global_env) (id:ident) : ML bool =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.has_reader
| _ -> false
let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.parser_kind_nz
| _ -> None
let parser_weak_kind (env:global_env) (id:ident) : ML (option _) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> Some attrs.parser_weak_kind
| _ -> None
let rec typ_weak_kind env (t:typ) : ML (option weak_kind) =
match t.v with
| Pointer _ -> typ_weak_kind env tuint64
| Type_app hd _ _ -> parser_weak_kind env.globals hd
let typ_has_reader env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
has_reader env.globals hd
let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match try_lookup env hd with
| Some (Inr (d, _)) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_only env t
| _ -> t
end
| _ -> t
end
| _ -> t
let update_typ_abbrev (env:env) (i:ident) (t:typ)
: ML unit
= match H.try_find env.globals.ge_h i.v with
| Some (d, ms) ->
let d_decl =
match d.d_decl.v with
| TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i }
| _ -> failwith "Expected a type abbreviation"
in
let d = {d with d_decl = d_decl } in
let entry = (d, ms) in
H.insert env.globals.ge_h i.v entry
| _ ->
failwith "Type abbreviation not found"
let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match lookup env hd with
| Inr (d, _) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t
| Enum t _ _ -> unfold_typ_abbrev_and_enum env t
| _ -> t
end
| _ -> t
end
| _ -> t
let size_of_integral_typ (env:env) (t:typ) r
: ML int
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_of_integral_typ env t with
| None -> failwith "Impossible"
| Some UInt8 -> 1
| Some UInt16 -> 2
| Some UInt32 -> 4
| Some UInt64 -> 8
let bit_order_of_integral_typ (env:env) (t:typ) r
: ML bitfield_bit_order
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_and_bit_order_of_integral_typ env t with
| _, None -> failwith "Impossible"
| _, Some order -> order
let eq_typ env t1 t2 =
if Ast.eq_typ t1 t2 then true
else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
let eq_typs env ts =
List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
let cast e t t' = { e with v = App (Cast (Some t) t') [e] }
let try_cast_integer env et to : ML (option expr) =
let e, from = et in
let i_to = typ_is_integral env to in
let i_from = typ_is_integral env from in
if i_from && i_to
then
let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in
let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in
if i_from = i_to
then Some e
else if integer_type_leq i_from i_to
then Some (cast e i_from i_to)
else None
else None
let _or_ b1 b2 = b1 || b2
let _and_ b1 b2 = b1 && b2
let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))=
let e1, t1 = e1 in
let e2, t2 = e2 in
let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)"
i
(print_expr e1)
(print_typ t1)
(print_expr e2)
(print_typ t2))) in
try
let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in
if not (typ_is_integral env t1 `_and_`
typ_is_integral env t2)
then fail 1;
let tt1 = typ_as_integer_type t1 in
let tt2 = typ_as_integer_type t2 in
let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in
let e1, e2, t =
if integer_type_leq tt1 tt2
then cast e1 tt1 tt2,
e2,
t2
else if integer_type_leq tt2 tt1
then e1,
cast e2 tt2 tt1,
t1
else fail 0
in
// FStar.IO.print_string
// (Printf.sprintf "Retyped to (%s, %s, %s)\n"
// (print_expr e1)
// (print_expr e2)
// (print_typ t));
Some (e1, e2, t)
with
| Error msg ->
FStar.IO.print_string msg;
None
| _ -> None
(*
* Add output type to the environment
*
* TODO: check_shadow
*)
let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_out_t i d in
insert i.v;
let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in
insert td_abbrev.v
(*
* Add extern type to the environment
*
* TODO: check shadow
*)
let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_extern_t i d in
insert i.v;
let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in
insert td_abbrev.v
(*
* Add extern probe function to the environment
*
* TODO: check shadow
*)
let add_extern_probe (ge:global_env) (i:ident) (d:decl{ExternProbe? d.d_decl.v}) : ML unit =
H.insert ge.ge_probe_fn i.v d
(*
* Add extern function to the environment
*
* TODO: check shadow
*)
let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit =
H.insert ge.ge_extern_fn i.v d
let lookup_output_type (ge:global_env) (i:ident) : ML out_typ =
match H.try_find ge.ge_out_t i.v with
| Some ({d_decl={v=OutputType out_t}}) -> out_t
| _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range
(*
* Returns the type of the field, with optional bitwidth if the field is a bitfield
*)
let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) =
let out_t = lookup_output_type ge i in
let rec find (flds:list out_field) : (option (typ & option int)) =
match flds with
| [] -> None
| (Out_field_named f' t n)::tl ->
if eq_idents f f' then Some (t, n)
else find tl
| (Out_field_anon l _)::tl ->
(match find l with
| None -> find tl
| Some t -> Some t) in
match find out_t.out_typ_fields with
| Some t -> t
| None ->
error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range
let lookup_extern_type (ge:global_env) (i:ident) : ML unit =
match H.try_find ge.ge_extern_t i.v with
| Some ({d_decl={v=ExternType _}}) -> ()
| _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) =
match H.try_find ge.ge_extern_fn f.v with
| Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps
| _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
let check_output_type (ge:global_env) (t:typ) : ML ident =
let err () : ML ident =
error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in
match t.v with
| Type_app i KindOutput [] -> i
| _ -> err ()
/// Populated the output expression metadata
///
/// We enforce that the spec cannot take address of output type bitfields
let rec check_out_expr (env:env) (oe0:out_expr)
: ML (oe:out_expr{Some? oe.out_expr_meta}) =
match oe0.out_expr_node.v with
| OE_id i ->
let t = lookup_expr_name env i in
{oe0 with
out_expr_meta = Some ({
out_expr_base_t = t;
out_expr_t = t;
out_expr_bit_width = None})}
| OE_star oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_star oe};
out_expr_meta=Some ({ out_expr_base_t = oe_bt;
out_expr_t = t;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_addrof oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_addrof oe};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
| OE_deref oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
let i = check_output_type (global_env_of_env env) t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_deref oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_dot oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
let i = check_output_type (global_env_of_env env) oe_t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_dot oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
let range_of_typ_param (p:typ_param) = match p with
| Inl e -> e.range
| Inr p -> p.out_expr_node.range
#push-options "--z3rlimit_factor 4"
let rec check_typ (pointer_ok:bool) (env:env) (t:typ)
: ML typ
= match t.v with
| Pointer t0 ->
if pointer_ok
then { t with v = Pointer (check_typ pointer_ok env t0) }
else error (Printf.sprintf "Pointer types are not permissible here; got %s" (print_typ t)) t.range
| Type_app s KindSpec ps ->
(match lookup env s with
| Inl _ ->
error (Printf.sprintf "%s is not a type" (ident_to_string s)) s.range
| Inr (d, _) ->
let params = params_of_decl d in
if List.length params <> List.length ps
then error (Printf.sprintf "Not enough arguments to %s" (ident_to_string s)) s.range;
let ps =
List.map2 (fun (t, _, _) p ->
let p, t' = check_typ_param env p in
if not (eq_typ env t t')
then begin
match p with
| Inl e -> (match try_cast_integer env (e, t') t with
| Some e -> Inl e
| _ -> error "Argument type mismatch after trying integer cast" (range_of_typ_param p))
| _ ->
error (Printf.sprintf
"Argument type mismatch (%s vs %s)"
(Ast.print_typ t) (Ast.print_typ t')) (range_of_typ_param p)
end
else p)
params
ps
in
{t with v = Type_app s KindSpec ps})
| Type_app i KindExtern args ->
if List.length args <> 0
then error (Printf.sprintf "Cannot apply the extern type %s" (ident_to_string i)) i.range
else t
| Type_app _ KindOutput _ ->
error "Impossible, check_typ is not supposed to typecheck output types!" t.range
and check_ident (env:env) (i:ident)
: ML (ident & typ)
= let t = lookup_expr_name env i in
i, t
and check_expr (env:env) (e:expr)
: ML (expr & typ)
= let w e' = with_range e' e.range in
let arith_op_t op t : ML Ast.op =
let t = tag_of_integral_typ env t in
match op with
| Plus _ -> Plus t
| Minus _ -> Minus t
| Mul _ -> Mul t
| Division _ -> Division t
| Remainder _ -> Remainder t
| BitwiseNot _ -> BitwiseNot t
| BitwiseAnd _ -> BitwiseAnd t
| BitwiseOr _ -> BitwiseOr t
| BitwiseXor _ -> BitwiseXor t
| ShiftLeft _ -> ShiftLeft t
| ShiftRight _ -> ShiftRight t
| LE _ -> LE t
| LT _ -> LT t
| GE _ -> GE t
| GT _ -> GT t
| _ -> op
in
match e.v with
| Constant c ->
e, type_of_constant e.range c
| Identifier i ->
let i, t = check_ident env i in
{ e with v = Identifier i }, t
| Static _ ->
failwith "Static expressions should have been desugared already"
| This ->
error "`this` is not a valid expression" e.range
| App (Cast _ to) [n] ->
let n, from = check_expr env n in
begin
if not (typ_is_integral env from)
then error (Printf.sprintf "Casts are only supported on integral types; %s is not integral"
(print_typ from)) e.range
else match from.v with
| Type_app i KindSpec _ ->
let from_t = as_integer_typ i in
// if integer_type_lub to from_t <> to
// then error (Printf.sprintf "Only widening casts are supported; casting %s to %s loses precision"
// (print_typ from)
// (print_integer_type to))
// e.range
// else
let e = {e with v = App (Cast (Some from_t) to) [n]} in
let t = type_of_integer_type to in
Options.debug_print_string
(Printf.sprintf "--------------- %s has type %s\n" (print_expr e) (print_typ t));
e, t
| _ -> failwith "Impossible: must be an integral type"
end
| App SizeOf [{v=This;range=r}] ->
let e =
match env.this with
| None ->
error "`this` is not in scope" r
| Some i ->
with_range (App SizeOf [with_range (Identifier i) r]) e.range
in
e, tuint32
| App SizeOf [{v=Identifier i;range=r}] ->
begin
match lookup env i with
| Inr ({d_decl={v=Enum _ _ _}}, _)
| Inr ({d_decl={v=Record _ _ _ _ }}, _)
| Inr ({d_decl={v=CaseType _ _ _}}, _)
| Inr (_, Inl _) -> //has decl-attributes
e, tuint32
| _ ->
error "`sizeof` applied to a non-sized-typed" r
end
| App (Ext s) es ->
//TODO: AR: not sure about this Ext node
let m = lookup_macro_name env (with_range (to_ident' s) e.range) in
let n_formals = List.length m.macro_arguments_t in
let n_actuals = List.length es in
if n_formals <> n_actuals
then error (Printf.sprintf "%s expects %d arguments; got %d" s n_formals n_actuals) e.range;
let check_arg e t : ML expr =
let e, t' = check_expr env e in
if not (eq_typ env t t')
then error
(Printf.sprintf
"%s expected argument of type %s; \
got argument %s of type %s"
s (print_typ t) (print_expr e) (print_typ t))
e.range;
e
in
let es = List.map2 check_arg es m.macro_arguments_t in
with_range (App (Ext s) es) e.range,
m.macro_result_t
| App op es ->
let ets = List.map (check_expr env) es in
match ets with
| [(e1, t1)] ->
begin
match op with
| Not ->
if not (eq_typ env t1 tbool)
then error "Expected bool" e1.range;
w (App Not [e1]), t1
| BitwiseNot _ ->
if typ_is_integral env t1
then w (App (arith_op_t op t1) [e1]), t1
else error (Printf.sprintf "Bitwise negation is only available on integral types; got %s"
(print_typ t1))
e1.range
| _ ->
error "Not a unary op" e1.range
end
| [(e1,t1);(e2,t2)] ->
begin
match op with
| Eq
| Neq ->
if not (eq_typ env t1 t2)
then
begin
let err #a () : ML a =
error
(Printf.sprintf "Equality on unequal types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range
in
let it1 = typ_is_integral env t1 in
let it2 = typ_is_integral env t2 in
if it1 && it2
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App op [e1; e2]), tbool
| _ -> err ()
else err ()
end
else
w (App op [e1; e2]), tbool
| And
| Or ->
if not (eq_typs env [(t1,tbool); (t2,tbool)])
then error "Binary boolean op on non booleans" e.range;
w (App op [e1; e2]), tbool
| ShiftLeft _
| ShiftRight _ ->
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Bit shifts are only permissible on integral types: got %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
begin
match try_cast_integer env (e2, t2) tuint32 with
| None ->
error (Printf.sprintf "Bit shift offset is too large: got type %s"
(print_typ t2))
e2.range
| Some e2 ->
w (App (arith_op_t op t1) [e1; e2]), t1
end
| Plus _
| Minus _
| Mul _
| Division _
| Remainder _
| LT _
| GT _
| LE _
| GE _
| BitwiseAnd _
| BitwiseOr _
| BitwiseXor _ ->
let result_typ t =
match op with
| LT _ | GT _ | LE _ | GE _ -> tbool
| _ -> t
in
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Binary integer op on non-integral types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
if not (eq_typs env [(t1,t2)])
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) ->
w (App (arith_op_t op t) [e1; e2]), result_typ t
| _ ->
error (Printf.sprintf "Binary integer operator (%s) on non-equal types: %s and %s"
(print_expr e)
(print_typ t1)
(print_typ t2))
e.range
else w (App (arith_op_t op t1) [e1; e2]), result_typ t1
| _ ->
error "Not a binary op" e.range
end
| [(e1, t1); (e2, t2); (e3, t3)] ->
begin
match op with
| IfThenElse ->
if not (eq_typ env t1 tbool)
then error (Printf.sprintf "If-then-else expects a boolean guard, got %s" (print_typ t1))
e1.range;
if not (eq_typ env t2 t3)
then match try_retype_arith_exprs env (e2, t2) (e3, t3) e.range with
| Some (e2, e3, t) ->
w (App IfThenElse [e1;e2;e3]), t
| None ->
error (Printf.sprintf "then- and else-branch do not have the same type: got %s and %s"
(print_typ t2)
(print_typ t3))
e.range
else
w (App IfThenElse [e1;e2;e3]), t2
| BitFieldOf n order ->
let base_size = size_of_integral_typ env t1 e1.range in
let size = 8 * base_size in
if n <> size
then error
(Printf.sprintf "BitFieldOf size %d is not equal to %d, i.e., the bit size %s"
n size (print_expr e1))
e1.range;
begin
match e2.v, e3.v with
| Constant (Int UInt32 from), (Constant (Int UInt32 to)) ->
if not
(from <= size
&& from <= to
&& to <= size)
then error "bitfield-of expresssions is out of bounds" e.range;
w (App (BitFieldOf n order) [e1; e2; e3]), t1
| _ ->
error "bitfield-of with non-32-bit-consant indices" e.range
end
| _ ->
error "Unexpected arity" e.range
end
| _ -> error "Unexpected arity" e.range
and check_typ_param (env:env) (p:typ_param) : ML (typ_param & typ) =
match p with
| Inl e ->
let e, t = check_expr env e in
Inl e, t
| Inr o ->
let o = check_out_expr env o in
let { out_expr_t = t;
out_expr_bit_width = bopt } = Some?.v o.out_expr_meta in
(match bopt with
| None ->
Inr o, t
| _ ->
error ("Type parameter cannot be a bitfield") (range_of_typ_param p))
#pop-options
#push-options "--z3rlimit_factor 3"
let rec check_field_action (env:env) (f:atomic_field) (a:action)
: ML (action & typ)
= let check_atomic_action env (r:range) (a:atomic_action)
: ML (atomic_action & typ)
= match a with
| Action_return e ->
let e, t = check_expr env e in
Action_return e, t
| Action_abort ->
Action_abort, tunit
| Action_field_pos_64 ->
Action_field_pos_64, tuint64
| Action_field_pos_32 ->
Action_field_pos_32, tuint32
| Action_field_ptr ->
Action_field_ptr, puint8
| Action_field_ptr_after e write_to ->
let e, t = check_expr env e in
if not (eq_typ env t tuint64)
then
error (Printf.sprintf "Argument type mismatch, expected %s whereas %s has type %s"
(Ast.print_typ tuint64)
(Ast.print_expr e)
(Ast.print_typ t)) e.range
else
let write_to = check_out_expr env write_to in
let { out_expr_t = et } = Some?.v write_to.out_expr_meta in
if not (eq_typ env et puint8)
then
error (Printf.sprintf "Pointee type mismatch, expected %s whereas %s points to %s"
(Ast.print_typ puint8)
(Ast.print_out_expr write_to)
(Ast.print_typ et)) write_to.out_expr_node.range
else
Action_field_ptr_after e write_to, tbool
| Action_deref i ->
let t = lookup_expr_name env i in
begin
match t.v with
| Pointer t -> Action_deref i, t
| _ -> error "Dereferencing a non-pointer" i.range
end
| Action_assignment lhs rhs ->
let lhs = check_out_expr env lhs in
let { out_expr_t = t } = Some?.v lhs.out_expr_meta in
let rhs, t' = check_expr env rhs in
let def_ret = Action_assignment lhs rhs, tunit in
if not (eq_typ env t t')
then begin
match try_cast_integer env (rhs, t') t with
| Some rhs ->
Action_assignment lhs rhs, tunit
| None ->
warning (Printf.sprintf
"Assigning to %s of type %s a value of incompatible type %s"
(print_out_expr lhs)
(print_typ t)
(print_typ t'))
rhs.range;
def_ret
end
else def_ret
| Action_call f args ->
let ret_t, params = lookup_extern_fn (global_env_of_env env) f in
if List.length params <> List.length args
then error (Printf.sprintf "Insufficient arguments to extern function %s" (ident_to_string f)) f.range
else let args = List.map2 (fun (t, _, _) arg ->
let arg, t_arg = check_expr env arg in
if not (eq_typ env t t_arg)
then error (Printf.sprintf "Argument type mismatch, expected %s whereas %s has type %s"
(Ast.print_typ t)
(Ast.print_expr arg)
(Ast.print_typ t_arg)) arg.range
else arg) params args in
Action_call f args, tunit
in
match a.v with
| Atomic_action aa ->
let aa, t = check_atomic_action env a.range aa in
{ a with v=Atomic_action aa }, t
| Action_seq a0 rest ->
let a0, _ = check_atomic_action env a.range a0 in
let rest, t = check_field_action env f rest in
{ a with v=Action_seq a0 rest }, t
| Action_ite hd then_ else_ ->
let hd, t = check_expr env hd in
if not (eq_typ env t tbool)
then error (Printf.sprintf
"Branching is only permitted on boolean expressions, %s has type %s"
(print_expr hd)
(print_typ t))
hd.range;
let then_, t = check_field_action env f then_ in
let else_, t' =
match else_ with
| None -> None, tunit
| Some else_ ->
let else_, t = check_field_action env f else_ in
Some else_, t
in
let branches_eq_t = eq_typ env t t' in
let eq_t_unit = eq_typ env t tunit in
if not branches_eq_t
|| (None? else_ && not eq_t_unit)
then error (Printf.sprintf "The branches of a conditional must both have the same type; got %s and %s"
(print_typ t)
(print_typ t'))
a.range;
{ a with v = Action_ite hd then_ else_ }, t
| Action_let i aa k ->
let aa, t = check_atomic_action env a.range aa in
add_local env i t;
let k, t = check_field_action env f k in
remove_local env i;
{ a with v = Action_let i aa k }, t
| Action_act a ->
let a, t = check_field_action env f a in
if eq_typ env t tunit
then { a with v = Action_act a }, tbool
else error (Printf.sprintf "This ':act' action returns %s instead of unit"
(print_typ t))
a.range
#pop-options
#push-options "--z3rlimit_factor 4"
let check_atomic_field (env:env) (extend_scope: bool) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let sf_field_type = check_typ (Some? sf.field_probe) env sf.field_type in
let check_annot (e: expr) : ML expr =
let e, t = check_expr env e in
if not (eq_typ env t tuint32)
then match try_cast_integer env (e, t) tuint32 with
| Some e -> e
| _ -> error (Printf.sprintf "Array expression %s has type %s instead of UInt32"
(print_expr e)
(print_typ t))
e.range
else e
in
let fa = match sf.field_array_opt with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (check_annot e, b)
| FieldString sz -> FieldString (map_opt check_annot sz)
| FieldConsumeAll ->
if
if eq_typ env sf.field_type tuint8
then true
else eq_typ env sf.field_type tuint8be
then FieldConsumeAll
else error (Printf.sprintf "This ':consume-all field returns %s instead of UINT8 or UINT8BE" (print_typ sf.field_type)) f.range
in
let fc = sf.field_constraint |> map_opt (fun e ->
add_local env sf.field_ident sf.field_type;
let e = fst (check_expr env e) in
remove_local env sf.field_ident;
e)
in
let f_act = sf.field_action |> map_opt (fun (a, _) ->
add_local env sf.field_ident sf.field_type;
let a, _ = check_field_action env f a in
let dependent = is_used env sf.field_ident in
remove_local env sf.field_ident;
a, dependent)
in
let f_probe =
match sf.field_probe with
| None -> None
| Some p ->
let length, typ = check_expr env p.probe_length in
let length =
if not (eq_typ env typ tuint64)
then match try_cast_integer env (length, typ) tuint64 with
| Some e -> e
| _ -> error (Printf.sprintf "Probe length expression %s has type %s instead of UInt64"
(print_expr length)
(print_typ typ))
length.range
else length
in
let dest, dest_typ = check_ident env p.probe_dest in
if not (eq_typ env dest_typ tcopybuffer)
then error (Printf.sprintf "Probe destination expression %s has type %s instead of EVERPARSE_COPY_BUFFER_T"
(print_ident dest)
(print_typ dest_typ))
dest.range;
let probe_fn =
match p.probe_fn with
| None -> (
match GlobalEnv.default_probe_fn env.globals with
| None ->
error (Printf.sprintf "Probe function not specified and no default probe function found")
p.probe_length.range
| Some i -> i
)
| Some p -> (
match GlobalEnv.resolve_probe_fn env.globals p with
| None ->
error (Printf.sprintf "Probe function %s not found" (print_ident p))
p.range
| Some i ->
i
)
in
Some { probe_fn=Some probe_fn; probe_length=length; probe_dest=dest }
in
if extend_scope then add_local env sf.field_ident sf.field_type;
let sf = {
sf with
field_type = sf_field_type;
field_array_opt = fa;
field_constraint = fc;
field_action = f_act;
field_probe = f_probe;
} in
let _ =
match sf.field_type.v, sf.field_array_opt,
sf.field_constraint, sf.field_bitwidth,
sf.field_action, sf.field_probe
with
| Pointer _, FieldScalar,
None, None,
None, Some _ ->
()
| _, _,
_, _,
_, Some _ ->
error (Printf.sprintf "Probe annotation is only allowed on pointer fields with no other constraints")
f.range
| _ -> ()
in
Options.debug_print_string
(Printf.sprintf "Field %s has comments <%s>\n"
(print_ident sf.field_ident)
(String.concat "\n" f.comments));
{ f with v = sf }
let is_strong_prefix_field_array (a: field_array_t) : Tot bool =
not (FieldScalar? a)
let weak_kind_of_atomic_field (env: env) (f: atomic_field) : ML weak_kind =
if is_strong_prefix_field_array f.v.field_array_opt
then WeakKindStrongPrefix
else match typ_weak_kind env f.v.field_type with
| Some e -> e
| None -> failwith (Printf.sprintf "cannot find the weak kind of field %s : %s" (print_ident f.v.field_ident) (print_typ f.v.field_type))
let weak_kind_of_list (wa:'a -> ML weak_kind) (xs:list 'a) : ML weak_kind =
let k =
List.fold_left
(fun out f ->
let fk = wa f in
match out with
| None -> Some fk
| Some o -> Some (weak_kind_glb o fk))
None
xs
in
match k with
| None -> WeakKindWeak
| Some k -> k
let rec weak_kind_of_field (env: env) (f: field) : ML weak_kind =
match f.v with
| AtomicField f -> weak_kind_of_atomic_field env f
| RecordField f _ -> weak_kind_of_record env f
| SwitchCaseField f _ -> weak_kind_of_switch_case env f
and weak_kind_of_record env (fs:record) : ML weak_kind =
match fs with
| [] -> WeakKindStrongPrefix
| [a] -> weak_kind_of_field env a
| a :: q ->
let wk = weak_kind_of_field env a in
if wk <> WeakKindStrongPrefix
then failwith
(Printf.sprintf "weak_kind_of_fields: \
field %s should be of strong kind \
instead of %s"
(print_field a)
(print_weak_kind wk))
else weak_kind_of_record env q
and weak_kind_of_switch_case env (s:switch_case) : ML weak_kind =
let _, cases = s in
weak_kind_of_list (weak_kind_of_case env) cases
and weak_kind_of_case (env: env) (c: case) : ML weak_kind =
match c with
| DefaultCase f
| Case _ f -> weak_kind_of_field env f
#pop-options
let check_field_t = env -> field -> ML field
#push-options "--z3rlimit_factor 8"
let check_switch (check_field:check_field_t) (env:env) (s:switch_case)
: ML switch_case
= let head, cases = s in
let head, scrutinee_t = check_expr env head in
let fail_non_equality_type (#a:Type) () : ML (option a) =
let integral = typ_is_integral env scrutinee_t in
let is_bool = eq_typ env scrutinee_t tbool in
if not integral
&& not is_bool
then error (Printf.sprintf "Case analysis of a non-integral or non-boolean type (%s) is not supported"
(print_typ scrutinee_t))
head.range;
None
in
let tags_t_opt =
match scrutinee_t.v with
| Pointer _ -> fail_non_equality_type ()
| Type_app hd KindSpec es ->
(match try_lookup_enum_cases env hd with
| Some enum -> Some enum
| _ -> fail_non_equality_type ())
| Type_app _ _ _ ->
error "Impossible, check_switch is not supposed to typecheck output/extern types!" head.range
in
let check_case (c:case{Case? c}) : ML case =
let Case pat f = c in
let pat, pat_t = check_expr env pat in
let f = check_field env f in
let pat = //check type of patterns
match tags_t_opt with
| None ->
//Not an enum; just check that its a valid u32
if not (eq_typ env scrutinee_t pat_t)
then match try_cast_integer env (pat, pat_t) scrutinee_t with
| Some pat -> pat
| _ ->
error (Printf.sprintf "Type of case (%s) does not match type of switch expression (%s)"
(print_typ pat_t)
(print_typ scrutinee_t))
pat.range
else pat
| Some (enum_tags, t) ->
//expected an enumerated type;
//check that patterns are valid cases of the enum
let case_exists =
match pat.v with
| Identifier pat ->
Some? (List.tryFind (fun (case:ident) -> case.v = pat.v) enum_tags)
| _ ->
false
in
if not (eq_typ env pat_t t)
then error (Printf.sprintf "Type of case (%s) does not match type of switch expression (%s)"
(print_typ pat_t)
(print_typ t))
pat.range;
if not case_exists
then error (Printf.sprintf "Case (%s) is not in the enumerated type %s"
(print_expr pat)
(print_typ scrutinee_t))
pat.range;
pat
in
Case pat f
in
let check_default_case (c:case{DefaultCase? c}) : ML case =
let DefaultCase f = c in
let f = check_field env f in
DefaultCase f
in
let cases =
List.map (fun (o:case) -> if Case? o then check_case o else check_default_case o) cases in
let _ =
List.fold_right
(fun case default_ok ->
match case with
| Case _ _ -> false
| DefaultCase f ->
if default_ok then false
else raise (error "default is only allowed in the last case"
f.range))
cases
true
in
(head, cases)
#pop-options
let is_bound_locally (env:env) (i:ident) =
match H.try_find env.locals i.v with
| None -> false
| Some _ -> true
let rec check_record (check_field:check_field_t) (env:env) (fs:record)
: ML record
= let env = copy_env env in //locals of a record do not escape the record
(* Elaborate and check each field in order;
Checking each field extends the local environment with the name of that field *)
let fields =
List.map
(fun f ->
match f.v with
| AtomicField af ->
let af = check_atomic_field env true af in
{ f with v = AtomicField af }
| RecordField fs i ->
let fs = check_record check_field env fs in
{f with v = RecordField fs i }
| SwitchCaseField swc i ->
let swc = check_switch check_field env swc in
{ f with v = SwitchCaseField swc i})
fs
in
(* Infer which of the fields are dependent by seeing which of them are used in refinements *)
let nfields = List.length fields in
let fields = fields |> List.mapi (fun i f ->
match f.v with
| RecordField _ _
| SwitchCaseField _ _ -> f
| AtomicField af ->
let sf = af.v in
let used = is_used env sf.field_ident in
let last_field = i = (nfields - 1) in
let dependent = used || (Some? sf.field_constraint && not last_field) in
let af =
with_range_and_comments
({ sf with field_dependence = dependent })
af.range
af.comments
in
let has_reader = typ_has_reader env af.v.field_type in
let is_enum = is_enum env af.v.field_type in
if af.v.field_dependence
&& not has_reader
&& not is_enum //if it's an enum, it can be inlined later to allow dependence
then error "The type of this field does not have a reader, \
either because its values are too large \
or because reading it may incur a double fetch; \
subsequent fields cannot depend on it" af.range
else { f with v = AtomicField af })
in
fields
let name_of_field (f:field) : ident =
match f.v with
| AtomicField af -> af.v.field_ident
| RecordField _ i
| SwitchCaseField _ i -> i
let check_field_names_unique (f:list field)
: ML unit
= match f with
| []
| [_] -> ()
| hd::tl ->
let i = name_of_field hd in
if List.for_all (fun f' -> not (eq_idents (name_of_field f') i)) tl
then ()
else error (Printf.sprintf "Field name %s is not unique" i.v.name) i.range
let rec check_field (env:env) (f:field)
: ML field
= match f.v with
| AtomicField af ->
{ f with v = AtomicField (check_atomic_field env false af) }
| RecordField fs i ->
check_field_names_unique fs;
{ f with v = RecordField (check_record check_field env fs) i }
| SwitchCaseField swc i ->
{ f with v = SwitchCaseField (check_switch check_field env swc) i }
(** Computes a layout for bit fields,
decorating each field with a bitfield index
and a bit range within that bitfield to store the given field.
Collapsing adjacent bitfields into a single field is done in a
separate phase, see BitFields.fst
*)
let elaborate_bit_fields env (fields:list field)
: ML (out:list field { List.length out == List.length fields })
= let bf_index : ref int = ST.alloc 0 in
let get_bf_index () = !bf_index in
let next_bf_index () = bf_index := !bf_index + 1 in
let new_bit_field (sf:atomic_field') bw r : ML (atomic_field & option (typ & int & int)) =
let index = get_bf_index () in
let size = size_of_integral_typ env sf.field_type r in
let bit_size = 8 * size in
let remaining_size = bit_size - bw.v in
let from = 0 in
let to = bw.v in
let bf_attr = {
bitfield_width = bw.v;
bitfield_identifier = index;
bitfield_type = sf.field_type;
bitfield_from = from;
bitfield_to = to
} in
let sf = { sf with field_bitwidth = Some (Inr (with_range bf_attr r)) } in
with_range sf r,
Some (sf.field_type, to, remaining_size)
in
let rec aux open_bit_field fields
: ML (out:list field { List.length out == List.length fields } )
= match fields with
| [] ->
[]
| hd::tl ->
begin
match hd.v with
| RecordField fs hd_fieldname ->
next_bf_index();
let fs = aux None fs in
let hd = { hd with v = RecordField fs hd_fieldname } in
next_bf_index();
hd :: aux None tl
| SwitchCaseField (e, cases) hd_fieldname ->
next_bf_index();
let cases =
List.map
(function
| Case p f ->
let [f] = aux None [f] in
Case p f
| DefaultCase f ->
let [f] = aux None [f] in
DefaultCase f)
cases
in
next_bf_index();
let hd = { hd with v = SwitchCaseField (e, cases) hd_fieldname } in
hd :: aux None tl
| AtomicField af ->
let sf = af.v in
match sf.field_bitwidth, open_bit_field with
| None, None ->
hd :: aux open_bit_field tl
| None, Some _ -> //end the bit field
next_bf_index();
hd :: aux None tl
| Some (Inr _), _ ->
failwith "Bitfield is already elaborated"
| Some (Inl bw), None ->
let af, open_bit_field = new_bit_field sf bw hd.range in
let tl = aux open_bit_field tl in
{ hd with v = AtomicField af } :: tl
| Some (Inl bw), Some (bit_field_typ, pos, remaining_size) ->
Options.debug_print_string
(Printf.sprintf
"Field type = %s; bit_field_type = %s\n"
(print_typ sf.field_type)
(print_typ bit_field_typ));
let type_matches_current_open_field = eq_typ env sf.field_type bit_field_typ in
if remaining_size < bw.v //not enough space in this bit field, start a new one
|| not type_matches_current_open_field
then let _ = next_bf_index () in
let af, open_bit_field = new_bit_field sf bw hd.range in
let tl = aux open_bit_field tl in
{ hd with v = AtomicField af } :: tl
else //extend this bit field
begin
let remaining_size = remaining_size - bw.v in
let from = pos in
let to = pos + bw.v in
let index = get_bf_index() in
let bf_attr = {
bitfield_width = bw.v;
bitfield_identifier = index;
bitfield_type = bit_field_typ;
bitfield_from = from;
bitfield_to = to
} in
let sf = { sf with field_bitwidth = Some (Inr (with_range bf_attr bw.range)) } in
let af = { af with v = sf } in
let hd = { hd with v = AtomicField af } in
let open_bit_field = Some (bit_field_typ, to, remaining_size) in
let tl = aux open_bit_field tl in
hd :: tl
end
end
in
aux None fields
let allowed_base_types_as_output_types = [
"UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"PUINT8";
"Bool"
]
let rec check_mutable_param_type (env:env) (t:typ) : ML unit =
let err iopt : ML unit =
let otype =
match iopt with
| None -> "None"
| Some i ->
match H.try_find env.globals.ge_out_t i.v with
| Some d ->
Printf.sprintf "(Some %s)" (print_decl d)
| _ -> "None"
in
error (Printf.sprintf "%s is not an integer or output or extern type (found decl %s)" (print_typ t) otype) t.range in
let t = unfold_typ_abbrev_only env t in
match t.v with
| Type_app i k [] ->
if k = KindOutput || k = KindExtern ||
(i.v.modul_name = None && List.Tot.mem i.v.name allowed_base_types_as_output_types)
then ()
else err (Some i)
| Pointer t -> check_mutable_param_type env t
| _ -> err None
let rec check_integer_or_output_type (env:env) (t:typ) : ML unit =
let t = unfold_typ_abbrev_only env t in
match t.v with
| Type_app i k [] -> //either it should be a base type, or an output type
if i.v.modul_name = None && List.Tot.mem i.v.name allowed_base_types_as_output_types
then ()
else if not (k = KindOutput) then error (Printf.sprintf "%s is not an integer or output type" (print_typ t)) t.range
| Pointer t -> check_integer_or_output_type env t
| _ -> error (Printf.sprintf "%s is not an integer or output type" (print_typ t)) t.range
let check_mutable_param (env:env) (p:param) : ML unit =
//a mutable parameter should have a pointer type
//and the base type may be a base type or an output type
let t, _, _ = p in
match t.v with
| Pointer bt ->
check_mutable_param_type env bt
| _ ->
error (Printf.sprintf "%s is not a valid mutable parameter type, it is not a pointer type" (print_typ t)) t.range
let check_params (env:env) (ps:list param) : ML unit =
ps |> List.iter (fun (t, p, q) ->
if q = Mutable then check_mutable_param env (t, p, q)
else ignore (check_typ true env t);
add_local env p t)
let elaborate_record_decl (e:global_env)
(tdnames:Ast.typedef_names)
(params:list param)
(where:option expr)
(fields:list field)
(range:range)
(comments:comments)
(is_exported:bool)
: ML decl
= let env = { mk_env e with this=Some tdnames.typedef_name } in
(* Check parameters, that their types are well-formed;
extend the environments with them *)
check_params env params;
(* If a where-clause is present, elaborate it into a refined unit field *)
let where, maybe_unit_field =
match where with
| None ->
None, []
| Some e ->
let e, t = check_expr env e in
if not (eq_typ env t tbool)
then error (Printf.sprintf "Expected a boolean where clause; got %s"
(print_typ t))
e.range;
let w = Some e in
let field =
{ field_dependence = true;
field_ident = with_range (to_ident' "__precondition") e.range;
field_type = tunit;
field_array_opt = FieldScalar;
field_constraint = w;
field_bitwidth = None;
field_action = None;
field_probe = None
}
in
let af = with_range (AtomicField (with_range field e.range)) e.range in
w, [af]
in
(* Elaborate and check each field in order;
Checking each field extends the local environment with the name of that field *)
let fields = check_record check_field env fields in
let fields = maybe_unit_field@fields in
let fields = elaborate_bit_fields env fields in
let d = mk_decl (Record tdnames params where fields) range comments is_exported in
let attrs = {
may_fail = false; //only its fields may fail; not the struct itself
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = weak_kind_of_record env fields;
parser_kind_nz = None
}
in
add_global e tdnames.typedef_name d (Inl attrs);
d
(*
* An output field type is either a base type or another output type
*
* TODO: check field name shadowing
* TODO: check bit fields, do we check that the sum of bitwidths is ok etc.?
* as of now, we don't check anything here
*)
let rec check_output_field (ge:global_env) (fld:out_field) : ML unit =
match fld with
| Out_field_named _ t _bopt -> check_integer_or_output_type (env_of_global_env ge) t
| Out_field_anon l _ -> check_output_fields ge l
and check_output_fields (ge:global_env) (flds:list out_field) : ML unit =
List.iter (check_output_field ge) flds
let bind_decl (e:global_env) (d:decl) : ML decl =
match d.d_decl.v with
| ModuleAbbrev i m -> d
| Define i None c ->
let t = type_of_constant d.d_decl.range c in
let d = decl_with_v d (Define i (Some t) c) in
add_global e i d (Inr (nullary_macro t (Some (with_range (Constant c) d.d_decl.range))));
d
| Define i (Some t) c ->
let env = mk_env e in
let t = check_typ false env t in
let t' = type_of_constant d.d_decl.range c in
let d = decl_with_v d (Define i (Some t) c) in
if eq_typ env t t'
then (add_global e i d (Inr (nullary_macro (type_of_constant d.d_decl.range c)
(Some (with_range (Constant c) d.d_decl.range))));
d)
else error "Ill-typed constant" d.d_decl.range
| TypeAbbrev t i ->
let env = mk_env e in
let t = check_typ false env t in
let wk =
match typ_weak_kind env t with
| None -> failwith (Printf.sprintf "Weak kind not found for type %s" (print_typ t))
| Some wk -> wk
in
let integral, bit_order = tag_and_bit_order_of_integral_typ env t in
let attrs =
{
may_fail = parser_may_fail env t;
integral = integral;
bit_order = bit_order;
has_reader = typ_has_reader env t;
parser_weak_kind = wk;
parser_kind_nz = None
}
in
let d = decl_with_v d (TypeAbbrev t i) in
add_global e i d (Inl attrs);
d
| Enum t i cases ->
let env = mk_env e in
let t = check_typ false env t in
let cases_idents = Desugar.check_desugared_enum_cases cases in
cases_idents |> List.iter (fun i ->
let _, t' = check_expr env (with_dummy_range (Identifier i)) in
if not (eq_typ env t t')
then error (Printf.sprintf "Inconsistent type of enumeration identifier: Expected %s, got %s"
(print_typ t)
(print_typ t'))
d.d_decl.range);
let integral = typ_as_integer_type t in
let bit_order = bit_order_of_typ t in
let attrs =
{
may_fail = true;
integral = Some integral;
bit_order = Some bit_order;
has_reader = false; //it's a refinement, so you can't read it again because of double fetches
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = None
}
in
let d = decl_with_v d (Enum t i cases) in
add_global e i d (Inl attrs);
d
| Record tdnames params where fields ->
elaborate_record_decl e tdnames params where fields d.d_decl.range d.d_decl.comments d.d_exported
| CaseType tdnames params switch ->
let env = { mk_env e with this=Some tdnames.typedef_name } in
check_params env params;
let switch = check_switch check_field env switch in
let wk = weak_kind_of_switch_case env switch in
let attrs = {
may_fail = false;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = wk;
parser_kind_nz = None
} in
let d = mk_decl (CaseType tdnames params switch) d.d_decl.range d.d_decl.comments d.d_exported in
add_global e tdnames.typedef_name d (Inl attrs);
d
| OutputType out_t ->
check_output_fields e out_t.out_typ_fields;
add_output_type e out_t.out_typ_names.typedef_name d;
d
| ExternType tdnames ->
add_extern_type e tdnames.typedef_name d;
d
| ExternFn f ret params ->
let env = mk_env e in
let ret = check_typ true env ret in
check_params env params;
let d = mk_decl (ExternFn f ret params) d.d_decl.range d.d_decl.comments d.d_exported in
add_extern_fn e f d;
d
| ExternProbe i ->
add_extern_probe e i d;
d
let bind_decls (g:global_env) (p:list decl) : ML (list decl & global_env) =
List.map (bind_decl g) p, g | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Options.fsti.checked",
"Hashtable.fsti.checked",
"GlobalEnv.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Binding.fst"
} | [
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML GlobalEnv.global_env | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"GlobalEnv.global_env",
"Config.config",
"Prims.string",
"FStar.List.iter",
"Binding.add_global",
"Ast.Inr",
"GlobalEnv.decl_attributes",
"GlobalEnv.macro_signature",
"Ast.decl",
"Ast.mk_decl",
"Ast.ExternFn",
"Ast.tbool",
"Prims.Nil",
"Ast.param",
"Ast.dummy_range",
"Ast.with_meta_t",
"Ast.ident'",
"Ast.with_dummy_range",
"Ast.Mkident'",
"FStar.Pervasives.Native.Some",
"Ast.__proj__Mkident'__item__name",
"Ast.to_ident'",
"GlobalEnv.nullary_macro",
"FStar.Pervasives.Native.None",
"Ast.expr",
"Config.__proj__Mkcompile_time_flags__item__flags",
"Config.__proj__Mkconfig__item__compile_time_flags",
"Binding.add_extern_type",
"Ast.ExternType",
"Ast.Mktypedef_names",
"Ast.attribute",
"FStar.Pervasives.Native.tuple2",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"GlobalEnv.Mkmacro_signature",
"Ast.typ",
"Ast.tuint32",
"Ast.Inl",
"GlobalEnv.Mkdecl_attributes",
"Ast.integer_type",
"Ast.bitfield_bit_order",
"Ast.WeakKindStrongPrefix",
"Prims.bool",
"Ast.UInt8",
"Ast.LSBFirst",
"Ast.UInt16",
"Ast.UInt32",
"Ast.UInt64",
"Ast.MSBFirst",
"Ast.WeakKindConsumesAll",
"Ast.ident",
"Ast.Record",
"Ast.field'",
"Ast.typedef_names",
"GlobalEnv.Mkglobal_env",
"Hashtable.t",
"Hashtable.create",
"GlobalEnv.global_hash_t",
"Ast.either",
"FStar.Pervasives.Native.option",
"Deps.get_config"
] | [] | false | true | false | false | false | let initial_global_env () =
| let cfg = Deps.get_config () in
let e =
{
ge_h = H.create 10;
ge_out_t = H.create 10;
ge_extern_t = H.create 10;
ge_extern_fn = H.create 10;
ge_probe_fn = H.create 10;
ge_cfg = cfg
}
in
let nullary_decl i =
let td_name =
{ typedef_name = i; typedef_abbrev = i; typedef_ptr_abbrev = i; typedef_attributes = [] }
in
mk_decl (Record td_name [] None []) dummy_range [] true
in
let _type_names =
[
("unit",
{
may_fail = false;
integral = None;
bit_order = None;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some false
});
("Bool",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT8",
{
may_fail = true;
integral = Some UInt8;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT16",
{
may_fail = true;
integral = Some UInt16;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT32",
{
may_fail = true;
integral = Some UInt32;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT64",
{
may_fail = true;
integral = Some UInt64;
bit_order = Some LSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT8BE",
{
may_fail = true;
integral = Some UInt8;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT16BE",
{
may_fail = true;
integral = Some UInt16;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT32BE",
{
may_fail = true;
integral = Some UInt32;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("UINT64BE",
{
may_fail = true;
integral = Some UInt64;
bit_order = Some MSBFirst;
has_reader = true;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("field_id",
{
may_fail = true;
integral = Some UInt32;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("all_bytes",
{
may_fail = false;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindConsumesAll;
parser_kind_nz = Some false
});
("all_zeros",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindConsumesAll;
parser_kind_nz = Some false
});
("PUINT8",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
});
("EVERPARSE_COPY_BUFFER_T",
{
may_fail = true;
integral = None;
bit_order = None;
has_reader = false;
parser_weak_kind = WeakKindStrongPrefix;
parser_kind_nz = Some true
})
] |>
List.iter (fun (i, attrs) ->
let i = with_dummy_range (to_ident' i) in
add_global e i (nullary_decl i) (Inl attrs))
in
let _operators =
[
("is_range_okay",
{
macro_arguments_t = [tuint32; tuint32; tuint32];
macro_result_t = tbool;
macro_defn_t = None
})
] |>
List.iter (fun (i, d) ->
let i = with_dummy_range (to_ident' i) in
add_global e i (nullary_decl i) (Inr d))
in
let _void =
let void_ident = with_dummy_range (to_ident' "void") in
add_extern_type e
void_ident
(mk_decl (ExternType
({
typedef_name = void_ident;
typedef_abbrev = void_ident;
typedef_ptr_abbrev = void_ident;
typedef_attributes = []
}))
dummy_range
[]
false)
in
let _ =
match cfg with
| None -> ()
| Some (cfg, module_name) ->
List.iter (fun flag ->
let ms = nullary_macro tbool None in
let i = with_dummy_range ({ to_ident' flag with modul_name = Some module_name }) in
let d = mk_decl (ExternFn i tbool []) dummy_range [] false in
add_global e i d (Inr ms))
cfg.compile_time_flags.flags
in
e | false |
Spec.Matrix.fst | Spec.Matrix.mget_s | val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem | val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem | let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i] | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 340,
"start_col": 0,
"start_line": 338
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Matrix.matrix n1 n2 -> i: Lib.IntTypes.size_nat{i < n1} -> j: Lib.IntTypes.size_nat{j < n2}
-> Spec.Matrix.elem | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Spec.Matrix.matrix",
"Prims.op_LessThan",
"Lib.Sequence.op_String_Access",
"Spec.Matrix.elem",
"Prims.op_Addition",
"Prims.unit",
"Spec.Matrix.index_lt"
] | [] | false | false | false | false | false | let mget_s #n1 #n2 a i j =
| index_lt n2 n1 j i;
a.[ j * n1 + i ] | false |
Spec.Matrix.fst | Spec.Matrix.mul_inner | val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))} | val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))} | let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 304,
"start_col": 0,
"start_line": 295
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))} | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Matrix.matrix n1 n2 ->
b: Spec.Matrix.matrix n2 n3 ->
i: Lib.IntTypes.size_nat{i < n1} ->
k: Lib.IntTypes.size_nat{k < n3}
-> res: Lib.IntTypes.uint16{res == Spec.Matrix.sum (fun l -> a.(i, l) *. b.(l, k))} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.l_and",
"Spec.Matrix.matrix",
"Prims.op_LessThan",
"Prims.unit",
"Spec.Matrix.sum_extensionality",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Spec.Matrix.op_Array_Access",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint16",
"Lib.IntTypes.int_t",
"Prims.eq2",
"Spec.Matrix.sum_",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Lib.IntTypes.op_Plus_Dot",
"Prims.op_Addition",
"Lib.IntTypes.u16",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Matrix.sum"
] | [] | false | false | false | false | false | let mul_inner #n1 #n2 #n3 a b i k =
| let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res -> res +. a.(i, j) *. b.(j, k))
(u16 0)
in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res | false |
Spec.Matrix.fst | Spec.Matrix.sum_extensionality | val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i) | val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i) | let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1) | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 282,
"start_col": 0,
"start_line": 280
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: Lib.IntTypes.size_nat ->
f: (i: Lib.IntTypes.size_nat{i < n} -> Prims.GTot Lib.IntTypes.uint16) ->
g: (i: Lib.IntTypes.size_nat{i < n} -> Prims.GTot Lib.IntTypes.uint16) ->
i: Lib.IntTypes.size_nat{i <= n}
-> FStar.Pervasives.Lemma (requires forall (i: Lib.IntTypes.size_nat{i < n}). f i == g i)
(ensures Spec.Matrix.sum_ f i == Spec.Matrix.sum_ g i)
(decreases i) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.uint16",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Spec.Matrix.sum_extensionality",
"Prims.op_Subtraction",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec sum_extensionality n f g i =
| if i = 0 then () else sum_extensionality n f g (i - 1) | false |
Spec.Matrix.fst | Spec.Matrix.sum_ | val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i) | val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i) | let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1) | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 264,
"start_col": 0,
"start_line": 262
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: (j: Lib.IntTypes.size_nat{j < n} -> Prims.GTot Lib.IntTypes.uint16) ->
i: Lib.IntTypes.size_nat{i <= n}
-> Prims.GTot Lib.IntTypes.uint16 | Prims.GTot | [
"sometrivial",
""
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.uint16",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.u16",
"Prims.bool",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Spec.Matrix.sum_",
"Prims.op_Subtraction"
] | [
"recursion"
] | false | false | false | false | false | let rec sum_ #n f i =
| if i = 0 then u16 0 else sum_ #n f (i - 1) +. f (i - 1) | false |
Spec.Matrix.fst | Spec.Matrix.map2 | val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) } | val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) } | let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 230,
"start_col": 0,
"start_line": 219
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) } | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: (_: Spec.Matrix.elem -> _: Spec.Matrix.elem -> Spec.Matrix.elem) ->
a: Spec.Matrix.matrix n1 n2 ->
b: Spec.Matrix.matrix n1 n2
-> c:
Spec.Matrix.matrix n1 n2
{ forall (i: Lib.IntTypes.size_nat{i < n1 /\ i < n1 /\ i < n1})
(j: Lib.IntTypes.size_nat{j < n2 /\ j < n2 /\ j < n2}).
c.(i, j) == f a.(i, j) b.(i, j) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Spec.Matrix.elem",
"Spec.Matrix.matrix",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.eq2",
"Spec.Matrix.op_Array_Access",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_and",
"Spec.Matrix.op_Array_Assignment",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Spec.Matrix.create"
] | [] | false | false | false | false | false | let map2 #n1 #n2 f a b =
| let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c ->
forall (i0: size_nat{i0 < i}) (j: size_nat{j < n2}). c.(i0, j) == f a.(i0, j) b.(i0, j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0: size_nat{i0 < i}) (j: size_nat{j < n2}). c0.(i0, j) == c.(i0, j)) /\
(forall (j0: size_nat{j0 < j}). c0.(i, j0) == f a.(i, j0) b.(i, j0)))
(fun j c' -> c'.(i, j) <- f a.(i, j) b.(i, j))
c)
c | false |
Spec.Matrix.fst | Spec.Matrix.map | val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) } | val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) } | let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 183,
"start_col": 0,
"start_line": 172
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) } | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: Spec.Matrix.elem -> Spec.Matrix.elem) -> a: Spec.Matrix.matrix n1 n2
-> c:
Spec.Matrix.matrix n1 n2
{ forall (i: Lib.IntTypes.size_nat{i < n1 /\ i < n1})
(j: Lib.IntTypes.size_nat{j < n2 /\ j < n2}).
c.(i, j) == f a.(i, j) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Spec.Matrix.elem",
"Spec.Matrix.matrix",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.eq2",
"Spec.Matrix.op_Array_Access",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_and",
"Spec.Matrix.op_Array_Assignment",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Spec.Matrix.create"
] | [] | false | false | false | false | false | let map #n1 #n2 f a =
| let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0: size_nat{i0 < i}) (j: size_nat{j < n2}). c.(i0, j) == f a.(i0, j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0: size_nat{i0 < i}) (j: size_nat{j < n2}). c0.(i0, j) == c.(i0, j)) /\
(forall (j0: size_nat{j0 < j}). c0.(i, j0) == f a.(i, j0)))
(fun j c' -> c'.(i, j) <- f a.(i, j))
c)
c | false |
Spec.Matrix.fst | Spec.Matrix.mul_inner_s | val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)} | val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)} | let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 363,
"start_col": 0,
"start_line": 354
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)} | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Matrix.matrix n1 n2 ->
b: Spec.Matrix.matrix n2 n3 ->
i: Lib.IntTypes.size_nat{i < n1} ->
k: Lib.IntTypes.size_nat{k < n3}
-> res:
Lib.IntTypes.uint16{res == Spec.Matrix.sum (fun l -> a.(i, l) *. Spec.Matrix.mget_s b l k)} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.l_and",
"Spec.Matrix.matrix",
"Prims.op_LessThan",
"Prims.unit",
"Spec.Matrix.sum_extensionality",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Spec.Matrix.op_Array_Access",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Matrix.mget_s",
"Lib.IntTypes.uint16",
"Lib.IntTypes.int_t",
"Prims.eq2",
"Spec.Matrix.sum_",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Lib.IntTypes.op_Plus_Dot",
"Prims.op_Addition",
"Lib.IntTypes.u16",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Matrix.sum"
] | [] | false | false | false | false | false | let mul_inner_s #n1 #n2 #n3 a b i k =
| let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res -> res +. a.(i, j) *. mget_s b j k)
(u16 0)
in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res | false |
Spec.Matrix.fst | Spec.Matrix.matrix_eq | val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0)) | val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0)) | let matrix_eq #n1 #n2 a b =
seq_eq_mask a b (n1 * n2) | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 401,
"start_col": 0,
"start_line": 400
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res
#pop-options
val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_s #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k
) c
) c
val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0)) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Matrix.matrix n1 n2 -> b: Spec.Matrix.matrix n1 n2 -> Prims.Pure Lib.IntTypes.uint16 | Prims.Pure | [] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Spec.Matrix.matrix",
"Lib.ByteSequence.seq_eq_mask",
"Lib.IntTypes.U16",
"Lib.IntTypes.uint16"
] | [] | false | false | false | false | false | let matrix_eq #n1 #n2 a b =
| seq_eq_mask a b (n1 * n2) | false |
LowParse.Low.Int32le.fst | LowParse.Low.Int32le.validate_int32le | val validate_int32le:validator parse_int32le | val validate_int32le:validator parse_int32le | let validate_int32le : validator parse_int32le
= validate_total_constant_size parse_int32le 4uL () | {
"file_name": "src/lowparse/LowParse.Low.Int32le.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 29,
"start_col": 0,
"start_line": 28
} | module LowParse.Low.Int32le
(* LowParse implementation module for 32 bits little endian integers *)
include LowParse.Low.Combinators
include LowParse.Spec.Int32le
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
inline_for_extraction
let read_int32le : leaf_reader parse_int32le
= make_total_constant_size_reader 4 4ul decode_int32le (decode_int32le_total_constant ()) (fun #rrel #rel b pos ->
let h = HST.get () in
assert ((U32.v pos + 4) <= Seq.length (B.as_seq h b));
[@inline_let] let _ = decode_int32le_eq (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)) in
let r0 = B.index b pos in
let r1 = B.index b (pos `U32.add` 1ul) in
let r2 = B.index b (pos `U32.add` 2ul) in
let r3 = B.index b (pos `U32.add` 3ul) in
Cast.uint8_to_uint32 r0 `U32.add` (256ul `U32.mul` (Cast.uint8_to_uint32 r1 `U32.add` (256ul `U32.mul` (Cast.uint8_to_uint32 r2 `U32.add` (256ul `U32.mul` Cast.uint8_to_uint32 r3)))))
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Int32le.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Low.Base.validator LowParse.Spec.Int32le.parse_int32le | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Base.validate_total_constant_size",
"LowParse.Spec.Base.total_constant_size_parser_kind",
"FStar.UInt32.t",
"LowParse.Spec.Int32le.parse_int32le",
"FStar.UInt64.__uint_to_t"
] | [] | false | false | false | false | false | let validate_int32le:validator parse_int32le =
| validate_total_constant_size parse_int32le 4uL () | false |
Spec.Matrix.fst | Spec.Matrix.matrix_to_lbytes | val matrix_to_lbytes:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> lbytes (2 * n1 * n2) | val matrix_to_lbytes:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> lbytes (2 * n1 * n2) | let matrix_to_lbytes #n1 #n2 m =
generate_blocks_simple 2 (n1 * n2) (n1 * n2) (matrix_to_lbytes_f m) | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 422,
"start_col": 0,
"start_line": 421
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res
#pop-options
val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_s #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k
) c
) c
val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0))
let matrix_eq #n1 #n2 a b =
seq_eq_mask a b (n1 * n2)
val matrix_to_lbytes_f:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> i:size_nat{i < n1 * n2}
-> lbytes 2
let matrix_to_lbytes_f #n1 #n2 m i =
uint_to_bytes_le m.[i]
val matrix_to_lbytes:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> lbytes (2 * n1 * n2) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Spec.Matrix.matrix n1 n2 -> Lib.ByteSequence.lbytes ((2 * n1) * n2) | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Spec.Matrix.matrix",
"Lib.Sequence.generate_blocks_simple",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Matrix.matrix_to_lbytes_f",
"Lib.ByteSequence.lbytes"
] | [] | false | false | false | false | false | let matrix_to_lbytes #n1 #n2 m =
| generate_blocks_simple 2 (n1 * n2) (n1 * n2) (matrix_to_lbytes_f m) | false |
Spec.Matrix.fst | Spec.Matrix.matrix_from_lbytes_f | val matrix_from_lbytes_f:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> i:size_nat{i < n1 * n2}
-> elem | val matrix_from_lbytes_f:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> i:size_nat{i < n1 * n2}
-> elem | let matrix_from_lbytes_f n1 n2 b i =
uint_from_bytes_le (LSeq.sub b (2 * i) 2) | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 433,
"start_col": 0,
"start_line": 432
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res
#pop-options
val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_s #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k
) c
) c
val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0))
let matrix_eq #n1 #n2 a b =
seq_eq_mask a b (n1 * n2)
val matrix_to_lbytes_f:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> i:size_nat{i < n1 * n2}
-> lbytes 2
let matrix_to_lbytes_f #n1 #n2 m i =
uint_to_bytes_le m.[i]
val matrix_to_lbytes:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> lbytes (2 * n1 * n2)
let matrix_to_lbytes #n1 #n2 m =
generate_blocks_simple 2 (n1 * n2) (n1 * n2) (matrix_to_lbytes_f m)
val matrix_from_lbytes_f:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> i:size_nat{i < n1 * n2}
-> elem | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n1: Lib.IntTypes.size_nat ->
n2: Lib.IntTypes.size_nat{(2 * n1) * n2 <= Lib.IntTypes.max_size_t} ->
b: Lib.ByteSequence.lbytes ((2 * n1) * n2) ->
i: Lib.IntTypes.size_nat{i < n1 * n2}
-> Spec.Matrix.elem | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.ByteSequence.lbytes",
"Prims.op_LessThan",
"Lib.ByteSequence.uint_from_bytes_le",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Lib.Sequence.sub",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Spec.Matrix.elem"
] | [] | false | false | false | false | false | let matrix_from_lbytes_f n1 n2 b i =
| uint_from_bytes_le (LSeq.sub b (2 * i) 2) | false |
Spec.Matrix.fst | Spec.Matrix.matrix_from_lbytes | val matrix_from_lbytes:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> matrix n1 n2 | val matrix_from_lbytes:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> matrix n1 n2 | let matrix_from_lbytes n1 n2 b =
createi (n1 * n2) (matrix_from_lbytes_f n1 n2 b) | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 443,
"start_col": 0,
"start_line": 442
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res
#pop-options
val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_s #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k
) c
) c
val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0))
let matrix_eq #n1 #n2 a b =
seq_eq_mask a b (n1 * n2)
val matrix_to_lbytes_f:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> i:size_nat{i < n1 * n2}
-> lbytes 2
let matrix_to_lbytes_f #n1 #n2 m i =
uint_to_bytes_le m.[i]
val matrix_to_lbytes:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> lbytes (2 * n1 * n2)
let matrix_to_lbytes #n1 #n2 m =
generate_blocks_simple 2 (n1 * n2) (n1 * n2) (matrix_to_lbytes_f m)
val matrix_from_lbytes_f:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> i:size_nat{i < n1 * n2}
-> elem
let matrix_from_lbytes_f n1 n2 b i =
uint_from_bytes_le (LSeq.sub b (2 * i) 2)
val matrix_from_lbytes:
n1:size_nat
-> n2:size_nat{2 * n1 * n2 <= max_size_t}
-> b:lbytes (2 * n1 * n2)
-> matrix n1 n2 | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n1: Lib.IntTypes.size_nat ->
n2: Lib.IntTypes.size_nat{(2 * n1) * n2 <= Lib.IntTypes.max_size_t} ->
b: Lib.ByteSequence.lbytes ((2 * n1) * n2)
-> Spec.Matrix.matrix n1 n2 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.ByteSequence.lbytes",
"Lib.Sequence.createi",
"Spec.Matrix.elem",
"Spec.Matrix.matrix_from_lbytes_f",
"Spec.Matrix.matrix"
] | [] | false | false | false | false | false | let matrix_from_lbytes n1 n2 b =
| createi (n1 * n2) (matrix_from_lbytes_f n1 n2 b) | false |
Spec.Matrix.fst | Spec.Matrix.mul | val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))} | val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))} | let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 327,
"start_col": 0,
"start_line": 316
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))} | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Matrix.matrix n1 n2 -> b: Spec.Matrix.matrix n2 n3
-> c:
Spec.Matrix.matrix n1 n3
{ forall (i: Lib.IntTypes.size_nat{i < n1}) (k: j: Lib.IntTypes.size_nat{j < n3}).
c.(i, k) == Spec.Matrix.sum (fun l -> a.(i, l) *. b.(l, k)) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.l_and",
"Spec.Matrix.matrix",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.IntTypes.uint16",
"Spec.Matrix.op_Array_Access",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Matrix.sum",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_disEquality",
"Prims.l_or",
"Spec.Matrix.elem",
"Spec.Matrix.op_Array_Assignment",
"Spec.Matrix.mul_inner",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.op_Multiply",
"Spec.Matrix.create"
] | [] | false | false | false | false | false | let mul #n1 #n2 #n3 a b =
| let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c ->
forall (i1: size_nat{i1 < i}) (k: size_nat{k < n3}).
c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 ->
(forall (k1: size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1: size_nat{i1 < n1 /\ i <> i1}) (k: size_nat{k < n3}).
c0.(i1, k) == c.(i1, k)))
(fun k c0 -> c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k)
c)
c | false |
Spec.Matrix.fst | Spec.Matrix.matrix_to_lbytes_f | val matrix_to_lbytes_f:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> i:size_nat{i < n1 * n2}
-> lbytes 2 | val matrix_to_lbytes_f:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> i:size_nat{i < n1 * n2}
-> lbytes 2 | let matrix_to_lbytes_f #n1 #n2 m i =
uint_to_bytes_le m.[i] | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 412,
"start_col": 0,
"start_line": 411
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res
#pop-options
val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_s #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k
) c
) c
val matrix_eq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Pure uint16
(requires True)
(ensures fun r ->
(a == b ==> v r == v (ones U16 SEC)) /\
(a =!= b ==> v r == 0))
let matrix_eq #n1 #n2 a b =
seq_eq_mask a b (n1 * n2)
val matrix_to_lbytes_f:
#n1:size_nat
-> #n2:size_nat{2 * n1 * n2 <= max_size_t}
-> m:matrix n1 n2
-> i:size_nat{i < n1 * n2}
-> lbytes 2 | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Spec.Matrix.matrix n1 n2 -> i: Lib.IntTypes.size_nat{i < n1 * n2} -> Lib.ByteSequence.lbytes 2 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Spec.Matrix.matrix",
"Prims.op_LessThan",
"Lib.ByteSequence.uint_to_bytes_le",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access",
"Spec.Matrix.elem",
"Lib.ByteSequence.lbytes"
] | [] | false | false | false | false | false | let matrix_to_lbytes_f #n1 #n2 m i =
| uint_to_bytes_le m.[ i ] | false |
Spec.Matrix.fst | Spec.Matrix.mul_s | val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)} | val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)} | let mul_s #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k
) c
) c | {
"file_name": "specs/frodo/Spec.Matrix.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 386,
"start_col": 0,
"start_line": 375
} | module Spec.Matrix
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
module LSeq = Lib.Sequence
module Lemmas = Spec.Frodo.Lemmas
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
/// Auxiliary lemmas
val index_lt:
n1:size_nat
-> n2:size_nat
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> Lemma (i * n2 + j < n1 * n2)
let index_lt n1 n2 i j =
calc (<=) {
i * n2 + j;
(<=) { Math.Lemmas.lemma_mult_le_right n2 i (n1 - 1) }
(n1 - 1) * n2 + j;
(==) { Math.Lemmas.distributivity_sub_left n1 1 n2 }
n1 * n2 - n2 + j;
(<=) { }
n1 * n2 - 1;
}
private
val index_neq:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> i:size_nat{i < n1}
-> j:nat{j < n2}
-> i':nat{i' < n1}
-> j':nat{j' < n2}
-> Lemma (((i', j') <> (i, j) ==> (i' * n2 + j' <> i * n2 + j) /\ i' * n2 + j' < n1 * n2))
let index_neq #n1 #n2 i j i' j' =
index_lt n1 n2 i' j';
assert (i' * n2 + j' < n1 * n2);
if i' < i then
calc (<) {
i' * n2 + j';
(<) { }
i' * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i' 1 n2 }
(i' + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i' + 1) i }
i * n2;
(<=) { }
i * n2 + j;
}
else if i = i' then ()
else
calc (<) {
i * n2 + j;
(<) { }
i * n2 + n2;
(==) { Math.Lemmas.distributivity_add_left i 1 n2 }
(i + 1) * n2;
(<=) { Math.Lemmas.lemma_mult_le_right n2 (i + 1) i' }
i' * n2;
(<=) { }
i' * n2 + j';
}
/// Matrices as flat sequences
unfold
let elem = uint16
unfold
let matrix (n1:size_nat) (n2:size_nat{n1 * n2 <= max_size_t}) = LSeq.lseq elem (n1 * n2)
val create: n1:size_nat -> n2:size_nat{n1 * n2 <= max_size_t} -> matrix n1 n2
let create n1 n2 = LSeq.create (n1 * n2) (u16 0)
val mget:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget #n1 #n2 a i j =
index_lt n1 n2 i j;
a.[i * n2 + j]
unfold
let op_Array_Access #n1 #n2 (m:matrix n1 n2) (i,j) = mget m i j
val mset:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> v:elem
-> Pure (matrix n1 n2)
(requires True)
(ensures fun r ->
r.(i,j) == v /\ (forall i' j'. (i', j') <> (i, j) ==> r.(i', j') == a.(i',j')))
let mset #n1 #n2 a i j v =
Classical.forall_intro_2 (index_neq #n1 #n2 i j);
index_lt n1 n2 i j;
a.[i * n2 + j] <- v
unfold
let op_Array_Assignment #n1 #n2 (m:matrix n1 n2) (i,j) x = mset m i j x
val extensionality:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> Lemma
(requires forall i j. a.(i,j) == b.(i,j))
(ensures a == b)
let extensionality #n1 #n2 a b =
let aux (k:size_nat{k < n1 * n2}) : Lemma (index a k == index b k) =
let i = k / n2 in
let j = k % n2 in
div_mul_lt n2 k n1;
assert (i < n1 /\ j < n2);
index_lt n1 n2 i j;
assert (a.(i, j) == a.[i * n2 + j] /\ b.(i, j) == b.[i * n2 + j]);
assert (a.[k] == b.[k]) in
Classical.forall_intro aux;
eq_intro a b;
eq_elim a b
(*
/// Example (of course it doesn't work with Lib.IntTypes)
/// [ 0 2 ]
/// [ 1 3 ]
let m:matrix 2 2 =
assert_norm (List.length [0us; 2us; 1us; 3us] == 4);
Seq.seq_of_list [0us; 2us; 1us; 3us]
let _ = assert_norm (m.(0,0) == 0us /\ m.(1,0) == 1us /\ m.(0,1) == 2us /\ m.(1,1) == 3us)
let _ = assert_norm (let m' = m.(0,0) <- 4us in m'.(0,0) == 4us)
*)
val map:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem)
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) }
let map #n1 #n2 f a =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j))
c)
c
val mod_pow2_felem: logq:size_pos{logq < 16} -> a:elem
-> Pure elem
(requires true)
(ensures fun r -> v r == v a % pow2 logq)
let mod_pow2_felem logq a =
Math.Lemmas.pow2_lt_compat 16 logq;
mod_mask_lemma #U16 a (size logq);
assert (v (mod_mask #U16 #SEC (size logq)) == v ((u16 1 <<. size logq) -. u16 1));
a &. ((u16 1 <<. size logq) -. u16 1)
val mod_pow2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> logq:size_pos{logq <= 16}
-> a:matrix n1 n2
-> c:matrix n1 n2{ forall i j. v c.(i,j) == v a.(i,j) % pow2 logq }
let mod_pow2 #n1 #n2 logq a =
if logq < 16 then
map (mod_pow2_felem logq) a
else a
val map2:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> f:(elem -> elem -> elem)
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == f a.(i,j) b.(i,j) }
let map2 #n1 #n2 f a b =
let c = create n1 n2 in
Loops.repeati_inductive n1
(fun i c -> forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c.(i0,j) == f a.(i0,j) b.(i0,j))
(fun i c ->
Loops.repeati_inductive n2
(fun j c0 ->
(forall (i0:size_nat{i0 < i}) (j:size_nat{j < n2}). c0.(i0,j) == c.(i0,j)) /\
(forall (j0:size_nat{j0 < j}). c0.(i,j0) == f a.(i,j0) b.(i,j0)))
(fun j c' -> c'.(i,j) <- f a.(i,j) b.(i,j))
c)
c
val add:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) +. b.(i,j) }
let add #n1 #n2 a b =
map2 add_mod a b
val sub:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n1 n2
-> c:matrix n1 n2{ forall i j. c.(i,j) == a.(i,j) -. b.(i,j) }
let sub #n1 #n2 a b =
map2 sub_mod a b
val sum_:
#n:size_nat
-> f:(j:size_nat{j < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> GTot uint16
(decreases i)
let rec sum_ #n f i =
if i = 0 then u16 0
else sum_ #n f (i - 1) +. f (i - 1)
let sum #n f = sum_ #n f n
#push-options "--fuel 1"
val sum_extensionality:
n:size_nat
-> f:(i:size_nat{i < n} -> GTot uint16)
-> g:(i:size_nat{i < n} -> GTot uint16)
-> i:size_nat{i <= n}
-> Lemma
(requires forall (i:size_nat{i < n}). f i == g i)
(ensures sum_ #n f i == sum_ #n g i)
(decreases i)
let rec sum_extensionality n f g i =
if i = 0 then ()
else sum_extensionality n f g (i - 1)
val mul_inner:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul_inner #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. b.(l, k) in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. b.(j, k)
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. b.(l, k)) n2;
res
#pop-options
val mul:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. b.(l, k))}
let mul #n1 #n2 #n3 a b =
let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c -> forall (i1:size_nat{i1 < i}) (k:size_nat{k < n3}). c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. b.(l, k)))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 -> (forall (k1:size_nat{k1 < k}). c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. b.(l, k1))) /\
(forall (i1:size_nat{i1 < n1 /\ i <> i1}) (k:size_nat{k < n3}). c0.(i1, k) == c.(i1, k)))
(fun k c0 ->
c0.(i, k) <- mul_inner #n1 #n2 #n3 a b i k
) c
) c
val mget_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> a:matrix n1 n2
-> i:size_nat{i < n1}
-> j:size_nat{j < n2}
-> elem
let mget_s #n1 #n2 a i j =
index_lt n2 n1 j i;
a.[j * n1 + i]
#push-options "--fuel 1"
val mul_inner_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> i:size_nat{i < n1}
-> k:size_nat{k < n3}
-> res:uint16{res == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)}
let mul_inner_s #n1 #n2 #n3 a b i k =
let f l = a.(i, l) *. mget_s b l k in
let res =
Loops.repeati_inductive n2
(fun j res -> res == sum_ #n2 f j)
(fun j res ->
res +. a.(i, j) *. mget_s b j k
) (u16 0) in
sum_extensionality n2 f (fun l -> a.(i, l) *. mget_s b l k) n2;
res
#pop-options
val mul_s:
#n1:size_nat
-> #n2:size_nat{n1 * n2 <= max_size_t}
-> #n3:size_nat{n1 * n3 <= max_size_t /\ n2 * n3 <= max_size_t}
-> a:matrix n1 n2
-> b:matrix n2 n3
-> c:matrix n1 n3{ forall i k. c.(i, k) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k)} | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Matrix.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Matrix.matrix n1 n2 -> b: Spec.Matrix.matrix n2 n3
-> c:
Spec.Matrix.matrix n1 n3
{ forall (i: Lib.IntTypes.size_nat{i < n1}) (k: j: Lib.IntTypes.size_nat{j < n3}).
c.(i, k) == Spec.Matrix.sum (fun l -> a.(i, l) *. Spec.Matrix.mget_s b l k) } | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.l_and",
"Spec.Matrix.matrix",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.IntTypes.uint16",
"Spec.Matrix.op_Array_Access",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Matrix.sum",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Spec.Matrix.mget_s",
"Prims.op_disEquality",
"Prims.l_or",
"Spec.Matrix.elem",
"Spec.Matrix.op_Array_Assignment",
"Spec.Matrix.mul_inner_s",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.op_Multiply",
"Spec.Matrix.create"
] | [] | false | false | false | false | false | let mul_s #n1 #n2 #n3 a b =
| let c = create n1 n3 in
Loops.repeati_inductive n1
(fun i c ->
forall (i1: size_nat{i1 < i}) (k: size_nat{k < n3}).
c.(i1, k) == sum #n2 (fun l -> a.(i1, l) *. mget_s b l k))
(fun i c ->
Loops.repeati_inductive n3
(fun k c0 ->
(forall (k1: size_nat{k1 < k}).
c0.(i, k1) == sum #n2 (fun l -> a.(i, l) *. mget_s b l k1)) /\
(forall (i1: size_nat{i1 < n1 /\ i <> i1}) (k: size_nat{k < n3}).
c0.(i1, k) == c.(i1, k)))
(fun k c0 -> c0.(i, k) <- mul_inner_s #n1 #n2 #n3 a b i k)
c)
c | false |
LowParse.Low.Int32le.fst | LowParse.Low.Int32le.read_int32le | val read_int32le:leaf_reader parse_int32le | val read_int32le:leaf_reader parse_int32le | let read_int32le : leaf_reader parse_int32le
= make_total_constant_size_reader 4 4ul decode_int32le (decode_int32le_total_constant ()) (fun #rrel #rel b pos ->
let h = HST.get () in
assert ((U32.v pos + 4) <= Seq.length (B.as_seq h b));
[@inline_let] let _ = decode_int32le_eq (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)) in
let r0 = B.index b pos in
let r1 = B.index b (pos `U32.add` 1ul) in
let r2 = B.index b (pos `U32.add` 2ul) in
let r3 = B.index b (pos `U32.add` 3ul) in
Cast.uint8_to_uint32 r0 `U32.add` (256ul `U32.mul` (Cast.uint8_to_uint32 r1 `U32.add` (256ul `U32.mul` (Cast.uint8_to_uint32 r2 `U32.add` (256ul `U32.mul` Cast.uint8_to_uint32 r3)))))
) | {
"file_name": "src/lowparse/LowParse.Low.Int32le.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 25,
"start_col": 0,
"start_line": 15
} | module LowParse.Low.Int32le
(* LowParse implementation module for 32 bits little endian integers *)
include LowParse.Low.Combinators
include LowParse.Spec.Int32le
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Int32le.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Low.Base.leaf_reader LowParse.Spec.Int32le.parse_int32le | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Combinators.make_total_constant_size_reader",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.t",
"LowParse.Spec.Int32le.decode_int32le",
"LowParse.Spec.Int32le.decode_int32le_total_constant",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.add",
"FStar.Int.Cast.uint8_to_uint32",
"FStar.UInt32.mul",
"LowStar.Monotonic.Buffer.index",
"Prims.unit",
"LowParse.Spec.Int32le.decode_int32le_eq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt32.v",
"Prims.op_Addition",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let read_int32le:leaf_reader parse_int32le =
| make_total_constant_size_reader 4
4ul
decode_int32le
(decode_int32le_total_constant ())
(fun #rrel #rel b pos ->
let h = HST.get () in
assert ((U32.v pos + 4) <= Seq.length (B.as_seq h b));
[@@ inline_let ]let _ =
decode_int32le_eq (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4))
in
let r0 = B.index b pos in
let r1 = B.index b (pos `U32.add` 1ul) in
let r2 = B.index b (pos `U32.add` 2ul) in
let r3 = B.index b (pos `U32.add` 3ul) in
(Cast.uint8_to_uint32 r0)
`U32.add`
(256ul
`U32.mul`
((Cast.uint8_to_uint32 r1)
`U32.add`
(256ul
`U32.mul`
((Cast.uint8_to_uint32 r2) `U32.add` (256ul `U32.mul` (Cast.uint8_to_uint32 r3))))))) | false |
Binding.fst | Binding.check_expr | val check_expr (env: env) (e: expr) : ML (expr & typ) | val check_expr (env: env) (e: expr) : ML (expr & typ) | let rec check_typ (pointer_ok:bool) (env:env) (t:typ)
: ML typ
= match t.v with
| Pointer t0 ->
if pointer_ok
then { t with v = Pointer (check_typ pointer_ok env t0) }
else error (Printf.sprintf "Pointer types are not permissible here; got %s" (print_typ t)) t.range
| Type_app s KindSpec ps ->
(match lookup env s with
| Inl _ ->
error (Printf.sprintf "%s is not a type" (ident_to_string s)) s.range
| Inr (d, _) ->
let params = params_of_decl d in
if List.length params <> List.length ps
then error (Printf.sprintf "Not enough arguments to %s" (ident_to_string s)) s.range;
let ps =
List.map2 (fun (t, _, _) p ->
let p, t' = check_typ_param env p in
if not (eq_typ env t t')
then begin
match p with
| Inl e -> (match try_cast_integer env (e, t') t with
| Some e -> Inl e
| _ -> error "Argument type mismatch after trying integer cast" (range_of_typ_param p))
| _ ->
error (Printf.sprintf
"Argument type mismatch (%s vs %s)"
(Ast.print_typ t) (Ast.print_typ t')) (range_of_typ_param p)
end
else p)
params
ps
in
{t with v = Type_app s KindSpec ps})
| Type_app i KindExtern args ->
if List.length args <> 0
then error (Printf.sprintf "Cannot apply the extern type %s" (ident_to_string i)) i.range
else t
| Type_app _ KindOutput _ ->
error "Impossible, check_typ is not supposed to typecheck output types!" t.range
and check_ident (env:env) (i:ident)
: ML (ident & typ)
= let t = lookup_expr_name env i in
i, t
and check_expr (env:env) (e:expr)
: ML (expr & typ)
= let w e' = with_range e' e.range in
let arith_op_t op t : ML Ast.op =
let t = tag_of_integral_typ env t in
match op with
| Plus _ -> Plus t
| Minus _ -> Minus t
| Mul _ -> Mul t
| Division _ -> Division t
| Remainder _ -> Remainder t
| BitwiseNot _ -> BitwiseNot t
| BitwiseAnd _ -> BitwiseAnd t
| BitwiseOr _ -> BitwiseOr t
| BitwiseXor _ -> BitwiseXor t
| ShiftLeft _ -> ShiftLeft t
| ShiftRight _ -> ShiftRight t
| LE _ -> LE t
| LT _ -> LT t
| GE _ -> GE t
| GT _ -> GT t
| _ -> op
in
match e.v with
| Constant c ->
e, type_of_constant e.range c
| Identifier i ->
let i, t = check_ident env i in
{ e with v = Identifier i }, t
| Static _ ->
failwith "Static expressions should have been desugared already"
| This ->
error "`this` is not a valid expression" e.range
| App (Cast _ to) [n] ->
let n, from = check_expr env n in
begin
if not (typ_is_integral env from)
then error (Printf.sprintf "Casts are only supported on integral types; %s is not integral"
(print_typ from)) e.range
else match from.v with
| Type_app i KindSpec _ ->
let from_t = as_integer_typ i in
// if integer_type_lub to from_t <> to
// then error (Printf.sprintf "Only widening casts are supported; casting %s to %s loses precision"
// (print_typ from)
// (print_integer_type to))
// e.range
// else
let e = {e with v = App (Cast (Some from_t) to) [n]} in
let t = type_of_integer_type to in
Options.debug_print_string
(Printf.sprintf "--------------- %s has type %s\n" (print_expr e) (print_typ t));
e, t
| _ -> failwith "Impossible: must be an integral type"
end
| App SizeOf [{v=This;range=r}] ->
let e =
match env.this with
| None ->
error "`this` is not in scope" r
| Some i ->
with_range (App SizeOf [with_range (Identifier i) r]) e.range
in
e, tuint32
| App SizeOf [{v=Identifier i;range=r}] ->
begin
match lookup env i with
| Inr ({d_decl={v=Enum _ _ _}}, _)
| Inr ({d_decl={v=Record _ _ _ _ }}, _)
| Inr ({d_decl={v=CaseType _ _ _}}, _)
| Inr (_, Inl _) -> //has decl-attributes
e, tuint32
| _ ->
error "`sizeof` applied to a non-sized-typed" r
end
| App (Ext s) es ->
//TODO: AR: not sure about this Ext node
let m = lookup_macro_name env (with_range (to_ident' s) e.range) in
let n_formals = List.length m.macro_arguments_t in
let n_actuals = List.length es in
if n_formals <> n_actuals
then error (Printf.sprintf "%s expects %d arguments; got %d" s n_formals n_actuals) e.range;
let check_arg e t : ML expr =
let e, t' = check_expr env e in
if not (eq_typ env t t')
then error
(Printf.sprintf
"%s expected argument of type %s; \
got argument %s of type %s"
s (print_typ t) (print_expr e) (print_typ t))
e.range;
e
in
let es = List.map2 check_arg es m.macro_arguments_t in
with_range (App (Ext s) es) e.range,
m.macro_result_t
| App op es ->
let ets = List.map (check_expr env) es in
match ets with
| [(e1, t1)] ->
begin
match op with
| Not ->
if not (eq_typ env t1 tbool)
then error "Expected bool" e1.range;
w (App Not [e1]), t1
| BitwiseNot _ ->
if typ_is_integral env t1
then w (App (arith_op_t op t1) [e1]), t1
else error (Printf.sprintf "Bitwise negation is only available on integral types; got %s"
(print_typ t1))
e1.range
| _ ->
error "Not a unary op" e1.range
end
| [(e1,t1);(e2,t2)] ->
begin
match op with
| Eq
| Neq ->
if not (eq_typ env t1 t2)
then
begin
let err #a () : ML a =
error
(Printf.sprintf "Equality on unequal types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range
in
let it1 = typ_is_integral env t1 in
let it2 = typ_is_integral env t2 in
if it1 && it2
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App op [e1; e2]), tbool
| _ -> err ()
else err ()
end
else
w (App op [e1; e2]), tbool
| And
| Or ->
if not (eq_typs env [(t1,tbool); (t2,tbool)])
then error "Binary boolean op on non booleans" e.range;
w (App op [e1; e2]), tbool
| ShiftLeft _
| ShiftRight _ ->
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Bit shifts are only permissible on integral types: got %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
begin
match try_cast_integer env (e2, t2) tuint32 with
| None ->
error (Printf.sprintf "Bit shift offset is too large: got type %s"
(print_typ t2))
e2.range
| Some e2 ->
w (App (arith_op_t op t1) [e1; e2]), t1
end
| Plus _
| Minus _
| Mul _
| Division _
| Remainder _
| LT _
| GT _
| LE _
| GE _
| BitwiseAnd _
| BitwiseOr _
| BitwiseXor _ ->
let result_typ t =
match op with
| LT _ | GT _ | LE _ | GE _ -> tbool
| _ -> t
in
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Binary integer op on non-integral types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
if not (eq_typs env [(t1,t2)])
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) ->
w (App (arith_op_t op t) [e1; e2]), result_typ t
| _ ->
error (Printf.sprintf "Binary integer operator (%s) on non-equal types: %s and %s"
(print_expr e)
(print_typ t1)
(print_typ t2))
e.range
else w (App (arith_op_t op t1) [e1; e2]), result_typ t1
| _ ->
error "Not a binary op" e.range
end
| [(e1, t1); (e2, t2); (e3, t3)] ->
begin
match op with
| IfThenElse ->
if not (eq_typ env t1 tbool)
then error (Printf.sprintf "If-then-else expects a boolean guard, got %s" (print_typ t1))
e1.range;
if not (eq_typ env t2 t3)
then match try_retype_arith_exprs env (e2, t2) (e3, t3) e.range with
| Some (e2, e3, t) ->
w (App IfThenElse [e1;e2;e3]), t
| None ->
error (Printf.sprintf "then- and else-branch do not have the same type: got %s and %s"
(print_typ t2)
(print_typ t3))
e.range
else
w (App IfThenElse [e1;e2;e3]), t2
| BitFieldOf n order ->
let base_size = size_of_integral_typ env t1 e1.range in
let size = 8 * base_size in
if n <> size
then error
(Printf.sprintf "BitFieldOf size %d is not equal to %d, i.e., the bit size %s"
n size (print_expr e1))
e1.range;
begin
match e2.v, e3.v with
| Constant (Int UInt32 from), (Constant (Int UInt32 to)) ->
if not
(from <= size
&& from <= to
&& to <= size)
then error "bitfield-of expresssions is out of bounds" e.range;
w (App (BitFieldOf n order) [e1; e2; e3]), t1
| _ ->
error "bitfield-of with non-32-bit-consant indices" e.range
end
| _ ->
error "Unexpected arity" e.range
end
| _ -> error "Unexpected arity" e.range
and check_typ_param (env:env) (p:typ_param) : ML (typ_param & typ) =
match p with
| Inl e ->
let e, t = check_expr env e in
Inl e, t
| Inr o ->
let o = check_out_expr env o in
let { out_expr_t = t;
out_expr_bit_width = bopt } = Some?.v o.out_expr_meta in
(match bopt with
| None ->
Inr o, t
| _ ->
error ("Type parameter cannot be a bitfield") (range_of_typ_param p)) | {
"file_name": "src/3d/Binding.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 954,
"start_col": 0,
"start_line": 625
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Binding
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
include GlobalEnv
/// Maps locally bound names, i.e., a field name to its type
/// -- the bool signifies that this identifier has been used, and is
/// therefore marked as a dependent field
///
/// The modul_name in these ident' must be None -- TODO: add a refinement?
let local_env = H.t ident' (ident' & typ & bool)
/// `env` includes both a global and local env, together with a
/// binding for the `this` variable (bound to the name of a type) in
/// the current scope
noeq
type env = {
this: option ident;
locals: local_env;
globals: global_env;
}
let mk_env (g:global_env) =
{ this = None;
locals = H.create 10;
globals = g }
let copy_env (e:env) =
let locals = H.create 10 in
H.iter (fun k v -> H.insert locals k v) e.locals;
{
this = e.this;
globals = e.globals;
locals = locals
}
#push-options "--warn_error -272" //intentional top-level effect
let env_of_global_env
: global_env -> env
= let locals = H.create 1 in
fun g -> { this = None; locals; globals = g }
#pop-options
let global_env_of_env e = e.globals
let params_of_decl (d:decl) : list param =
match d.d_decl.v with
| ModuleAbbrev _ _
| Define _ _ _
| TypeAbbrev _ _
| Enum _ _ _ -> []
| Record _ params _ _
| CaseType _ params _ -> params
| OutputType _ -> []
| ExternType _ -> []
| ExternFn _ _ ps -> ps
| ExternProbe _ -> []
let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) =
match H.try_find e i.v with
| Some j ->
let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in
error msg i.range
| _ -> ()
let typedef_names (d:decl) : option typedef_names =
match d.d_decl.v with
| Record td _ _ _
| CaseType td _ _ -> Some td
| _ -> None
let format_identifier (e:env) (i:ident) : ML ident =
let j =
match String.list_of_string i.v.name with
| [] ->
failwith "Impossible: empty identifier"
| c0::cs ->
if FStar.Char.lowercase c0 = c0
then i //it starts with a lowercase symbol; that's ok
else //otherwise, add an underscore
{i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}}
in
match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with
| None, None -> j
| _ ->
let msg = Printf.sprintf
"This name (%s) starts will clash with another name in scope (%s) as it is translated. \
Please rename it"
(ident_to_string i) (ident_to_string j) in
error msg i.range
let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit =
let insert k v = H.insert e.ge_h k v in
check_shadow e.ge_h i d.d_decl.range;
let env = mk_env e in
let i' = format_identifier env i in
insert i.v (d, t);
insert i'.v (d, t);
match typedef_names d with
| None -> ()
| Some td ->
if td.typedef_abbrev.v <> i.v
then begin
check_shadow e.ge_h td.typedef_abbrev d.d_decl.range;
let abbrev = format_identifier env td.typedef_abbrev in
insert td.typedef_abbrev.v (d, t);
insert abbrev.v (d, t)
end
let add_local (e:env) (i:ident) (t:typ) : ML unit =
check_shadow e.globals.ge_h i t.range;
check_shadow e.locals i t.range;
let i' = format_identifier e i in
H.insert e.locals i.v (i'.v, t, false);
H.insert e.locals i'.v (i'.v, t, false)
let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) =
match H.try_find e.locals i.v with
| Some (_, t, true) ->
Some (Inl t)
| Some (j, t, false) -> //mark it as used
H.remove e.locals i.v;
H.insert e.locals i.v (j, t, true);
Some (Inl t)
| None ->
match H.try_find e.globals.ge_h i.v with
| Some d -> Some (Inr d)
| None -> None
let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) =
match try_lookup e i with
| None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
| Some v -> v
let remove_local (e:env) (i:ident) : ML unit =
match H.try_find e.locals i.v with
| Some (j, _, _) ->
H.remove e.locals i.v;
H.remove e.locals j
| _ -> ()
let resolve_record_case_output_extern_type_name (env:env) (i:ident) =
match H.try_find (global_env_of_env env).ge_out_t i.v with
| Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev
| _ ->
(match H.try_find (global_env_of_env env).ge_extern_t i.v with
| Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev
| _ ->
(match lookup env i with
| Inr ({d_decl={v=Record names _ _ _}}, _)
| Inr ({d_decl={v=CaseType names _ _}}, _) ->
names.typedef_name
| _ -> i))
let lookup_expr_name (e:env) (i:ident) : ML typ =
match lookup e i with
| Inl t -> t
| Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t
| Inr _ ->
error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
let lookup_macro_name (e:env) (i:ident) : ML macro_signature =
match lookup e i with
| Inr (_, Inr m) -> m
| _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
let lookup_macro_definition (e:env) (i:ident) =
try
let m = lookup_macro_name e i in
m.macro_defn_t
with
| _ -> None
let try_lookup_enum_cases (e:env) (i:ident)
: ML (option (list ident & typ))
= match lookup e i with
| Inr ({d_decl={v=Enum t _ tags}}, _) ->
Some (Desugar.check_desugared_enum_cases tags, t)
| _ -> None
let lookup_enum_cases (e:env) (i:ident)
: ML (list ident & typ)
= match try_lookup_enum_cases e i with
| Some (tags, t) -> tags, t
| _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
let is_enum (e:env) (t:typ) =
match t.v with
| Type_app i KindSpec [] ->
Some? (try_lookup_enum_cases e i)
| _ -> false
let is_used (e:env) (i:ident) : ML bool =
match H.try_find e.locals i.v with
| Some (_, t, b) -> b
| _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
let type_of_integer_type = function
| UInt8 -> tuint8
| UInt16 -> tuint16
| UInt32 -> tuint32
| UInt64 -> tuint64
let check_integer_bounds t i =
match t with
| UInt8 -> FStar.UInt.fits i 8
| UInt16 -> FStar.UInt.fits i 16
| UInt32 -> FStar.UInt.fits i 32
| UInt64 -> FStar.UInt.fits i 64
let type_of_constant rng (c:constant) : ML typ =
match c with
| Unit -> tunit
| Int tag i ->
if check_integer_bounds tag i
then type_of_integer_type tag
else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng
| XInt tag _ -> //bounds checked by the syntax
type_of_integer_type tag
| Bool _ -> tbool
let parser_may_fail (env:env) (t:typ) : ML bool =
match t.v with
| Pointer _ -> true
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> attrs.may_fail
| _ -> false
let typ_is_integral env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> Some? attrs.integral
| _ -> false
let tag_of_integral_typ env (t:typ) : ML (option _) =
match t.v with
| Pointer _ -> None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral
| _ -> None
let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) =
match t.v with
| Pointer _ -> None, None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order
| _ -> None, None
let has_reader (env:global_env) (id:ident) : ML bool =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.has_reader
| _ -> false
let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.parser_kind_nz
| _ -> None
let parser_weak_kind (env:global_env) (id:ident) : ML (option _) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> Some attrs.parser_weak_kind
| _ -> None
let rec typ_weak_kind env (t:typ) : ML (option weak_kind) =
match t.v with
| Pointer _ -> typ_weak_kind env tuint64
| Type_app hd _ _ -> parser_weak_kind env.globals hd
let typ_has_reader env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
has_reader env.globals hd
let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match try_lookup env hd with
| Some (Inr (d, _)) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_only env t
| _ -> t
end
| _ -> t
end
| _ -> t
let update_typ_abbrev (env:env) (i:ident) (t:typ)
: ML unit
= match H.try_find env.globals.ge_h i.v with
| Some (d, ms) ->
let d_decl =
match d.d_decl.v with
| TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i }
| _ -> failwith "Expected a type abbreviation"
in
let d = {d with d_decl = d_decl } in
let entry = (d, ms) in
H.insert env.globals.ge_h i.v entry
| _ ->
failwith "Type abbreviation not found"
let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match lookup env hd with
| Inr (d, _) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t
| Enum t _ _ -> unfold_typ_abbrev_and_enum env t
| _ -> t
end
| _ -> t
end
| _ -> t
let size_of_integral_typ (env:env) (t:typ) r
: ML int
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_of_integral_typ env t with
| None -> failwith "Impossible"
| Some UInt8 -> 1
| Some UInt16 -> 2
| Some UInt32 -> 4
| Some UInt64 -> 8
let bit_order_of_integral_typ (env:env) (t:typ) r
: ML bitfield_bit_order
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_and_bit_order_of_integral_typ env t with
| _, None -> failwith "Impossible"
| _, Some order -> order
let eq_typ env t1 t2 =
if Ast.eq_typ t1 t2 then true
else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
let eq_typs env ts =
List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
let cast e t t' = { e with v = App (Cast (Some t) t') [e] }
let try_cast_integer env et to : ML (option expr) =
let e, from = et in
let i_to = typ_is_integral env to in
let i_from = typ_is_integral env from in
if i_from && i_to
then
let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in
let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in
if i_from = i_to
then Some e
else if integer_type_leq i_from i_to
then Some (cast e i_from i_to)
else None
else None
let _or_ b1 b2 = b1 || b2
let _and_ b1 b2 = b1 && b2
let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))=
let e1, t1 = e1 in
let e2, t2 = e2 in
let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)"
i
(print_expr e1)
(print_typ t1)
(print_expr e2)
(print_typ t2))) in
try
let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in
if not (typ_is_integral env t1 `_and_`
typ_is_integral env t2)
then fail 1;
let tt1 = typ_as_integer_type t1 in
let tt2 = typ_as_integer_type t2 in
let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in
let e1, e2, t =
if integer_type_leq tt1 tt2
then cast e1 tt1 tt2,
e2,
t2
else if integer_type_leq tt2 tt1
then e1,
cast e2 tt2 tt1,
t1
else fail 0
in
// FStar.IO.print_string
// (Printf.sprintf "Retyped to (%s, %s, %s)\n"
// (print_expr e1)
// (print_expr e2)
// (print_typ t));
Some (e1, e2, t)
with
| Error msg ->
FStar.IO.print_string msg;
None
| _ -> None
(*
* Add output type to the environment
*
* TODO: check_shadow
*)
let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_out_t i d in
insert i.v;
let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in
insert td_abbrev.v
(*
* Add extern type to the environment
*
* TODO: check shadow
*)
let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_extern_t i d in
insert i.v;
let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in
insert td_abbrev.v
(*
* Add extern probe function to the environment
*
* TODO: check shadow
*)
let add_extern_probe (ge:global_env) (i:ident) (d:decl{ExternProbe? d.d_decl.v}) : ML unit =
H.insert ge.ge_probe_fn i.v d
(*
* Add extern function to the environment
*
* TODO: check shadow
*)
let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit =
H.insert ge.ge_extern_fn i.v d
let lookup_output_type (ge:global_env) (i:ident) : ML out_typ =
match H.try_find ge.ge_out_t i.v with
| Some ({d_decl={v=OutputType out_t}}) -> out_t
| _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range
(*
* Returns the type of the field, with optional bitwidth if the field is a bitfield
*)
let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) =
let out_t = lookup_output_type ge i in
let rec find (flds:list out_field) : (option (typ & option int)) =
match flds with
| [] -> None
| (Out_field_named f' t n)::tl ->
if eq_idents f f' then Some (t, n)
else find tl
| (Out_field_anon l _)::tl ->
(match find l with
| None -> find tl
| Some t -> Some t) in
match find out_t.out_typ_fields with
| Some t -> t
| None ->
error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range
let lookup_extern_type (ge:global_env) (i:ident) : ML unit =
match H.try_find ge.ge_extern_t i.v with
| Some ({d_decl={v=ExternType _}}) -> ()
| _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) =
match H.try_find ge.ge_extern_fn f.v with
| Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps
| _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
let check_output_type (ge:global_env) (t:typ) : ML ident =
let err () : ML ident =
error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in
match t.v with
| Type_app i KindOutput [] -> i
| _ -> err ()
/// Populated the output expression metadata
///
/// We enforce that the spec cannot take address of output type bitfields
let rec check_out_expr (env:env) (oe0:out_expr)
: ML (oe:out_expr{Some? oe.out_expr_meta}) =
match oe0.out_expr_node.v with
| OE_id i ->
let t = lookup_expr_name env i in
{oe0 with
out_expr_meta = Some ({
out_expr_base_t = t;
out_expr_t = t;
out_expr_bit_width = None})}
| OE_star oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_star oe};
out_expr_meta=Some ({ out_expr_base_t = oe_bt;
out_expr_t = t;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_addrof oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_addrof oe};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
| OE_deref oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
let i = check_output_type (global_env_of_env env) t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_deref oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_dot oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
let i = check_output_type (global_env_of_env env) oe_t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_dot oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
let range_of_typ_param (p:typ_param) = match p with
| Inl e -> e.range
| Inr p -> p.out_expr_node.range | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Options.fsti.checked",
"Hashtable.fsti.checked",
"GlobalEnv.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Binding.fst"
} | [
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Binding.env -> e: Ast.expr -> FStar.All.ML (Ast.expr * Ast.typ) | FStar.All.ML | [
"ml"
] | [
"check_typ",
"check_ident",
"check_expr",
"check_typ_param"
] | [
"Binding.env",
"Ast.expr",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.expr'",
"Ast.constant",
"FStar.Pervasives.Native.Mktuple2",
"Ast.typ",
"FStar.Pervasives.Native.tuple2",
"Binding.type_of_constant",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.ident",
"Ast.Mkwith_meta_t",
"Ast.Identifier",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Binding.check_ident",
"Ast.with_meta_t",
"FStar.All.failwith",
"Ast.error",
"FStar.Pervasives.Native.option",
"Ast.integer_type",
"Prims.string",
"FStar.Printf.sprintf",
"Ast.print_typ",
"Prims.bool",
"Ast.typ'",
"Prims.list",
"Ast.either",
"Ast.out_expr",
"Prims.unit",
"Options.debug_print_string",
"Ast.print_expr",
"Binding.type_of_integer_type",
"Ast.App",
"Ast.Cast",
"FStar.Pervasives.Native.Some",
"Prims.Cons",
"Prims.Nil",
"Ast.as_integer_typ",
"Prims.op_Negation",
"Binding.typ_is_integral",
"Binding.check_expr",
"Ast.range",
"Ast.comments",
"Ast.tuint32",
"Binding.__proj__Mkenv__item__this",
"Ast.with_range",
"Ast.SizeOf",
"Ast.enum_case",
"GlobalEnv.decl_attributes",
"GlobalEnv.macro_signature",
"Ast.typedef_names",
"Ast.param",
"Ast.record",
"Ast.switch_case",
"Ast.decl",
"Binding.lookup",
"Ast.Ext",
"GlobalEnv.__proj__Mkmacro_signature__item__macro_result_t",
"FStar.List.map2",
"GlobalEnv.__proj__Mkmacro_signature__item__macro_arguments_t",
"Binding.eq_typ",
"Prims.op_disEquality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Binding.lookup_macro_name",
"Ast.ident'",
"Ast.to_ident'",
"Ast.op",
"Ast.Not",
"Ast.tbool",
"Prims.op_AmpAmp",
"FStar.Pervasives.Native.tuple3",
"Binding.try_retype_arith_exprs",
"Binding.eq_typs",
"Binding.try_cast_integer",
"Prims.op_BarBar",
"Ast.IfThenElse",
"Prims.int",
"Ast.bitfield_bit_order",
"Ast.BitFieldOf",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Binding.size_of_integral_typ",
"FStar.List.map",
"Ast.Plus",
"Ast.Minus",
"Ast.Mul",
"Ast.Division",
"Ast.Remainder",
"Ast.BitwiseNot",
"Ast.BitwiseAnd",
"Ast.BitwiseOr",
"Ast.BitwiseXor",
"Ast.ShiftLeft",
"Ast.ShiftRight",
"Ast.LE",
"Ast.LT",
"Ast.GE",
"Ast.GT",
"Binding.tag_of_integral_typ"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec check_expr (env: env) (e: expr) : ML (expr & typ) =
| let w e' = with_range e' e.range in
let arith_op_t op t : ML Ast.op =
let t = tag_of_integral_typ env t in
match op with
| Plus _ -> Plus t
| Minus _ -> Minus t
| Mul _ -> Mul t
| Division _ -> Division t
| Remainder _ -> Remainder t
| BitwiseNot _ -> BitwiseNot t
| BitwiseAnd _ -> BitwiseAnd t
| BitwiseOr _ -> BitwiseOr t
| BitwiseXor _ -> BitwiseXor t
| ShiftLeft _ -> ShiftLeft t
| ShiftRight _ -> ShiftRight t
| LE _ -> LE t
| LT _ -> LT t
| GE _ -> GE t
| GT _ -> GT t
| _ -> op
in
match e.v with
| Constant c -> e, type_of_constant e.range c
| Identifier i ->
let i, t = check_ident env i in
{ e with v = Identifier i }, t
| Static _ -> failwith "Static expressions should have been desugared already"
| This -> error "`this` is not a valid expression" e.range
| App (Cast _ to) [n] ->
let n, from = check_expr env n in
if not (typ_is_integral env from)
then
error (Printf.sprintf "Casts are only supported on integral types; %s is not integral"
(print_typ from))
e.range
else
(match from.v with
| Type_app i KindSpec _ ->
let from_t = as_integer_typ i in
let e = { e with v = App (Cast (Some from_t) to) [n] } in
let t = type_of_integer_type to in
Options.debug_print_string (Printf.sprintf "--------------- %s has type %s\n"
(print_expr e)
(print_typ t));
e, t
| _ -> failwith "Impossible: must be an integral type")
| App SizeOf [{ v = This ; range = r }] ->
let e =
match env.this with
| None -> error "`this` is not in scope" r
| Some i -> with_range (App SizeOf [with_range (Identifier i) r]) e.range
in
e, tuint32
| App SizeOf [{ v = Identifier i ; range = r }] ->
(match lookup env i with
| Inr ({ d_decl = { v = Enum _ _ _ } }, _)
| Inr ({ d_decl = { v = Record _ _ _ _ } }, _)
| Inr ({ d_decl = { v = CaseType _ _ _ } }, _)
| Inr (_, Inl _) -> e, tuint32
| _ -> error "`sizeof` applied to a non-sized-typed" r)
| App (Ext s) es ->
let m = lookup_macro_name env (with_range (to_ident' s) e.range) in
let n_formals = List.length m.macro_arguments_t in
let n_actuals = List.length es in
if n_formals <> n_actuals
then error (Printf.sprintf "%s expects %d arguments; got %d" s n_formals n_actuals) e.range;
let check_arg e t : ML expr =
let e, t' = check_expr env e in
if not (eq_typ env t t')
then
error (Printf.sprintf "%s expected argument of type %s; got argument %s of type %s"
s
(print_typ t)
(print_expr e)
(print_typ t))
e.range;
e
in
let es = List.map2 check_arg es m.macro_arguments_t in
with_range (App (Ext s) es) e.range, m.macro_result_t
| App op es ->
let ets = List.map (check_expr env) es in
match ets with
| [e1, t1] ->
(match op with
| Not ->
if not (eq_typ env t1 tbool) then error "Expected bool" e1.range;
w (App Not [e1]), t1
| BitwiseNot _ ->
if typ_is_integral env t1
then w (App (arith_op_t op t1) [e1]), t1
else
error (Printf.sprintf "Bitwise negation is only available on integral types; got %s"
(print_typ t1))
e1.range
| _ -> error "Not a unary op" e1.range)
| [e1, t1 ; e2, t2] ->
(match op with
| Eq
| Neq ->
if not (eq_typ env t1 t2)
then
let err #a () : ML a =
error (Printf.sprintf "Equality on unequal types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range
in
let it1 = typ_is_integral env t1 in
let it2 = typ_is_integral env t2 in
if it1 && it2
then
match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App op [e1; e2]), tbool
| _ -> err ()
else err ()
else w (App op [e1; e2]), tbool
| And
| Or ->
if not (eq_typs env [(t1, tbool); (t2, tbool)])
then error "Binary boolean op on non booleans" e.range;
w (App op [e1; e2]), tbool
| ShiftLeft _
| ShiftRight _ ->
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then
error (Printf.sprintf "Bit shifts are only permissible on integral types: got %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
(match try_cast_integer env (e2, t2) tuint32 with
| None ->
error (Printf.sprintf "Bit shift offset is too large: got type %s" (print_typ t2))
e2.range
| Some e2 -> w (App (arith_op_t op t1) [e1; e2]), t1)
| Plus _
| Minus _
| Mul _
| Division _
| Remainder _
| LT _
| GT _
| LE _
| GE _
| BitwiseAnd _
| BitwiseOr _
| BitwiseXor _ ->
let result_typ t =
match op with
| LT _ | GT _ | LE _ | GE _ -> tbool
| _ -> t
in
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then
error (Printf.sprintf "Binary integer op on non-integral types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
if not (eq_typs env [(t1, t2)])
then
match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App (arith_op_t op t) [e1; e2]), result_typ t
| _ ->
error (Printf.sprintf "Binary integer operator (%s) on non-equal types: %s and %s"
(print_expr e)
(print_typ t1)
(print_typ t2))
e.range
else w (App (arith_op_t op t1) [e1; e2]), result_typ t1
| _ -> error "Not a binary op" e.range)
| [e1, t1 ; e2, t2 ; e3, t3] ->
(match op with
| IfThenElse ->
if not (eq_typ env t1 tbool)
then
error (Printf.sprintf "If-then-else expects a boolean guard, got %s" (print_typ t1))
e1.range;
if not (eq_typ env t2 t3)
then
match try_retype_arith_exprs env (e2, t2) (e3, t3) e.range with
| Some (e2, e3, t) -> w (App IfThenElse [e1; e2; e3]), t
| None ->
error (Printf.sprintf "then- and else-branch do not have the same type: got %s and %s"
(print_typ t2)
(print_typ t3))
e.range
else w (App IfThenElse [e1; e2; e3]), t2
| BitFieldOf n order ->
let base_size = size_of_integral_typ env t1 e1.range in
let size = 8 * base_size in
if n <> size
then
error (Printf.sprintf "BitFieldOf size %d is not equal to %d, i.e., the bit size %s"
n
size
(print_expr e1))
e1.range;
(match e2.v, e3.v with
| Constant (Int UInt32 from), Constant (Int UInt32 to) ->
if not (from <= size && from <= to && to <= size)
then error "bitfield-of expresssions is out of bounds" e.range;
w (App (BitFieldOf n order) [e1; e2; e3]), t1
| _ -> error "bitfield-of with non-32-bit-consant indices" e.range)
| _ -> error "Unexpected arity" e.range)
| _ -> error "Unexpected arity" e.range | false |
Binding.fst | Binding.check_typ | val check_typ (pointer_ok: bool) (env: env) (t: typ) : ML typ | val check_typ (pointer_ok: bool) (env: env) (t: typ) : ML typ | let rec check_typ (pointer_ok:bool) (env:env) (t:typ)
: ML typ
= match t.v with
| Pointer t0 ->
if pointer_ok
then { t with v = Pointer (check_typ pointer_ok env t0) }
else error (Printf.sprintf "Pointer types are not permissible here; got %s" (print_typ t)) t.range
| Type_app s KindSpec ps ->
(match lookup env s with
| Inl _ ->
error (Printf.sprintf "%s is not a type" (ident_to_string s)) s.range
| Inr (d, _) ->
let params = params_of_decl d in
if List.length params <> List.length ps
then error (Printf.sprintf "Not enough arguments to %s" (ident_to_string s)) s.range;
let ps =
List.map2 (fun (t, _, _) p ->
let p, t' = check_typ_param env p in
if not (eq_typ env t t')
then begin
match p with
| Inl e -> (match try_cast_integer env (e, t') t with
| Some e -> Inl e
| _ -> error "Argument type mismatch after trying integer cast" (range_of_typ_param p))
| _ ->
error (Printf.sprintf
"Argument type mismatch (%s vs %s)"
(Ast.print_typ t) (Ast.print_typ t')) (range_of_typ_param p)
end
else p)
params
ps
in
{t with v = Type_app s KindSpec ps})
| Type_app i KindExtern args ->
if List.length args <> 0
then error (Printf.sprintf "Cannot apply the extern type %s" (ident_to_string i)) i.range
else t
| Type_app _ KindOutput _ ->
error "Impossible, check_typ is not supposed to typecheck output types!" t.range
and check_ident (env:env) (i:ident)
: ML (ident & typ)
= let t = lookup_expr_name env i in
i, t
and check_expr (env:env) (e:expr)
: ML (expr & typ)
= let w e' = with_range e' e.range in
let arith_op_t op t : ML Ast.op =
let t = tag_of_integral_typ env t in
match op with
| Plus _ -> Plus t
| Minus _ -> Minus t
| Mul _ -> Mul t
| Division _ -> Division t
| Remainder _ -> Remainder t
| BitwiseNot _ -> BitwiseNot t
| BitwiseAnd _ -> BitwiseAnd t
| BitwiseOr _ -> BitwiseOr t
| BitwiseXor _ -> BitwiseXor t
| ShiftLeft _ -> ShiftLeft t
| ShiftRight _ -> ShiftRight t
| LE _ -> LE t
| LT _ -> LT t
| GE _ -> GE t
| GT _ -> GT t
| _ -> op
in
match e.v with
| Constant c ->
e, type_of_constant e.range c
| Identifier i ->
let i, t = check_ident env i in
{ e with v = Identifier i }, t
| Static _ ->
failwith "Static expressions should have been desugared already"
| This ->
error "`this` is not a valid expression" e.range
| App (Cast _ to) [n] ->
let n, from = check_expr env n in
begin
if not (typ_is_integral env from)
then error (Printf.sprintf "Casts are only supported on integral types; %s is not integral"
(print_typ from)) e.range
else match from.v with
| Type_app i KindSpec _ ->
let from_t = as_integer_typ i in
// if integer_type_lub to from_t <> to
// then error (Printf.sprintf "Only widening casts are supported; casting %s to %s loses precision"
// (print_typ from)
// (print_integer_type to))
// e.range
// else
let e = {e with v = App (Cast (Some from_t) to) [n]} in
let t = type_of_integer_type to in
Options.debug_print_string
(Printf.sprintf "--------------- %s has type %s\n" (print_expr e) (print_typ t));
e, t
| _ -> failwith "Impossible: must be an integral type"
end
| App SizeOf [{v=This;range=r}] ->
let e =
match env.this with
| None ->
error "`this` is not in scope" r
| Some i ->
with_range (App SizeOf [with_range (Identifier i) r]) e.range
in
e, tuint32
| App SizeOf [{v=Identifier i;range=r}] ->
begin
match lookup env i with
| Inr ({d_decl={v=Enum _ _ _}}, _)
| Inr ({d_decl={v=Record _ _ _ _ }}, _)
| Inr ({d_decl={v=CaseType _ _ _}}, _)
| Inr (_, Inl _) -> //has decl-attributes
e, tuint32
| _ ->
error "`sizeof` applied to a non-sized-typed" r
end
| App (Ext s) es ->
//TODO: AR: not sure about this Ext node
let m = lookup_macro_name env (with_range (to_ident' s) e.range) in
let n_formals = List.length m.macro_arguments_t in
let n_actuals = List.length es in
if n_formals <> n_actuals
then error (Printf.sprintf "%s expects %d arguments; got %d" s n_formals n_actuals) e.range;
let check_arg e t : ML expr =
let e, t' = check_expr env e in
if not (eq_typ env t t')
then error
(Printf.sprintf
"%s expected argument of type %s; \
got argument %s of type %s"
s (print_typ t) (print_expr e) (print_typ t))
e.range;
e
in
let es = List.map2 check_arg es m.macro_arguments_t in
with_range (App (Ext s) es) e.range,
m.macro_result_t
| App op es ->
let ets = List.map (check_expr env) es in
match ets with
| [(e1, t1)] ->
begin
match op with
| Not ->
if not (eq_typ env t1 tbool)
then error "Expected bool" e1.range;
w (App Not [e1]), t1
| BitwiseNot _ ->
if typ_is_integral env t1
then w (App (arith_op_t op t1) [e1]), t1
else error (Printf.sprintf "Bitwise negation is only available on integral types; got %s"
(print_typ t1))
e1.range
| _ ->
error "Not a unary op" e1.range
end
| [(e1,t1);(e2,t2)] ->
begin
match op with
| Eq
| Neq ->
if not (eq_typ env t1 t2)
then
begin
let err #a () : ML a =
error
(Printf.sprintf "Equality on unequal types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range
in
let it1 = typ_is_integral env t1 in
let it2 = typ_is_integral env t2 in
if it1 && it2
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App op [e1; e2]), tbool
| _ -> err ()
else err ()
end
else
w (App op [e1; e2]), tbool
| And
| Or ->
if not (eq_typs env [(t1,tbool); (t2,tbool)])
then error "Binary boolean op on non booleans" e.range;
w (App op [e1; e2]), tbool
| ShiftLeft _
| ShiftRight _ ->
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Bit shifts are only permissible on integral types: got %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
begin
match try_cast_integer env (e2, t2) tuint32 with
| None ->
error (Printf.sprintf "Bit shift offset is too large: got type %s"
(print_typ t2))
e2.range
| Some e2 ->
w (App (arith_op_t op t1) [e1; e2]), t1
end
| Plus _
| Minus _
| Mul _
| Division _
| Remainder _
| LT _
| GT _
| LE _
| GE _
| BitwiseAnd _
| BitwiseOr _
| BitwiseXor _ ->
let result_typ t =
match op with
| LT _ | GT _ | LE _ | GE _ -> tbool
| _ -> t
in
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Binary integer op on non-integral types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
if not (eq_typs env [(t1,t2)])
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) ->
w (App (arith_op_t op t) [e1; e2]), result_typ t
| _ ->
error (Printf.sprintf "Binary integer operator (%s) on non-equal types: %s and %s"
(print_expr e)
(print_typ t1)
(print_typ t2))
e.range
else w (App (arith_op_t op t1) [e1; e2]), result_typ t1
| _ ->
error "Not a binary op" e.range
end
| [(e1, t1); (e2, t2); (e3, t3)] ->
begin
match op with
| IfThenElse ->
if not (eq_typ env t1 tbool)
then error (Printf.sprintf "If-then-else expects a boolean guard, got %s" (print_typ t1))
e1.range;
if not (eq_typ env t2 t3)
then match try_retype_arith_exprs env (e2, t2) (e3, t3) e.range with
| Some (e2, e3, t) ->
w (App IfThenElse [e1;e2;e3]), t
| None ->
error (Printf.sprintf "then- and else-branch do not have the same type: got %s and %s"
(print_typ t2)
(print_typ t3))
e.range
else
w (App IfThenElse [e1;e2;e3]), t2
| BitFieldOf n order ->
let base_size = size_of_integral_typ env t1 e1.range in
let size = 8 * base_size in
if n <> size
then error
(Printf.sprintf "BitFieldOf size %d is not equal to %d, i.e., the bit size %s"
n size (print_expr e1))
e1.range;
begin
match e2.v, e3.v with
| Constant (Int UInt32 from), (Constant (Int UInt32 to)) ->
if not
(from <= size
&& from <= to
&& to <= size)
then error "bitfield-of expresssions is out of bounds" e.range;
w (App (BitFieldOf n order) [e1; e2; e3]), t1
| _ ->
error "bitfield-of with non-32-bit-consant indices" e.range
end
| _ ->
error "Unexpected arity" e.range
end
| _ -> error "Unexpected arity" e.range
and check_typ_param (env:env) (p:typ_param) : ML (typ_param & typ) =
match p with
| Inl e ->
let e, t = check_expr env e in
Inl e, t
| Inr o ->
let o = check_out_expr env o in
let { out_expr_t = t;
out_expr_bit_width = bopt } = Some?.v o.out_expr_meta in
(match bopt with
| None ->
Inr o, t
| _ ->
error ("Type parameter cannot be a bitfield") (range_of_typ_param p)) | {
"file_name": "src/3d/Binding.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 954,
"start_col": 0,
"start_line": 625
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Binding
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
include GlobalEnv
/// Maps locally bound names, i.e., a field name to its type
/// -- the bool signifies that this identifier has been used, and is
/// therefore marked as a dependent field
///
/// The modul_name in these ident' must be None -- TODO: add a refinement?
let local_env = H.t ident' (ident' & typ & bool)
/// `env` includes both a global and local env, together with a
/// binding for the `this` variable (bound to the name of a type) in
/// the current scope
noeq
type env = {
this: option ident;
locals: local_env;
globals: global_env;
}
let mk_env (g:global_env) =
{ this = None;
locals = H.create 10;
globals = g }
let copy_env (e:env) =
let locals = H.create 10 in
H.iter (fun k v -> H.insert locals k v) e.locals;
{
this = e.this;
globals = e.globals;
locals = locals
}
#push-options "--warn_error -272" //intentional top-level effect
let env_of_global_env
: global_env -> env
= let locals = H.create 1 in
fun g -> { this = None; locals; globals = g }
#pop-options
let global_env_of_env e = e.globals
let params_of_decl (d:decl) : list param =
match d.d_decl.v with
| ModuleAbbrev _ _
| Define _ _ _
| TypeAbbrev _ _
| Enum _ _ _ -> []
| Record _ params _ _
| CaseType _ params _ -> params
| OutputType _ -> []
| ExternType _ -> []
| ExternFn _ _ ps -> ps
| ExternProbe _ -> []
let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) =
match H.try_find e i.v with
| Some j ->
let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in
error msg i.range
| _ -> ()
let typedef_names (d:decl) : option typedef_names =
match d.d_decl.v with
| Record td _ _ _
| CaseType td _ _ -> Some td
| _ -> None
let format_identifier (e:env) (i:ident) : ML ident =
let j =
match String.list_of_string i.v.name with
| [] ->
failwith "Impossible: empty identifier"
| c0::cs ->
if FStar.Char.lowercase c0 = c0
then i //it starts with a lowercase symbol; that's ok
else //otherwise, add an underscore
{i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}}
in
match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with
| None, None -> j
| _ ->
let msg = Printf.sprintf
"This name (%s) starts will clash with another name in scope (%s) as it is translated. \
Please rename it"
(ident_to_string i) (ident_to_string j) in
error msg i.range
let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit =
let insert k v = H.insert e.ge_h k v in
check_shadow e.ge_h i d.d_decl.range;
let env = mk_env e in
let i' = format_identifier env i in
insert i.v (d, t);
insert i'.v (d, t);
match typedef_names d with
| None -> ()
| Some td ->
if td.typedef_abbrev.v <> i.v
then begin
check_shadow e.ge_h td.typedef_abbrev d.d_decl.range;
let abbrev = format_identifier env td.typedef_abbrev in
insert td.typedef_abbrev.v (d, t);
insert abbrev.v (d, t)
end
let add_local (e:env) (i:ident) (t:typ) : ML unit =
check_shadow e.globals.ge_h i t.range;
check_shadow e.locals i t.range;
let i' = format_identifier e i in
H.insert e.locals i.v (i'.v, t, false);
H.insert e.locals i'.v (i'.v, t, false)
let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) =
match H.try_find e.locals i.v with
| Some (_, t, true) ->
Some (Inl t)
| Some (j, t, false) -> //mark it as used
H.remove e.locals i.v;
H.insert e.locals i.v (j, t, true);
Some (Inl t)
| None ->
match H.try_find e.globals.ge_h i.v with
| Some d -> Some (Inr d)
| None -> None
let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) =
match try_lookup e i with
| None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
| Some v -> v
let remove_local (e:env) (i:ident) : ML unit =
match H.try_find e.locals i.v with
| Some (j, _, _) ->
H.remove e.locals i.v;
H.remove e.locals j
| _ -> ()
let resolve_record_case_output_extern_type_name (env:env) (i:ident) =
match H.try_find (global_env_of_env env).ge_out_t i.v with
| Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev
| _ ->
(match H.try_find (global_env_of_env env).ge_extern_t i.v with
| Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev
| _ ->
(match lookup env i with
| Inr ({d_decl={v=Record names _ _ _}}, _)
| Inr ({d_decl={v=CaseType names _ _}}, _) ->
names.typedef_name
| _ -> i))
let lookup_expr_name (e:env) (i:ident) : ML typ =
match lookup e i with
| Inl t -> t
| Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t
| Inr _ ->
error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
let lookup_macro_name (e:env) (i:ident) : ML macro_signature =
match lookup e i with
| Inr (_, Inr m) -> m
| _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
let lookup_macro_definition (e:env) (i:ident) =
try
let m = lookup_macro_name e i in
m.macro_defn_t
with
| _ -> None
let try_lookup_enum_cases (e:env) (i:ident)
: ML (option (list ident & typ))
= match lookup e i with
| Inr ({d_decl={v=Enum t _ tags}}, _) ->
Some (Desugar.check_desugared_enum_cases tags, t)
| _ -> None
let lookup_enum_cases (e:env) (i:ident)
: ML (list ident & typ)
= match try_lookup_enum_cases e i with
| Some (tags, t) -> tags, t
| _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
let is_enum (e:env) (t:typ) =
match t.v with
| Type_app i KindSpec [] ->
Some? (try_lookup_enum_cases e i)
| _ -> false
let is_used (e:env) (i:ident) : ML bool =
match H.try_find e.locals i.v with
| Some (_, t, b) -> b
| _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
let type_of_integer_type = function
| UInt8 -> tuint8
| UInt16 -> tuint16
| UInt32 -> tuint32
| UInt64 -> tuint64
let check_integer_bounds t i =
match t with
| UInt8 -> FStar.UInt.fits i 8
| UInt16 -> FStar.UInt.fits i 16
| UInt32 -> FStar.UInt.fits i 32
| UInt64 -> FStar.UInt.fits i 64
let type_of_constant rng (c:constant) : ML typ =
match c with
| Unit -> tunit
| Int tag i ->
if check_integer_bounds tag i
then type_of_integer_type tag
else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng
| XInt tag _ -> //bounds checked by the syntax
type_of_integer_type tag
| Bool _ -> tbool
let parser_may_fail (env:env) (t:typ) : ML bool =
match t.v with
| Pointer _ -> true
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> attrs.may_fail
| _ -> false
let typ_is_integral env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> Some? attrs.integral
| _ -> false
let tag_of_integral_typ env (t:typ) : ML (option _) =
match t.v with
| Pointer _ -> None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral
| _ -> None
let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) =
match t.v with
| Pointer _ -> None, None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order
| _ -> None, None
let has_reader (env:global_env) (id:ident) : ML bool =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.has_reader
| _ -> false
let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.parser_kind_nz
| _ -> None
let parser_weak_kind (env:global_env) (id:ident) : ML (option _) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> Some attrs.parser_weak_kind
| _ -> None
let rec typ_weak_kind env (t:typ) : ML (option weak_kind) =
match t.v with
| Pointer _ -> typ_weak_kind env tuint64
| Type_app hd _ _ -> parser_weak_kind env.globals hd
let typ_has_reader env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
has_reader env.globals hd
let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match try_lookup env hd with
| Some (Inr (d, _)) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_only env t
| _ -> t
end
| _ -> t
end
| _ -> t
let update_typ_abbrev (env:env) (i:ident) (t:typ)
: ML unit
= match H.try_find env.globals.ge_h i.v with
| Some (d, ms) ->
let d_decl =
match d.d_decl.v with
| TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i }
| _ -> failwith "Expected a type abbreviation"
in
let d = {d with d_decl = d_decl } in
let entry = (d, ms) in
H.insert env.globals.ge_h i.v entry
| _ ->
failwith "Type abbreviation not found"
let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match lookup env hd with
| Inr (d, _) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t
| Enum t _ _ -> unfold_typ_abbrev_and_enum env t
| _ -> t
end
| _ -> t
end
| _ -> t
let size_of_integral_typ (env:env) (t:typ) r
: ML int
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_of_integral_typ env t with
| None -> failwith "Impossible"
| Some UInt8 -> 1
| Some UInt16 -> 2
| Some UInt32 -> 4
| Some UInt64 -> 8
let bit_order_of_integral_typ (env:env) (t:typ) r
: ML bitfield_bit_order
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_and_bit_order_of_integral_typ env t with
| _, None -> failwith "Impossible"
| _, Some order -> order
let eq_typ env t1 t2 =
if Ast.eq_typ t1 t2 then true
else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
let eq_typs env ts =
List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
let cast e t t' = { e with v = App (Cast (Some t) t') [e] }
let try_cast_integer env et to : ML (option expr) =
let e, from = et in
let i_to = typ_is_integral env to in
let i_from = typ_is_integral env from in
if i_from && i_to
then
let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in
let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in
if i_from = i_to
then Some e
else if integer_type_leq i_from i_to
then Some (cast e i_from i_to)
else None
else None
let _or_ b1 b2 = b1 || b2
let _and_ b1 b2 = b1 && b2
let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))=
let e1, t1 = e1 in
let e2, t2 = e2 in
let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)"
i
(print_expr e1)
(print_typ t1)
(print_expr e2)
(print_typ t2))) in
try
let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in
if not (typ_is_integral env t1 `_and_`
typ_is_integral env t2)
then fail 1;
let tt1 = typ_as_integer_type t1 in
let tt2 = typ_as_integer_type t2 in
let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in
let e1, e2, t =
if integer_type_leq tt1 tt2
then cast e1 tt1 tt2,
e2,
t2
else if integer_type_leq tt2 tt1
then e1,
cast e2 tt2 tt1,
t1
else fail 0
in
// FStar.IO.print_string
// (Printf.sprintf "Retyped to (%s, %s, %s)\n"
// (print_expr e1)
// (print_expr e2)
// (print_typ t));
Some (e1, e2, t)
with
| Error msg ->
FStar.IO.print_string msg;
None
| _ -> None
(*
* Add output type to the environment
*
* TODO: check_shadow
*)
let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_out_t i d in
insert i.v;
let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in
insert td_abbrev.v
(*
* Add extern type to the environment
*
* TODO: check shadow
*)
let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_extern_t i d in
insert i.v;
let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in
insert td_abbrev.v
(*
* Add extern probe function to the environment
*
* TODO: check shadow
*)
let add_extern_probe (ge:global_env) (i:ident) (d:decl{ExternProbe? d.d_decl.v}) : ML unit =
H.insert ge.ge_probe_fn i.v d
(*
* Add extern function to the environment
*
* TODO: check shadow
*)
let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit =
H.insert ge.ge_extern_fn i.v d
let lookup_output_type (ge:global_env) (i:ident) : ML out_typ =
match H.try_find ge.ge_out_t i.v with
| Some ({d_decl={v=OutputType out_t}}) -> out_t
| _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range
(*
* Returns the type of the field, with optional bitwidth if the field is a bitfield
*)
let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) =
let out_t = lookup_output_type ge i in
let rec find (flds:list out_field) : (option (typ & option int)) =
match flds with
| [] -> None
| (Out_field_named f' t n)::tl ->
if eq_idents f f' then Some (t, n)
else find tl
| (Out_field_anon l _)::tl ->
(match find l with
| None -> find tl
| Some t -> Some t) in
match find out_t.out_typ_fields with
| Some t -> t
| None ->
error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range
let lookup_extern_type (ge:global_env) (i:ident) : ML unit =
match H.try_find ge.ge_extern_t i.v with
| Some ({d_decl={v=ExternType _}}) -> ()
| _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) =
match H.try_find ge.ge_extern_fn f.v with
| Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps
| _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
let check_output_type (ge:global_env) (t:typ) : ML ident =
let err () : ML ident =
error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in
match t.v with
| Type_app i KindOutput [] -> i
| _ -> err ()
/// Populated the output expression metadata
///
/// We enforce that the spec cannot take address of output type bitfields
let rec check_out_expr (env:env) (oe0:out_expr)
: ML (oe:out_expr{Some? oe.out_expr_meta}) =
match oe0.out_expr_node.v with
| OE_id i ->
let t = lookup_expr_name env i in
{oe0 with
out_expr_meta = Some ({
out_expr_base_t = t;
out_expr_t = t;
out_expr_bit_width = None})}
| OE_star oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_star oe};
out_expr_meta=Some ({ out_expr_base_t = oe_bt;
out_expr_t = t;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_addrof oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_addrof oe};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
| OE_deref oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
let i = check_output_type (global_env_of_env env) t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_deref oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_dot oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
let i = check_output_type (global_env_of_env env) oe_t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_dot oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
let range_of_typ_param (p:typ_param) = match p with
| Inl e -> e.range
| Inr p -> p.out_expr_node.range | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Options.fsti.checked",
"Hashtable.fsti.checked",
"GlobalEnv.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Binding.fst"
} | [
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pointer_ok: Prims.bool -> env: Binding.env -> t: Ast.typ -> FStar.All.ML Ast.typ | FStar.All.ML | [
"ml"
] | [
"check_typ",
"check_ident",
"check_expr",
"check_typ_param"
] | [
"Prims.bool",
"Binding.env",
"Ast.typ",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.typ'",
"Ast.with_meta_t",
"Ast.Mkwith_meta_t",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.Pointer",
"Binding.check_typ",
"Ast.error",
"Prims.string",
"FStar.Printf.sprintf",
"Ast.print_typ",
"Ast.ident",
"Prims.list",
"Ast.either",
"Ast.expr",
"Ast.out_expr",
"Ast.ident_to_string",
"Ast.ident'",
"Ast.decl",
"GlobalEnv.decl_attributes",
"GlobalEnv.macro_signature",
"Ast.Type_app",
"Ast.KindSpec",
"FStar.List.map2",
"FStar.Pervasives.Native.tuple3",
"Ast.qualifier",
"Ast.typ_param",
"Ast.Inl",
"FStar.Pervasives.Native.option",
"Binding.range_of_typ_param",
"Binding.try_cast_integer",
"FStar.Pervasives.Native.Mktuple2",
"Ast.expr'",
"Prims.op_Negation",
"Binding.eq_typ",
"FStar.Pervasives.Native.tuple2",
"Binding.check_typ_param",
"Prims.unit",
"Prims.op_disEquality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Ast.param",
"Binding.params_of_decl",
"Binding.lookup",
"Prims.int"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec check_typ (pointer_ok: bool) (env: env) (t: typ) : ML typ =
| match t.v with
| Pointer t0 ->
if pointer_ok
then { t with v = Pointer (check_typ pointer_ok env t0) }
else error (Printf.sprintf "Pointer types are not permissible here; got %s" (print_typ t)) t.range
| Type_app s KindSpec ps ->
(match lookup env s with
| Inl _ -> error (Printf.sprintf "%s is not a type" (ident_to_string s)) s.range
| Inr (d, _) ->
let params = params_of_decl d in
if List.length params <> List.length ps
then error (Printf.sprintf "Not enough arguments to %s" (ident_to_string s)) s.range;
let ps =
List.map2 (fun (t, _, _) p ->
let p, t' = check_typ_param env p in
if not (eq_typ env t t')
then
match p with
| Inl e ->
(match try_cast_integer env (e, t') t with
| Some e -> Inl e
| _ ->
error "Argument type mismatch after trying integer cast"
(range_of_typ_param p))
| _ ->
error (Printf.sprintf "Argument type mismatch (%s vs %s)"
(Ast.print_typ t)
(Ast.print_typ t'))
(range_of_typ_param p)
else p)
params
ps
in
{ t with v = Type_app s KindSpec ps })
| Type_app i KindExtern args ->
if List.length args <> 0
then error (Printf.sprintf "Cannot apply the extern type %s" (ident_to_string i)) i.range
else t
| Type_app _ KindOutput _ ->
error "Impossible, check_typ is not supposed to typecheck output types!" t.range | false |
Binding.fst | Binding.check_ident | val check_ident (env: env) (i: ident) : ML (ident & typ) | val check_ident (env: env) (i: ident) : ML (ident & typ) | let rec check_typ (pointer_ok:bool) (env:env) (t:typ)
: ML typ
= match t.v with
| Pointer t0 ->
if pointer_ok
then { t with v = Pointer (check_typ pointer_ok env t0) }
else error (Printf.sprintf "Pointer types are not permissible here; got %s" (print_typ t)) t.range
| Type_app s KindSpec ps ->
(match lookup env s with
| Inl _ ->
error (Printf.sprintf "%s is not a type" (ident_to_string s)) s.range
| Inr (d, _) ->
let params = params_of_decl d in
if List.length params <> List.length ps
then error (Printf.sprintf "Not enough arguments to %s" (ident_to_string s)) s.range;
let ps =
List.map2 (fun (t, _, _) p ->
let p, t' = check_typ_param env p in
if not (eq_typ env t t')
then begin
match p with
| Inl e -> (match try_cast_integer env (e, t') t with
| Some e -> Inl e
| _ -> error "Argument type mismatch after trying integer cast" (range_of_typ_param p))
| _ ->
error (Printf.sprintf
"Argument type mismatch (%s vs %s)"
(Ast.print_typ t) (Ast.print_typ t')) (range_of_typ_param p)
end
else p)
params
ps
in
{t with v = Type_app s KindSpec ps})
| Type_app i KindExtern args ->
if List.length args <> 0
then error (Printf.sprintf "Cannot apply the extern type %s" (ident_to_string i)) i.range
else t
| Type_app _ KindOutput _ ->
error "Impossible, check_typ is not supposed to typecheck output types!" t.range
and check_ident (env:env) (i:ident)
: ML (ident & typ)
= let t = lookup_expr_name env i in
i, t
and check_expr (env:env) (e:expr)
: ML (expr & typ)
= let w e' = with_range e' e.range in
let arith_op_t op t : ML Ast.op =
let t = tag_of_integral_typ env t in
match op with
| Plus _ -> Plus t
| Minus _ -> Minus t
| Mul _ -> Mul t
| Division _ -> Division t
| Remainder _ -> Remainder t
| BitwiseNot _ -> BitwiseNot t
| BitwiseAnd _ -> BitwiseAnd t
| BitwiseOr _ -> BitwiseOr t
| BitwiseXor _ -> BitwiseXor t
| ShiftLeft _ -> ShiftLeft t
| ShiftRight _ -> ShiftRight t
| LE _ -> LE t
| LT _ -> LT t
| GE _ -> GE t
| GT _ -> GT t
| _ -> op
in
match e.v with
| Constant c ->
e, type_of_constant e.range c
| Identifier i ->
let i, t = check_ident env i in
{ e with v = Identifier i }, t
| Static _ ->
failwith "Static expressions should have been desugared already"
| This ->
error "`this` is not a valid expression" e.range
| App (Cast _ to) [n] ->
let n, from = check_expr env n in
begin
if not (typ_is_integral env from)
then error (Printf.sprintf "Casts are only supported on integral types; %s is not integral"
(print_typ from)) e.range
else match from.v with
| Type_app i KindSpec _ ->
let from_t = as_integer_typ i in
// if integer_type_lub to from_t <> to
// then error (Printf.sprintf "Only widening casts are supported; casting %s to %s loses precision"
// (print_typ from)
// (print_integer_type to))
// e.range
// else
let e = {e with v = App (Cast (Some from_t) to) [n]} in
let t = type_of_integer_type to in
Options.debug_print_string
(Printf.sprintf "--------------- %s has type %s\n" (print_expr e) (print_typ t));
e, t
| _ -> failwith "Impossible: must be an integral type"
end
| App SizeOf [{v=This;range=r}] ->
let e =
match env.this with
| None ->
error "`this` is not in scope" r
| Some i ->
with_range (App SizeOf [with_range (Identifier i) r]) e.range
in
e, tuint32
| App SizeOf [{v=Identifier i;range=r}] ->
begin
match lookup env i with
| Inr ({d_decl={v=Enum _ _ _}}, _)
| Inr ({d_decl={v=Record _ _ _ _ }}, _)
| Inr ({d_decl={v=CaseType _ _ _}}, _)
| Inr (_, Inl _) -> //has decl-attributes
e, tuint32
| _ ->
error "`sizeof` applied to a non-sized-typed" r
end
| App (Ext s) es ->
//TODO: AR: not sure about this Ext node
let m = lookup_macro_name env (with_range (to_ident' s) e.range) in
let n_formals = List.length m.macro_arguments_t in
let n_actuals = List.length es in
if n_formals <> n_actuals
then error (Printf.sprintf "%s expects %d arguments; got %d" s n_formals n_actuals) e.range;
let check_arg e t : ML expr =
let e, t' = check_expr env e in
if not (eq_typ env t t')
then error
(Printf.sprintf
"%s expected argument of type %s; \
got argument %s of type %s"
s (print_typ t) (print_expr e) (print_typ t))
e.range;
e
in
let es = List.map2 check_arg es m.macro_arguments_t in
with_range (App (Ext s) es) e.range,
m.macro_result_t
| App op es ->
let ets = List.map (check_expr env) es in
match ets with
| [(e1, t1)] ->
begin
match op with
| Not ->
if not (eq_typ env t1 tbool)
then error "Expected bool" e1.range;
w (App Not [e1]), t1
| BitwiseNot _ ->
if typ_is_integral env t1
then w (App (arith_op_t op t1) [e1]), t1
else error (Printf.sprintf "Bitwise negation is only available on integral types; got %s"
(print_typ t1))
e1.range
| _ ->
error "Not a unary op" e1.range
end
| [(e1,t1);(e2,t2)] ->
begin
match op with
| Eq
| Neq ->
if not (eq_typ env t1 t2)
then
begin
let err #a () : ML a =
error
(Printf.sprintf "Equality on unequal types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range
in
let it1 = typ_is_integral env t1 in
let it2 = typ_is_integral env t2 in
if it1 && it2
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App op [e1; e2]), tbool
| _ -> err ()
else err ()
end
else
w (App op [e1; e2]), tbool
| And
| Or ->
if not (eq_typs env [(t1,tbool); (t2,tbool)])
then error "Binary boolean op on non booleans" e.range;
w (App op [e1; e2]), tbool
| ShiftLeft _
| ShiftRight _ ->
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Bit shifts are only permissible on integral types: got %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
begin
match try_cast_integer env (e2, t2) tuint32 with
| None ->
error (Printf.sprintf "Bit shift offset is too large: got type %s"
(print_typ t2))
e2.range
| Some e2 ->
w (App (arith_op_t op t1) [e1; e2]), t1
end
| Plus _
| Minus _
| Mul _
| Division _
| Remainder _
| LT _
| GT _
| LE _
| GE _
| BitwiseAnd _
| BitwiseOr _
| BitwiseXor _ ->
let result_typ t =
match op with
| LT _ | GT _ | LE _ | GE _ -> tbool
| _ -> t
in
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Binary integer op on non-integral types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
if not (eq_typs env [(t1,t2)])
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) ->
w (App (arith_op_t op t) [e1; e2]), result_typ t
| _ ->
error (Printf.sprintf "Binary integer operator (%s) on non-equal types: %s and %s"
(print_expr e)
(print_typ t1)
(print_typ t2))
e.range
else w (App (arith_op_t op t1) [e1; e2]), result_typ t1
| _ ->
error "Not a binary op" e.range
end
| [(e1, t1); (e2, t2); (e3, t3)] ->
begin
match op with
| IfThenElse ->
if not (eq_typ env t1 tbool)
then error (Printf.sprintf "If-then-else expects a boolean guard, got %s" (print_typ t1))
e1.range;
if not (eq_typ env t2 t3)
then match try_retype_arith_exprs env (e2, t2) (e3, t3) e.range with
| Some (e2, e3, t) ->
w (App IfThenElse [e1;e2;e3]), t
| None ->
error (Printf.sprintf "then- and else-branch do not have the same type: got %s and %s"
(print_typ t2)
(print_typ t3))
e.range
else
w (App IfThenElse [e1;e2;e3]), t2
| BitFieldOf n order ->
let base_size = size_of_integral_typ env t1 e1.range in
let size = 8 * base_size in
if n <> size
then error
(Printf.sprintf "BitFieldOf size %d is not equal to %d, i.e., the bit size %s"
n size (print_expr e1))
e1.range;
begin
match e2.v, e3.v with
| Constant (Int UInt32 from), (Constant (Int UInt32 to)) ->
if not
(from <= size
&& from <= to
&& to <= size)
then error "bitfield-of expresssions is out of bounds" e.range;
w (App (BitFieldOf n order) [e1; e2; e3]), t1
| _ ->
error "bitfield-of with non-32-bit-consant indices" e.range
end
| _ ->
error "Unexpected arity" e.range
end
| _ -> error "Unexpected arity" e.range
and check_typ_param (env:env) (p:typ_param) : ML (typ_param & typ) =
match p with
| Inl e ->
let e, t = check_expr env e in
Inl e, t
| Inr o ->
let o = check_out_expr env o in
let { out_expr_t = t;
out_expr_bit_width = bopt } = Some?.v o.out_expr_meta in
(match bopt with
| None ->
Inr o, t
| _ ->
error ("Type parameter cannot be a bitfield") (range_of_typ_param p)) | {
"file_name": "src/3d/Binding.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 954,
"start_col": 0,
"start_line": 625
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Binding
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
include GlobalEnv
/// Maps locally bound names, i.e., a field name to its type
/// -- the bool signifies that this identifier has been used, and is
/// therefore marked as a dependent field
///
/// The modul_name in these ident' must be None -- TODO: add a refinement?
let local_env = H.t ident' (ident' & typ & bool)
/// `env` includes both a global and local env, together with a
/// binding for the `this` variable (bound to the name of a type) in
/// the current scope
noeq
type env = {
this: option ident;
locals: local_env;
globals: global_env;
}
let mk_env (g:global_env) =
{ this = None;
locals = H.create 10;
globals = g }
let copy_env (e:env) =
let locals = H.create 10 in
H.iter (fun k v -> H.insert locals k v) e.locals;
{
this = e.this;
globals = e.globals;
locals = locals
}
#push-options "--warn_error -272" //intentional top-level effect
let env_of_global_env
: global_env -> env
= let locals = H.create 1 in
fun g -> { this = None; locals; globals = g }
#pop-options
let global_env_of_env e = e.globals
let params_of_decl (d:decl) : list param =
match d.d_decl.v with
| ModuleAbbrev _ _
| Define _ _ _
| TypeAbbrev _ _
| Enum _ _ _ -> []
| Record _ params _ _
| CaseType _ params _ -> params
| OutputType _ -> []
| ExternType _ -> []
| ExternFn _ _ ps -> ps
| ExternProbe _ -> []
let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) =
match H.try_find e i.v with
| Some j ->
let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in
error msg i.range
| _ -> ()
let typedef_names (d:decl) : option typedef_names =
match d.d_decl.v with
| Record td _ _ _
| CaseType td _ _ -> Some td
| _ -> None
let format_identifier (e:env) (i:ident) : ML ident =
let j =
match String.list_of_string i.v.name with
| [] ->
failwith "Impossible: empty identifier"
| c0::cs ->
if FStar.Char.lowercase c0 = c0
then i //it starts with a lowercase symbol; that's ok
else //otherwise, add an underscore
{i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}}
in
match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with
| None, None -> j
| _ ->
let msg = Printf.sprintf
"This name (%s) starts will clash with another name in scope (%s) as it is translated. \
Please rename it"
(ident_to_string i) (ident_to_string j) in
error msg i.range
let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit =
let insert k v = H.insert e.ge_h k v in
check_shadow e.ge_h i d.d_decl.range;
let env = mk_env e in
let i' = format_identifier env i in
insert i.v (d, t);
insert i'.v (d, t);
match typedef_names d with
| None -> ()
| Some td ->
if td.typedef_abbrev.v <> i.v
then begin
check_shadow e.ge_h td.typedef_abbrev d.d_decl.range;
let abbrev = format_identifier env td.typedef_abbrev in
insert td.typedef_abbrev.v (d, t);
insert abbrev.v (d, t)
end
let add_local (e:env) (i:ident) (t:typ) : ML unit =
check_shadow e.globals.ge_h i t.range;
check_shadow e.locals i t.range;
let i' = format_identifier e i in
H.insert e.locals i.v (i'.v, t, false);
H.insert e.locals i'.v (i'.v, t, false)
let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) =
match H.try_find e.locals i.v with
| Some (_, t, true) ->
Some (Inl t)
| Some (j, t, false) -> //mark it as used
H.remove e.locals i.v;
H.insert e.locals i.v (j, t, true);
Some (Inl t)
| None ->
match H.try_find e.globals.ge_h i.v with
| Some d -> Some (Inr d)
| None -> None
let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) =
match try_lookup e i with
| None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
| Some v -> v
let remove_local (e:env) (i:ident) : ML unit =
match H.try_find e.locals i.v with
| Some (j, _, _) ->
H.remove e.locals i.v;
H.remove e.locals j
| _ -> ()
let resolve_record_case_output_extern_type_name (env:env) (i:ident) =
match H.try_find (global_env_of_env env).ge_out_t i.v with
| Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev
| _ ->
(match H.try_find (global_env_of_env env).ge_extern_t i.v with
| Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev
| _ ->
(match lookup env i with
| Inr ({d_decl={v=Record names _ _ _}}, _)
| Inr ({d_decl={v=CaseType names _ _}}, _) ->
names.typedef_name
| _ -> i))
let lookup_expr_name (e:env) (i:ident) : ML typ =
match lookup e i with
| Inl t -> t
| Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t
| Inr _ ->
error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
let lookup_macro_name (e:env) (i:ident) : ML macro_signature =
match lookup e i with
| Inr (_, Inr m) -> m
| _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
let lookup_macro_definition (e:env) (i:ident) =
try
let m = lookup_macro_name e i in
m.macro_defn_t
with
| _ -> None
let try_lookup_enum_cases (e:env) (i:ident)
: ML (option (list ident & typ))
= match lookup e i with
| Inr ({d_decl={v=Enum t _ tags}}, _) ->
Some (Desugar.check_desugared_enum_cases tags, t)
| _ -> None
let lookup_enum_cases (e:env) (i:ident)
: ML (list ident & typ)
= match try_lookup_enum_cases e i with
| Some (tags, t) -> tags, t
| _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
let is_enum (e:env) (t:typ) =
match t.v with
| Type_app i KindSpec [] ->
Some? (try_lookup_enum_cases e i)
| _ -> false
let is_used (e:env) (i:ident) : ML bool =
match H.try_find e.locals i.v with
| Some (_, t, b) -> b
| _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
let type_of_integer_type = function
| UInt8 -> tuint8
| UInt16 -> tuint16
| UInt32 -> tuint32
| UInt64 -> tuint64
let check_integer_bounds t i =
match t with
| UInt8 -> FStar.UInt.fits i 8
| UInt16 -> FStar.UInt.fits i 16
| UInt32 -> FStar.UInt.fits i 32
| UInt64 -> FStar.UInt.fits i 64
let type_of_constant rng (c:constant) : ML typ =
match c with
| Unit -> tunit
| Int tag i ->
if check_integer_bounds tag i
then type_of_integer_type tag
else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng
| XInt tag _ -> //bounds checked by the syntax
type_of_integer_type tag
| Bool _ -> tbool
let parser_may_fail (env:env) (t:typ) : ML bool =
match t.v with
| Pointer _ -> true
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> attrs.may_fail
| _ -> false
let typ_is_integral env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> Some? attrs.integral
| _ -> false
let tag_of_integral_typ env (t:typ) : ML (option _) =
match t.v with
| Pointer _ -> None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral
| _ -> None
let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) =
match t.v with
| Pointer _ -> None, None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order
| _ -> None, None
let has_reader (env:global_env) (id:ident) : ML bool =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.has_reader
| _ -> false
let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.parser_kind_nz
| _ -> None
let parser_weak_kind (env:global_env) (id:ident) : ML (option _) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> Some attrs.parser_weak_kind
| _ -> None
let rec typ_weak_kind env (t:typ) : ML (option weak_kind) =
match t.v with
| Pointer _ -> typ_weak_kind env tuint64
| Type_app hd _ _ -> parser_weak_kind env.globals hd
let typ_has_reader env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
has_reader env.globals hd
let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match try_lookup env hd with
| Some (Inr (d, _)) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_only env t
| _ -> t
end
| _ -> t
end
| _ -> t
let update_typ_abbrev (env:env) (i:ident) (t:typ)
: ML unit
= match H.try_find env.globals.ge_h i.v with
| Some (d, ms) ->
let d_decl =
match d.d_decl.v with
| TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i }
| _ -> failwith "Expected a type abbreviation"
in
let d = {d with d_decl = d_decl } in
let entry = (d, ms) in
H.insert env.globals.ge_h i.v entry
| _ ->
failwith "Type abbreviation not found"
let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match lookup env hd with
| Inr (d, _) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t
| Enum t _ _ -> unfold_typ_abbrev_and_enum env t
| _ -> t
end
| _ -> t
end
| _ -> t
let size_of_integral_typ (env:env) (t:typ) r
: ML int
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_of_integral_typ env t with
| None -> failwith "Impossible"
| Some UInt8 -> 1
| Some UInt16 -> 2
| Some UInt32 -> 4
| Some UInt64 -> 8
let bit_order_of_integral_typ (env:env) (t:typ) r
: ML bitfield_bit_order
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_and_bit_order_of_integral_typ env t with
| _, None -> failwith "Impossible"
| _, Some order -> order
let eq_typ env t1 t2 =
if Ast.eq_typ t1 t2 then true
else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
let eq_typs env ts =
List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
let cast e t t' = { e with v = App (Cast (Some t) t') [e] }
let try_cast_integer env et to : ML (option expr) =
let e, from = et in
let i_to = typ_is_integral env to in
let i_from = typ_is_integral env from in
if i_from && i_to
then
let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in
let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in
if i_from = i_to
then Some e
else if integer_type_leq i_from i_to
then Some (cast e i_from i_to)
else None
else None
let _or_ b1 b2 = b1 || b2
let _and_ b1 b2 = b1 && b2
let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))=
let e1, t1 = e1 in
let e2, t2 = e2 in
let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)"
i
(print_expr e1)
(print_typ t1)
(print_expr e2)
(print_typ t2))) in
try
let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in
if not (typ_is_integral env t1 `_and_`
typ_is_integral env t2)
then fail 1;
let tt1 = typ_as_integer_type t1 in
let tt2 = typ_as_integer_type t2 in
let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in
let e1, e2, t =
if integer_type_leq tt1 tt2
then cast e1 tt1 tt2,
e2,
t2
else if integer_type_leq tt2 tt1
then e1,
cast e2 tt2 tt1,
t1
else fail 0
in
// FStar.IO.print_string
// (Printf.sprintf "Retyped to (%s, %s, %s)\n"
// (print_expr e1)
// (print_expr e2)
// (print_typ t));
Some (e1, e2, t)
with
| Error msg ->
FStar.IO.print_string msg;
None
| _ -> None
(*
* Add output type to the environment
*
* TODO: check_shadow
*)
let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_out_t i d in
insert i.v;
let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in
insert td_abbrev.v
(*
* Add extern type to the environment
*
* TODO: check shadow
*)
let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_extern_t i d in
insert i.v;
let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in
insert td_abbrev.v
(*
* Add extern probe function to the environment
*
* TODO: check shadow
*)
let add_extern_probe (ge:global_env) (i:ident) (d:decl{ExternProbe? d.d_decl.v}) : ML unit =
H.insert ge.ge_probe_fn i.v d
(*
* Add extern function to the environment
*
* TODO: check shadow
*)
let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit =
H.insert ge.ge_extern_fn i.v d
let lookup_output_type (ge:global_env) (i:ident) : ML out_typ =
match H.try_find ge.ge_out_t i.v with
| Some ({d_decl={v=OutputType out_t}}) -> out_t
| _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range
(*
* Returns the type of the field, with optional bitwidth if the field is a bitfield
*)
let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) =
let out_t = lookup_output_type ge i in
let rec find (flds:list out_field) : (option (typ & option int)) =
match flds with
| [] -> None
| (Out_field_named f' t n)::tl ->
if eq_idents f f' then Some (t, n)
else find tl
| (Out_field_anon l _)::tl ->
(match find l with
| None -> find tl
| Some t -> Some t) in
match find out_t.out_typ_fields with
| Some t -> t
| None ->
error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range
let lookup_extern_type (ge:global_env) (i:ident) : ML unit =
match H.try_find ge.ge_extern_t i.v with
| Some ({d_decl={v=ExternType _}}) -> ()
| _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) =
match H.try_find ge.ge_extern_fn f.v with
| Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps
| _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
let check_output_type (ge:global_env) (t:typ) : ML ident =
let err () : ML ident =
error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in
match t.v with
| Type_app i KindOutput [] -> i
| _ -> err ()
/// Populated the output expression metadata
///
/// We enforce that the spec cannot take address of output type bitfields
let rec check_out_expr (env:env) (oe0:out_expr)
: ML (oe:out_expr{Some? oe.out_expr_meta}) =
match oe0.out_expr_node.v with
| OE_id i ->
let t = lookup_expr_name env i in
{oe0 with
out_expr_meta = Some ({
out_expr_base_t = t;
out_expr_t = t;
out_expr_bit_width = None})}
| OE_star oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_star oe};
out_expr_meta=Some ({ out_expr_base_t = oe_bt;
out_expr_t = t;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_addrof oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_addrof oe};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
| OE_deref oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
let i = check_output_type (global_env_of_env env) t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_deref oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_dot oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
let i = check_output_type (global_env_of_env env) oe_t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_dot oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
let range_of_typ_param (p:typ_param) = match p with
| Inl e -> e.range
| Inr p -> p.out_expr_node.range | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Options.fsti.checked",
"Hashtable.fsti.checked",
"GlobalEnv.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Binding.fst"
} | [
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Binding.env -> i: Ast.ident -> FStar.All.ML (Ast.ident * Ast.typ) | FStar.All.ML | [
"ml"
] | [
"check_typ",
"check_ident",
"check_expr",
"check_typ_param"
] | [
"Binding.env",
"Ast.ident",
"FStar.Pervasives.Native.Mktuple2",
"Ast.typ",
"FStar.Pervasives.Native.tuple2",
"Binding.lookup_expr_name"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec check_ident (env: env) (i: ident) : ML (ident & typ) =
| let t = lookup_expr_name env i in
i, t | false |
Binding.fst | Binding.check_typ_param | val check_typ_param (env: env) (p: typ_param) : ML (typ_param & typ) | val check_typ_param (env: env) (p: typ_param) : ML (typ_param & typ) | let rec check_typ (pointer_ok:bool) (env:env) (t:typ)
: ML typ
= match t.v with
| Pointer t0 ->
if pointer_ok
then { t with v = Pointer (check_typ pointer_ok env t0) }
else error (Printf.sprintf "Pointer types are not permissible here; got %s" (print_typ t)) t.range
| Type_app s KindSpec ps ->
(match lookup env s with
| Inl _ ->
error (Printf.sprintf "%s is not a type" (ident_to_string s)) s.range
| Inr (d, _) ->
let params = params_of_decl d in
if List.length params <> List.length ps
then error (Printf.sprintf "Not enough arguments to %s" (ident_to_string s)) s.range;
let ps =
List.map2 (fun (t, _, _) p ->
let p, t' = check_typ_param env p in
if not (eq_typ env t t')
then begin
match p with
| Inl e -> (match try_cast_integer env (e, t') t with
| Some e -> Inl e
| _ -> error "Argument type mismatch after trying integer cast" (range_of_typ_param p))
| _ ->
error (Printf.sprintf
"Argument type mismatch (%s vs %s)"
(Ast.print_typ t) (Ast.print_typ t')) (range_of_typ_param p)
end
else p)
params
ps
in
{t with v = Type_app s KindSpec ps})
| Type_app i KindExtern args ->
if List.length args <> 0
then error (Printf.sprintf "Cannot apply the extern type %s" (ident_to_string i)) i.range
else t
| Type_app _ KindOutput _ ->
error "Impossible, check_typ is not supposed to typecheck output types!" t.range
and check_ident (env:env) (i:ident)
: ML (ident & typ)
= let t = lookup_expr_name env i in
i, t
and check_expr (env:env) (e:expr)
: ML (expr & typ)
= let w e' = with_range e' e.range in
let arith_op_t op t : ML Ast.op =
let t = tag_of_integral_typ env t in
match op with
| Plus _ -> Plus t
| Minus _ -> Minus t
| Mul _ -> Mul t
| Division _ -> Division t
| Remainder _ -> Remainder t
| BitwiseNot _ -> BitwiseNot t
| BitwiseAnd _ -> BitwiseAnd t
| BitwiseOr _ -> BitwiseOr t
| BitwiseXor _ -> BitwiseXor t
| ShiftLeft _ -> ShiftLeft t
| ShiftRight _ -> ShiftRight t
| LE _ -> LE t
| LT _ -> LT t
| GE _ -> GE t
| GT _ -> GT t
| _ -> op
in
match e.v with
| Constant c ->
e, type_of_constant e.range c
| Identifier i ->
let i, t = check_ident env i in
{ e with v = Identifier i }, t
| Static _ ->
failwith "Static expressions should have been desugared already"
| This ->
error "`this` is not a valid expression" e.range
| App (Cast _ to) [n] ->
let n, from = check_expr env n in
begin
if not (typ_is_integral env from)
then error (Printf.sprintf "Casts are only supported on integral types; %s is not integral"
(print_typ from)) e.range
else match from.v with
| Type_app i KindSpec _ ->
let from_t = as_integer_typ i in
// if integer_type_lub to from_t <> to
// then error (Printf.sprintf "Only widening casts are supported; casting %s to %s loses precision"
// (print_typ from)
// (print_integer_type to))
// e.range
// else
let e = {e with v = App (Cast (Some from_t) to) [n]} in
let t = type_of_integer_type to in
Options.debug_print_string
(Printf.sprintf "--------------- %s has type %s\n" (print_expr e) (print_typ t));
e, t
| _ -> failwith "Impossible: must be an integral type"
end
| App SizeOf [{v=This;range=r}] ->
let e =
match env.this with
| None ->
error "`this` is not in scope" r
| Some i ->
with_range (App SizeOf [with_range (Identifier i) r]) e.range
in
e, tuint32
| App SizeOf [{v=Identifier i;range=r}] ->
begin
match lookup env i with
| Inr ({d_decl={v=Enum _ _ _}}, _)
| Inr ({d_decl={v=Record _ _ _ _ }}, _)
| Inr ({d_decl={v=CaseType _ _ _}}, _)
| Inr (_, Inl _) -> //has decl-attributes
e, tuint32
| _ ->
error "`sizeof` applied to a non-sized-typed" r
end
| App (Ext s) es ->
//TODO: AR: not sure about this Ext node
let m = lookup_macro_name env (with_range (to_ident' s) e.range) in
let n_formals = List.length m.macro_arguments_t in
let n_actuals = List.length es in
if n_formals <> n_actuals
then error (Printf.sprintf "%s expects %d arguments; got %d" s n_formals n_actuals) e.range;
let check_arg e t : ML expr =
let e, t' = check_expr env e in
if not (eq_typ env t t')
then error
(Printf.sprintf
"%s expected argument of type %s; \
got argument %s of type %s"
s (print_typ t) (print_expr e) (print_typ t))
e.range;
e
in
let es = List.map2 check_arg es m.macro_arguments_t in
with_range (App (Ext s) es) e.range,
m.macro_result_t
| App op es ->
let ets = List.map (check_expr env) es in
match ets with
| [(e1, t1)] ->
begin
match op with
| Not ->
if not (eq_typ env t1 tbool)
then error "Expected bool" e1.range;
w (App Not [e1]), t1
| BitwiseNot _ ->
if typ_is_integral env t1
then w (App (arith_op_t op t1) [e1]), t1
else error (Printf.sprintf "Bitwise negation is only available on integral types; got %s"
(print_typ t1))
e1.range
| _ ->
error "Not a unary op" e1.range
end
| [(e1,t1);(e2,t2)] ->
begin
match op with
| Eq
| Neq ->
if not (eq_typ env t1 t2)
then
begin
let err #a () : ML a =
error
(Printf.sprintf "Equality on unequal types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range
in
let it1 = typ_is_integral env t1 in
let it2 = typ_is_integral env t2 in
if it1 && it2
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) -> w (App op [e1; e2]), tbool
| _ -> err ()
else err ()
end
else
w (App op [e1; e2]), tbool
| And
| Or ->
if not (eq_typs env [(t1,tbool); (t2,tbool)])
then error "Binary boolean op on non booleans" e.range;
w (App op [e1; e2]), tbool
| ShiftLeft _
| ShiftRight _ ->
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Bit shifts are only permissible on integral types: got %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
begin
match try_cast_integer env (e2, t2) tuint32 with
| None ->
error (Printf.sprintf "Bit shift offset is too large: got type %s"
(print_typ t2))
e2.range
| Some e2 ->
w (App (arith_op_t op t1) [e1; e2]), t1
end
| Plus _
| Minus _
| Mul _
| Division _
| Remainder _
| LT _
| GT _
| LE _
| GE _
| BitwiseAnd _
| BitwiseOr _
| BitwiseXor _ ->
let result_typ t =
match op with
| LT _ | GT _ | LE _ | GE _ -> tbool
| _ -> t
in
let t1_integral = typ_is_integral env t1 in
let t2_integral = typ_is_integral env t2 in
if not t1_integral || not t2_integral
then error (Printf.sprintf "Binary integer op on non-integral types: %s and %s"
(print_typ t1)
(print_typ t2))
e.range;
if not (eq_typs env [(t1,t2)])
then match try_retype_arith_exprs env (e1, t1) (e2, t2) e.range with
| Some (e1, e2, t) ->
w (App (arith_op_t op t) [e1; e2]), result_typ t
| _ ->
error (Printf.sprintf "Binary integer operator (%s) on non-equal types: %s and %s"
(print_expr e)
(print_typ t1)
(print_typ t2))
e.range
else w (App (arith_op_t op t1) [e1; e2]), result_typ t1
| _ ->
error "Not a binary op" e.range
end
| [(e1, t1); (e2, t2); (e3, t3)] ->
begin
match op with
| IfThenElse ->
if not (eq_typ env t1 tbool)
then error (Printf.sprintf "If-then-else expects a boolean guard, got %s" (print_typ t1))
e1.range;
if not (eq_typ env t2 t3)
then match try_retype_arith_exprs env (e2, t2) (e3, t3) e.range with
| Some (e2, e3, t) ->
w (App IfThenElse [e1;e2;e3]), t
| None ->
error (Printf.sprintf "then- and else-branch do not have the same type: got %s and %s"
(print_typ t2)
(print_typ t3))
e.range
else
w (App IfThenElse [e1;e2;e3]), t2
| BitFieldOf n order ->
let base_size = size_of_integral_typ env t1 e1.range in
let size = 8 * base_size in
if n <> size
then error
(Printf.sprintf "BitFieldOf size %d is not equal to %d, i.e., the bit size %s"
n size (print_expr e1))
e1.range;
begin
match e2.v, e3.v with
| Constant (Int UInt32 from), (Constant (Int UInt32 to)) ->
if not
(from <= size
&& from <= to
&& to <= size)
then error "bitfield-of expresssions is out of bounds" e.range;
w (App (BitFieldOf n order) [e1; e2; e3]), t1
| _ ->
error "bitfield-of with non-32-bit-consant indices" e.range
end
| _ ->
error "Unexpected arity" e.range
end
| _ -> error "Unexpected arity" e.range
and check_typ_param (env:env) (p:typ_param) : ML (typ_param & typ) =
match p with
| Inl e ->
let e, t = check_expr env e in
Inl e, t
| Inr o ->
let o = check_out_expr env o in
let { out_expr_t = t;
out_expr_bit_width = bopt } = Some?.v o.out_expr_meta in
(match bopt with
| None ->
Inr o, t
| _ ->
error ("Type parameter cannot be a bitfield") (range_of_typ_param p)) | {
"file_name": "src/3d/Binding.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 954,
"start_col": 0,
"start_line": 625
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Binding
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
include GlobalEnv
/// Maps locally bound names, i.e., a field name to its type
/// -- the bool signifies that this identifier has been used, and is
/// therefore marked as a dependent field
///
/// The modul_name in these ident' must be None -- TODO: add a refinement?
let local_env = H.t ident' (ident' & typ & bool)
/// `env` includes both a global and local env, together with a
/// binding for the `this` variable (bound to the name of a type) in
/// the current scope
noeq
type env = {
this: option ident;
locals: local_env;
globals: global_env;
}
let mk_env (g:global_env) =
{ this = None;
locals = H.create 10;
globals = g }
let copy_env (e:env) =
let locals = H.create 10 in
H.iter (fun k v -> H.insert locals k v) e.locals;
{
this = e.this;
globals = e.globals;
locals = locals
}
#push-options "--warn_error -272" //intentional top-level effect
let env_of_global_env
: global_env -> env
= let locals = H.create 1 in
fun g -> { this = None; locals; globals = g }
#pop-options
let global_env_of_env e = e.globals
let params_of_decl (d:decl) : list param =
match d.d_decl.v with
| ModuleAbbrev _ _
| Define _ _ _
| TypeAbbrev _ _
| Enum _ _ _ -> []
| Record _ params _ _
| CaseType _ params _ -> params
| OutputType _ -> []
| ExternType _ -> []
| ExternFn _ _ ps -> ps
| ExternProbe _ -> []
let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) =
match H.try_find e i.v with
| Some j ->
let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in
error msg i.range
| _ -> ()
let typedef_names (d:decl) : option typedef_names =
match d.d_decl.v with
| Record td _ _ _
| CaseType td _ _ -> Some td
| _ -> None
let format_identifier (e:env) (i:ident) : ML ident =
let j =
match String.list_of_string i.v.name with
| [] ->
failwith "Impossible: empty identifier"
| c0::cs ->
if FStar.Char.lowercase c0 = c0
then i //it starts with a lowercase symbol; that's ok
else //otherwise, add an underscore
{i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}}
in
match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with
| None, None -> j
| _ ->
let msg = Printf.sprintf
"This name (%s) starts will clash with another name in scope (%s) as it is translated. \
Please rename it"
(ident_to_string i) (ident_to_string j) in
error msg i.range
let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit =
let insert k v = H.insert e.ge_h k v in
check_shadow e.ge_h i d.d_decl.range;
let env = mk_env e in
let i' = format_identifier env i in
insert i.v (d, t);
insert i'.v (d, t);
match typedef_names d with
| None -> ()
| Some td ->
if td.typedef_abbrev.v <> i.v
then begin
check_shadow e.ge_h td.typedef_abbrev d.d_decl.range;
let abbrev = format_identifier env td.typedef_abbrev in
insert td.typedef_abbrev.v (d, t);
insert abbrev.v (d, t)
end
let add_local (e:env) (i:ident) (t:typ) : ML unit =
check_shadow e.globals.ge_h i t.range;
check_shadow e.locals i t.range;
let i' = format_identifier e i in
H.insert e.locals i.v (i'.v, t, false);
H.insert e.locals i'.v (i'.v, t, false)
let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) =
match H.try_find e.locals i.v with
| Some (_, t, true) ->
Some (Inl t)
| Some (j, t, false) -> //mark it as used
H.remove e.locals i.v;
H.insert e.locals i.v (j, t, true);
Some (Inl t)
| None ->
match H.try_find e.globals.ge_h i.v with
| Some d -> Some (Inr d)
| None -> None
let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) =
match try_lookup e i with
| None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
| Some v -> v
let remove_local (e:env) (i:ident) : ML unit =
match H.try_find e.locals i.v with
| Some (j, _, _) ->
H.remove e.locals i.v;
H.remove e.locals j
| _ -> ()
let resolve_record_case_output_extern_type_name (env:env) (i:ident) =
match H.try_find (global_env_of_env env).ge_out_t i.v with
| Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev
| _ ->
(match H.try_find (global_env_of_env env).ge_extern_t i.v with
| Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev
| _ ->
(match lookup env i with
| Inr ({d_decl={v=Record names _ _ _}}, _)
| Inr ({d_decl={v=CaseType names _ _}}, _) ->
names.typedef_name
| _ -> i))
let lookup_expr_name (e:env) (i:ident) : ML typ =
match lookup e i with
| Inl t -> t
| Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t
| Inr _ ->
error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
let lookup_macro_name (e:env) (i:ident) : ML macro_signature =
match lookup e i with
| Inr (_, Inr m) -> m
| _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
let lookup_macro_definition (e:env) (i:ident) =
try
let m = lookup_macro_name e i in
m.macro_defn_t
with
| _ -> None
let try_lookup_enum_cases (e:env) (i:ident)
: ML (option (list ident & typ))
= match lookup e i with
| Inr ({d_decl={v=Enum t _ tags}}, _) ->
Some (Desugar.check_desugared_enum_cases tags, t)
| _ -> None
let lookup_enum_cases (e:env) (i:ident)
: ML (list ident & typ)
= match try_lookup_enum_cases e i with
| Some (tags, t) -> tags, t
| _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
let is_enum (e:env) (t:typ) =
match t.v with
| Type_app i KindSpec [] ->
Some? (try_lookup_enum_cases e i)
| _ -> false
let is_used (e:env) (i:ident) : ML bool =
match H.try_find e.locals i.v with
| Some (_, t, b) -> b
| _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
let type_of_integer_type = function
| UInt8 -> tuint8
| UInt16 -> tuint16
| UInt32 -> tuint32
| UInt64 -> tuint64
let check_integer_bounds t i =
match t with
| UInt8 -> FStar.UInt.fits i 8
| UInt16 -> FStar.UInt.fits i 16
| UInt32 -> FStar.UInt.fits i 32
| UInt64 -> FStar.UInt.fits i 64
let type_of_constant rng (c:constant) : ML typ =
match c with
| Unit -> tunit
| Int tag i ->
if check_integer_bounds tag i
then type_of_integer_type tag
else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng
| XInt tag _ -> //bounds checked by the syntax
type_of_integer_type tag
| Bool _ -> tbool
let parser_may_fail (env:env) (t:typ) : ML bool =
match t.v with
| Pointer _ -> true
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> attrs.may_fail
| _ -> false
let typ_is_integral env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
match lookup env hd with
| Inr (d, Inl attrs) -> Some? attrs.integral
| _ -> false
let tag_of_integral_typ env (t:typ) : ML (option _) =
match t.v with
| Pointer _ -> None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral
| _ -> None
let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) =
match t.v with
| Pointer _ -> None, None
| Type_app hd _ _ ->
match lookup env hd with
| Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order
| _ -> None, None
let has_reader (env:global_env) (id:ident) : ML bool =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.has_reader
| _ -> false
let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> attrs.parser_kind_nz
| _ -> None
let parser_weak_kind (env:global_env) (id:ident) : ML (option _) =
match H.try_find env.ge_h id.v with
| Some (_, Inl attrs) -> Some attrs.parser_weak_kind
| _ -> None
let rec typ_weak_kind env (t:typ) : ML (option weak_kind) =
match t.v with
| Pointer _ -> typ_weak_kind env tuint64
| Type_app hd _ _ -> parser_weak_kind env.globals hd
let typ_has_reader env (t:typ) : ML bool =
match t.v with
| Pointer _ -> false
| Type_app hd _ _ ->
has_reader env.globals hd
let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match try_lookup env hd with
| Some (Inr (d, _)) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_only env t
| _ -> t
end
| _ -> t
end
| _ -> t
let update_typ_abbrev (env:env) (i:ident) (t:typ)
: ML unit
= match H.try_find env.globals.ge_h i.v with
| Some (d, ms) ->
let d_decl =
match d.d_decl.v with
| TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i }
| _ -> failwith "Expected a type abbreviation"
in
let d = {d with d_decl = d_decl } in
let entry = (d, ms) in
H.insert env.globals.ge_h i.v entry
| _ ->
failwith "Type abbreviation not found"
let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ =
match t.v with
| Type_app hd _ [] -> //type abbreviations are not parameterized
begin
match lookup env hd with
| Inr (d, _) ->
begin
match d.d_decl.v with
| TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t
| Enum t _ _ -> unfold_typ_abbrev_and_enum env t
| _ -> t
end
| _ -> t
end
| _ -> t
let size_of_integral_typ (env:env) (t:typ) r
: ML int
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_of_integral_typ env t with
| None -> failwith "Impossible"
| Some UInt8 -> 1
| Some UInt16 -> 2
| Some UInt32 -> 4
| Some UInt64 -> 8
let bit_order_of_integral_typ (env:env) (t:typ) r
: ML bitfield_bit_order
= let t = unfold_typ_abbrev_and_enum env t in
if not (typ_is_integral env t)
then error (Printf.sprintf "Expected and integral type, got %s"
(print_typ t))
r;
match tag_and_bit_order_of_integral_typ env t with
| _, None -> failwith "Impossible"
| _, Some order -> order
let eq_typ env t1 t2 =
if Ast.eq_typ t1 t2 then true
else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
let eq_typs env ts =
List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
let cast e t t' = { e with v = App (Cast (Some t) t') [e] }
let try_cast_integer env et to : ML (option expr) =
let e, from = et in
let i_to = typ_is_integral env to in
let i_from = typ_is_integral env from in
if i_from && i_to
then
let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in
let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in
if i_from = i_to
then Some e
else if integer_type_leq i_from i_to
then Some (cast e i_from i_to)
else None
else None
let _or_ b1 b2 = b1 || b2
let _and_ b1 b2 = b1 && b2
let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))=
let e1, t1 = e1 in
let e2, t2 = e2 in
let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)"
i
(print_expr e1)
(print_typ t1)
(print_expr e2)
(print_typ t2))) in
try
let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in
if not (typ_is_integral env t1 `_and_`
typ_is_integral env t2)
then fail 1;
let tt1 = typ_as_integer_type t1 in
let tt2 = typ_as_integer_type t2 in
let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in
let e1, e2, t =
if integer_type_leq tt1 tt2
then cast e1 tt1 tt2,
e2,
t2
else if integer_type_leq tt2 tt1
then e1,
cast e2 tt2 tt1,
t1
else fail 0
in
// FStar.IO.print_string
// (Printf.sprintf "Retyped to (%s, %s, %s)\n"
// (print_expr e1)
// (print_expr e2)
// (print_typ t));
Some (e1, e2, t)
with
| Error msg ->
FStar.IO.print_string msg;
None
| _ -> None
(*
* Add output type to the environment
*
* TODO: check_shadow
*)
let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_out_t i d in
insert i.v;
let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in
insert td_abbrev.v
(*
* Add extern type to the environment
*
* TODO: check shadow
*)
let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit =
let insert i = H.insert ge.ge_extern_t i d in
insert i.v;
let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in
insert td_abbrev.v
(*
* Add extern probe function to the environment
*
* TODO: check shadow
*)
let add_extern_probe (ge:global_env) (i:ident) (d:decl{ExternProbe? d.d_decl.v}) : ML unit =
H.insert ge.ge_probe_fn i.v d
(*
* Add extern function to the environment
*
* TODO: check shadow
*)
let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit =
H.insert ge.ge_extern_fn i.v d
let lookup_output_type (ge:global_env) (i:ident) : ML out_typ =
match H.try_find ge.ge_out_t i.v with
| Some ({d_decl={v=OutputType out_t}}) -> out_t
| _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range
(*
* Returns the type of the field, with optional bitwidth if the field is a bitfield
*)
let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) =
let out_t = lookup_output_type ge i in
let rec find (flds:list out_field) : (option (typ & option int)) =
match flds with
| [] -> None
| (Out_field_named f' t n)::tl ->
if eq_idents f f' then Some (t, n)
else find tl
| (Out_field_anon l _)::tl ->
(match find l with
| None -> find tl
| Some t -> Some t) in
match find out_t.out_typ_fields with
| Some t -> t
| None ->
error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range
let lookup_extern_type (ge:global_env) (i:ident) : ML unit =
match H.try_find ge.ge_extern_t i.v with
| Some ({d_decl={v=ExternType _}}) -> ()
| _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) =
match H.try_find ge.ge_extern_fn f.v with
| Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps
| _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
let check_output_type (ge:global_env) (t:typ) : ML ident =
let err () : ML ident =
error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in
match t.v with
| Type_app i KindOutput [] -> i
| _ -> err ()
/// Populated the output expression metadata
///
/// We enforce that the spec cannot take address of output type bitfields
let rec check_out_expr (env:env) (oe0:out_expr)
: ML (oe:out_expr{Some? oe.out_expr_meta}) =
match oe0.out_expr_node.v with
| OE_id i ->
let t = lookup_expr_name env i in
{oe0 with
out_expr_meta = Some ({
out_expr_base_t = t;
out_expr_t = t;
out_expr_bit_width = None})}
| OE_star oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_star oe};
out_expr_meta=Some ({ out_expr_base_t = oe_bt;
out_expr_t = t;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_addrof oe ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_addrof oe};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range;
out_expr_bit_width = None })}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
| OE_deref oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match oe_t.v, bopt with
| Pointer t, None ->
let i = check_output_type (global_env_of_env env) t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_deref oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type"
(print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range)
| OE_dot oe f ->
let oe = check_out_expr env oe in
let { out_expr_base_t = oe_bt;
out_expr_t = oe_t;
out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in
(match bopt with
| None ->
let i = check_output_type (global_env_of_env env) oe_t in
let out_expr_t, out_expr_bit_width = lookup_output_type_field
(global_env_of_env env)
i f in
{oe0 with
out_expr_node={oe0.out_expr_node with v=OE_dot oe f};
out_expr_meta=Some ({
out_expr_base_t = oe_bt;
out_expr_t = out_expr_t;
out_expr_bit_width = out_expr_bit_width})}
| _ ->
error
(Printf.sprintf "Cannot take address of a bit field %s"
(print_out_expr oe0)) oe.out_expr_node.range)
let range_of_typ_param (p:typ_param) = match p with
| Inl e -> e.range
| Inr p -> p.out_expr_node.range | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Options.fsti.checked",
"Hashtable.fsti.checked",
"GlobalEnv.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Binding.fst"
} | [
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "GlobalEnv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Binding.env -> p: Ast.typ_param -> FStar.All.ML (Ast.typ_param * Ast.typ) | FStar.All.ML | [
"ml"
] | [
"check_typ",
"check_ident",
"check_expr",
"check_typ_param"
] | [
"Binding.env",
"Ast.typ_param",
"Ast.expr",
"Ast.typ",
"FStar.Pervasives.Native.Mktuple2",
"Ast.Inl",
"Ast.out_expr",
"FStar.Pervasives.Native.tuple2",
"Binding.check_expr",
"Ast.with_meta_t",
"Ast.typ'",
"FStar.Pervasives.Native.option",
"Prims.int",
"Ast.Inr",
"Ast.error",
"Binding.range_of_typ_param",
"Ast.out_expr_meta_t",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Ast.__proj__Mkout_expr__item__out_expr_meta",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Binding.check_out_expr"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec check_typ_param (env: env) (p: typ_param) : ML (typ_param & typ) =
| match p with
| Inl e ->
let e, t = check_expr env e in
Inl e, t
| Inr o ->
let o = check_out_expr env o in
let { out_expr_t = t ; out_expr_bit_width = bopt } = Some?.v o.out_expr_meta in
(match bopt with
| None -> Inr o, t
| _ -> error ("Type parameter cannot be a bitfield") (range_of_typ_param p)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_p | val tele_p (x: gen_elim_tele) : Tot vprop | val tele_p (x: gen_elim_tele) : Tot vprop | let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x)) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 197,
"start_col": 0,
"start_line": 194
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Steel.ST.GenElim1.Base.gen_elim_tele -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_tele",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.Effect.Common.star",
"Steel.ST.Util.pure",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.tele_p"
] | [
"recursion"
] | false | false | false | true | false | let rec tele_p (x: gen_elim_tele) : Tot vprop =
| match x with
| TRet v p -> v `star` (pure p)
| TExists ty body -> exists_ (fun x -> tele_p (body x)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f | val compute_gen_elim_f (i: gen_elim_i) : GTot (gen_elim_t i) | val compute_gen_elim_f (i: gen_elim_i) : GTot (gen_elim_t i) | let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x)) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 94,
"end_line": 192,
"start_col": 0,
"start_line": 179
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Steel.ST.GenElim1.Base.gen_elim_i -> Prims.GTot (Steel.ST.GenElim1.gen_elim_t i) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.compute_gen_elim_f_unit",
"Steel.ST.GenElim1.compute_gen_elim_f_star_l",
"Steel.ST.GenElim1.compute_gen_elim_f",
"Steel.ST.GenElim1.compute_gen_elim_f_star_r",
"Steel.ST.GenElim1.compute_gen_elim_f_star",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.compute_gen_elim_f_exists_no_abs0",
"Steel.ST.GenElim1.compute_gen_elim_f_exists_unit0",
"Steel.ST.GenElim1.compute_gen_elim_f_exists0",
"Steel.ST.GenElim1.compute_gen_elim_f_exists_no_abs1",
"Steel.ST.GenElim1.compute_gen_elim_f_exists_unit1",
"Steel.ST.GenElim1.compute_gen_elim_f_exists1"
] | [
"recursion"
] | false | false | false | false | false | let rec compute_gen_elim_f (i: gen_elim_i) : GTot (gen_elim_t i) =
| match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_star_vprop_correct | val tele_star_vprop_correct (i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite (((tele_p i) `star` v) `star` (pure p)) (tele_p (tele_star_vprop i v p))) | val tele_star_vprop_correct (i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite (((tele_p i) `star` v) `star` (pure p)) (tele_p (tele_star_vprop i v p))) | let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 113,
"end_line": 245,
"start_col": 0,
"start_line": 235
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Steel.ST.GenElim1.Base.gen_elim_tele -> v: Steel.Effect.Common.vprop -> p: Prims.prop
-> Prims.GTot
(Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p
i)
v)
(Steel.ST.Util.pure p))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star_vprop i v p))) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_tele",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.ST.GenElim1.tele_star_vprop_correct_ret",
"Steel.ST.GenElim1.tele_star_vprop_correct_exists",
"Steel.ST.GenElim1.tele_star_vprop_correct"
] | [
"recursion"
] | false | false | false | false | false | let rec tele_star_vprop_correct (i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite (((tele_p i) `star` v) `star` (pure p)) (tele_p (tele_star_vprop i v p))) =
| match
i returns vprop_rewrite (((tele_p i) `star` v) `star` (pure p)) (tele_p (tele_star_vprop i v p))
with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body ->
tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_unit_elim_f | val compute_gen_unit_elim_f (i: gen_unit_elim_i) : GTot (gen_unit_elim_t i) | val compute_gen_unit_elim_f (i: gen_unit_elim_i) : GTot (gen_unit_elim_t i) | let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 113,
"end_line": 47,
"start_col": 0,
"start_line": 41
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Steel.ST.GenElim1.Base.gen_unit_elim_i -> Prims.GTot (Steel.ST.GenElim1.gen_unit_elim_t i) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.gen_unit_elim_t",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.compute_gen_unit_elim_f_id",
"Prims.prop",
"Steel.ST.GenElim1.compute_gen_unit_elim_f_pure",
"Steel.ST.GenElim1.compute_gen_unit_elim_f_star",
"Steel.ST.GenElim1.compute_gen_unit_elim_f"
] | [
"recursion"
] | false | false | false | false | false | let rec compute_gen_unit_elim_f (i: gen_unit_elim_i) : GTot (gen_unit_elim_t i) =
| match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 ->
compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct | val compute_gen_elim_tele_correct (x: gen_elim_i) : GTot (ge_to_tele_t x) | val compute_gen_elim_tele_correct (x: gen_elim_i) : GTot (ge_to_tele_t x) | let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x)) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 121,
"end_line": 428,
"start_col": 0,
"start_line": 415
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Steel.ST.GenElim1.Base.gen_elim_i -> Prims.GTot (Steel.ST.GenElim1.ge_to_tele_t x) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.ge_to_tele_t",
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_unit",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_star_l",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_star_r",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_star",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_no_abs0",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_unit0",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists0",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_no_abs1",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_unit1",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists1"
] | [
"recursion"
] | false | false | false | false | false | let rec compute_gen_elim_tele_correct (x: gen_elim_i) : GTot (ge_to_tele_t x) =
| match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r ->
compute_gen_elim_tele_correct_star l
(compute_gen_elim_tele_correct l)
r
(compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body ->
compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body ->
compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_star_correct | val tele_star_correct (i1 i2: gen_elim_tele)
: GTot (vprop_rewrite ((tele_p i1) `star` (tele_p i2)) (tele_p (i1 `tele_star` i2))) | val tele_star_correct (i1 i2: gen_elim_tele)
: GTot (vprop_rewrite ((tele_p i1) `star` (tele_p i2)) (tele_p (i1 `tele_star` i2))) | let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 286,
"start_col": 0,
"start_line": 277
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i1: Steel.ST.GenElim1.Base.gen_elim_tele -> i2: Steel.ST.GenElim1.Base.gen_elim_tele
-> Prims.GTot
(Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p i1)
(Steel.ST.GenElim1.tele_p i2))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star i1 i2))) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_tele",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.tele_star_correct_ret_l",
"Steel.ST.GenElim1.Base.TExists",
"Steel.ST.GenElim1.tele_star_correct_ret_r",
"Steel.ST.GenElim1.tele_star_correct_exists",
"Steel.ST.GenElim1.tele_star_correct"
] | [
"recursion"
] | false | false | false | false | false | let rec tele_star_correct (i1 i2: gen_elim_tele)
: GTot (vprop_rewrite ((tele_p i1) `star` (tele_p i2)) (tele_p (i1 `tele_star` i2))) =
| match i1 returns vprop_rewrite ((tele_p i1) `star` (tele_p i2)) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
match
i2
returns
vprop_rewrite ((tele_p (TExists ty1 f1)) `star` (tele_p i2))
(tele_p ((TExists ty1 f1) `tele_star` i2))
with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 ->
tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.gen_elim_nondep_p | val gen_elim_nondep_p (ty: list (Type u#a))
: Tot
(
curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) ->
curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop)
-> Tot vprop) | val gen_elim_nondep_p (ty: list (Type u#a))
: Tot
(
curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) ->
curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop)
-> Tot vprop) | let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 83,
"end_line": 433,
"start_col": 0,
"start_line": 430
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ty: Prims.list Type ->
_:
Steel.ST.GenElim1.Base.curried_function_type ty
(_: FStar.Universe.raise_t Prims.unit -> Steel.Effect.Common.vprop) ->
_:
Steel.ST.GenElim1.Base.curried_function_type ty
(_: FStar.Universe.raise_t Prims.unit -> Prims.prop)
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Steel.ST.GenElim1.Base.curried_function_type",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Prims.Nil",
"Steel.Effect.Common.star",
"FStar.Universe.raise_val",
"Steel.ST.Util.pure",
"Prims.Cons",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.gen_elim_nondep_p"
] | [
"recursion"
] | false | false | false | false | false | let rec gen_elim_nondep_p (ty: list (Type u#a))
: Tot
(
curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) ->
curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop)
-> Tot vprop) =
| match
ty
as ty'
returns
curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) ->
curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop)
-> Tot vprop
with
| [] -> fun q post -> (q (U.raise_val ())) `star` (pure (post (U.raise_val ())))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.gen_elim_nondep_sem_correct | val gen_elim_nondep_sem_correct (ty: list (Type u#a))
: Tot
(q: curried_function_type ty _ -> post: curried_function_type ty _
-> Lemma ((tele_p (gen_elim_nondep_sem ty q post)) `equiv` (gen_elim_nondep_p ty q post))) | val gen_elim_nondep_sem_correct (ty: list (Type u#a))
: Tot
(q: curried_function_type ty _ -> post: curried_function_type ty _
-> Lemma ((tele_p (gen_elim_nondep_sem ty q post)) `equiv` (gen_elim_nondep_p ty q post))) | let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf () | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 460,
"start_col": 0,
"start_line": 435
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ty: Prims.list Type ->
q:
Steel.ST.GenElim1.Base.curried_function_type ty
(_: FStar.Universe.raise_t Prims.unit -> Steel.Effect.Common.vprop) ->
post:
Steel.ST.GenElim1.Base.curried_function_type ty
(_: FStar.Universe.raise_t Prims.unit -> Prims.prop)
-> FStar.Pervasives.Lemma
(ensures
Steel.Effect.Common.equiv (Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.gen_elim_nondep_sem
ty
q
post))
(Steel.ST.GenElim1.gen_elim_nondep_p ty q post)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Steel.ST.GenElim1.Base.curried_function_type",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Prims.l_True",
"Prims.squash",
"Steel.Effect.Common.equiv",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.gen_elim_nondep_sem",
"Steel.ST.GenElim1.gen_elim_nondep_p",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Steel.Effect.Common.equiv_refl",
"Steel.Effect.Common.star",
"FStar.Universe.raise_val",
"Steel.ST.Util.pure",
"Prims.Cons",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Steel.ST.Util.exists_",
"Steel.ST.Util.exists_equiv",
"FStar.Classical.forall_intro",
"Steel.ST.GenElim1.gen_elim_nondep_sem_correct"
] | [
"recursion"
] | false | false | true | false | false | let rec gen_elim_nondep_sem_correct (ty: list (Type u#a))
: Tot
(q: curried_function_type ty _ -> post: curried_function_type ty _
-> Lemma ((tele_p (gen_elim_nondep_sem ty q post)) `equiv` (gen_elim_nondep_p ty q post))) =
| match
ty
returns
(q: curried_function_type ty _ -> post: curried_function_type ty _
-> Lemma
((tele_p (gen_elim_nondep_sem ty q post)) `equiv` (gen_elim_nondep_p ty q post)))
with
| [] -> fun q post -> equiv_refl ((q (U.raise_val ())) `star` (pure (post (U.raise_val ()))))
| ta :: tq ->
fun q post ->
let phi (x: ta)
: Lemma
((tele_p (gen_elim_nondep_sem tq (q x) (post x)))
`equiv`
(gen_elim_nondep_p tq (q x) (post x))) =
gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf ()
: Lemma
((exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))))
`equiv`
(exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))) =
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x)))
(fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) ==
exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post ==
exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf () | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.coerce_with_smt | val coerce_with_smt (#tfrom #tto: Type) (x: tfrom)
: Pure tto (requires ((tfrom == tto))) (ensures (fun _ -> True)) | val coerce_with_smt (#tfrom #tto: Type) (x: tfrom)
: Pure tto (requires ((tfrom == tto))) (ensures (fun _ -> True)) | let coerce_with_smt (#tfrom #tto: Type) (x: tfrom) : Pure tto (requires ( (tfrom == tto))) (ensures (fun _ -> True)) = x | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 120,
"end_line": 829,
"start_col": 0,
"start_line": 829
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq
let compute_gen_elim_nondep_correct_0
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
= match i returns
(sq: squash (check_gen_elim_nondep_sem i0 i)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i)
)
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post -> fun _ ->
let intro : vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) = fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro
let compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot (gen_elim_f
(compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)
)
= fun _ ->
let res0 = compute_gen_elim_nondep_correct_0 i0 i sq _ in
let res = Ghost.hide res0 in
rewrite (compute_gen_elim_nondep_q0 i0 i res0) (compute_gen_elim_nondep_q i0 i res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: tfrom -> Prims.Pure tto | Prims.Pure | [] | [] | [
"Prims.eq2",
"Prims.l_True"
] | [] | false | false | false | false | false | let coerce_with_smt (#tfrom #tto: Type) (x: tfrom)
: Pure tto (requires ((tfrom == tto))) (ensures (fun _ -> True)) =
| x | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_unit | val compute_gen_elim_f_unit (i: gen_unit_elim_i) : GTot (gen_elim_t (GEUnit i)) | val compute_gen_elim_f_unit (i: gen_unit_elim_i) : GTot (gen_elim_t (GEUnit i)) | let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 55,
"start_col": 0,
"start_line": 52
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Steel.ST.GenElim1.Base.gen_unit_elim_i
-> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEUnit i)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.ST.GenElim1.Base.GEUnit"
] | [] | false | false | false | false | false | let compute_gen_elim_f_unit (i: gen_unit_elim_i) : GTot (gen_elim_t (GEUnit i)) =
| compute_gen_unit_elim_f i | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.gen_elim_dep | val gen_elim_dep
(#opened: _)
(#[@@@ framing_implicit] p: vprop)
(#[@@@ framing_implicit] a: Type)
(#[@@@ framing_implicit] q: Ghost.erased a -> Tot vprop)
(#[@@@ framing_implicit] post: Ghost.erased a -> Tot prop)
(#[@@@ framing_implicit] sq: squash (gen_elim_prop_placeholder false p a q post))
(_: unit)
: STGhostF (Ghost.erased a) opened p (fun x -> guard_vprop (q x)) ( (T.with_tactic solve_gen_elim_prop) (squash (gen_elim_prop false p a q post))) post | val gen_elim_dep
(#opened: _)
(#[@@@ framing_implicit] p: vprop)
(#[@@@ framing_implicit] a: Type)
(#[@@@ framing_implicit] q: Ghost.erased a -> Tot vprop)
(#[@@@ framing_implicit] post: Ghost.erased a -> Tot prop)
(#[@@@ framing_implicit] sq: squash (gen_elim_prop_placeholder false p a q post))
(_: unit)
: STGhostF (Ghost.erased a) opened p (fun x -> guard_vprop (q x)) ( (T.with_tactic solve_gen_elim_prop) (squash (gen_elim_prop false p a q post))) post | let gen_elim_dep
#opened #p #a #q #post #sq _
= gen_elim' #opened _ p a q post sq () | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 847,
"start_col": 0,
"start_line": 845
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq
let compute_gen_elim_nondep_correct_0
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
= match i returns
(sq: squash (check_gen_elim_nondep_sem i0 i)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i)
)
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post -> fun _ ->
let intro : vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) = fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro
let compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot (gen_elim_f
(compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)
)
= fun _ ->
let res0 = compute_gen_elim_nondep_correct_0 i0 i sq _ in
let res = Ghost.hide res0 in
rewrite (compute_gen_elim_nondep_q0 i0 i res0) (compute_gen_elim_nondep_q i0 i res);
res
let coerce_with_smt (#tfrom #tto: Type) (x: tfrom) : Pure tto (requires ( (tfrom == tto))) (ensures (fun _ -> True)) = x
let gen_elim'
#opened enable_nondep_opt p a q post _ ()
=
let (i, j) = gen_elim_prop_elim enable_nondep_opt p a q post in
rewrite p (compute_gen_elim_p i);
let res' = compute_gen_elim_nondep_correct i j () _ in
let res : Ghost.erased a = Ghost.hide (coerce_with_smt (Ghost.reveal res')) in
rewrite (compute_gen_elim_nondep_q i j res') (guard_vprop (q res));
res
let gen_elim
#opened #p #a #q #post #sq _
= gen_elim' #opened _ p a q post sq () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Steel.ST.Effect.Ghost.STGhostF (FStar.Ghost.erased a) | Steel.ST.Effect.Ghost.STGhostF | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Ghost.erased",
"Prims.prop",
"Prims.squash",
"Steel.ST.GenElim1.Base.gen_elim_prop_placeholder",
"Prims.unit",
"Steel.ST.GenElim1.gen_elim'"
] | [] | false | true | false | false | false | let gen_elim_dep #opened #p #a #q #post #sq _ =
| gen_elim' #opened _ p a q post sq () | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.gen_elim | val gen_elim
(#opened: _)
(#[@@@ framing_implicit] p: vprop)
(#[@@@ framing_implicit] a: Type)
(#[@@@ framing_implicit] q: Ghost.erased a -> Tot vprop)
(#[@@@ framing_implicit] post: Ghost.erased a -> Tot prop)
(#[@@@ framing_implicit] sq: squash (gen_elim_prop_placeholder true p a q post))
(_: unit)
: STGhostF (Ghost.erased a) opened p (fun x -> guard_vprop (q x)) ( (T.with_tactic solve_gen_elim_prop) (squash (gen_elim_prop true p a q post))) post | val gen_elim
(#opened: _)
(#[@@@ framing_implicit] p: vprop)
(#[@@@ framing_implicit] a: Type)
(#[@@@ framing_implicit] q: Ghost.erased a -> Tot vprop)
(#[@@@ framing_implicit] post: Ghost.erased a -> Tot prop)
(#[@@@ framing_implicit] sq: squash (gen_elim_prop_placeholder true p a q post))
(_: unit)
: STGhostF (Ghost.erased a) opened p (fun x -> guard_vprop (q x)) ( (T.with_tactic solve_gen_elim_prop) (squash (gen_elim_prop true p a q post))) post | let gen_elim
#opened #p #a #q #post #sq _
= gen_elim' #opened _ p a q post sq () | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 843,
"start_col": 0,
"start_line": 841
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq
let compute_gen_elim_nondep_correct_0
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
= match i returns
(sq: squash (check_gen_elim_nondep_sem i0 i)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i)
)
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post -> fun _ ->
let intro : vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) = fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro
let compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot (gen_elim_f
(compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)
)
= fun _ ->
let res0 = compute_gen_elim_nondep_correct_0 i0 i sq _ in
let res = Ghost.hide res0 in
rewrite (compute_gen_elim_nondep_q0 i0 i res0) (compute_gen_elim_nondep_q i0 i res);
res
let coerce_with_smt (#tfrom #tto: Type) (x: tfrom) : Pure tto (requires ( (tfrom == tto))) (ensures (fun _ -> True)) = x
let gen_elim'
#opened enable_nondep_opt p a q post _ ()
=
let (i, j) = gen_elim_prop_elim enable_nondep_opt p a q post in
rewrite p (compute_gen_elim_p i);
let res' = compute_gen_elim_nondep_correct i j () _ in
let res : Ghost.erased a = Ghost.hide (coerce_with_smt (Ghost.reveal res')) in
rewrite (compute_gen_elim_nondep_q i j res') (guard_vprop (q res));
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Steel.ST.Effect.Ghost.STGhostF (FStar.Ghost.erased a) | Steel.ST.Effect.Ghost.STGhostF | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Ghost.erased",
"Prims.prop",
"Prims.squash",
"Steel.ST.GenElim1.Base.gen_elim_prop_placeholder",
"Prims.unit",
"Steel.ST.GenElim1.gen_elim'"
] | [] | false | true | false | false | false | let gen_elim #opened #p #a #q #post #sq _ =
| gen_elim' #opened _ p a q post sq () | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct' | val compute_gen_elim_nondep_correct' (i0: gen_elim_i) (ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty) | val compute_gen_elim_nondep_correct' (i0: gen_elim_i) (ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty) | let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 202,
"end_line": 789,
"start_col": 0,
"start_line": 769
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i0: Steel.ST.GenElim1.Base.gen_elim_i -> ty: Prims.list Type
-> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0 ty | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Prims.list",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct0",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct1",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct2",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct3",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct4",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct5",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct6",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct7",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct8",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct9",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct10",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct11",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct12",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct13",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct14",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_default"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct' (i0: gen_elim_i) (ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty) =
| match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1 ; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1 ; t2 ; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1 ; t2 ; t3 ; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1 ; t2 ; t3 ; t4 ; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8] ->
compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8 ; t9] ->
compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8 ; t9 ; t10] ->
compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8 ; t9 ; t10 ; t11] ->
compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8 ; t9 ; t10 ; t11 ; t12] ->
compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8 ; t9 ; t10 ; t11 ; t12 ; t13] ->
compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1 ; t2 ; t3 ; t4 ; t5 ; t6 ; t7 ; t8 ; t9 ; t10 ; t11 ; t12 ; t13 ; t14] ->
compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq ->
compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq | false |
Hacl.Bignum25519.fst | Hacl.Bignum25519.times_2 | val times_2:
out:felem
-> a:felem ->
Stack unit
(requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.felem_fits h1 out (2, 4, 2, 2, 2) /\
F51.fevalh h1 out == 2 `SC.fmul` F51.fevalh h0 a
) | val times_2:
out:felem
-> a:felem ->
Stack unit
(requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.felem_fits h1 out (2, 4, 2, 2, 2) /\
F51.fevalh h1 out == 2 `SC.fmul` F51.fevalh h0 a
) | let times_2 out a =
(**) let h0 = ST.get() in
let a0 = a.(0ul) in
let a1 = a.(1ul) in
let a2 = a.(2ul) in
let a3 = a.(3ul) in
let a4 = a.(4ul) in
let o0 = u64 2 *. a0 in
let o1 = u64 2 *. a1 in
let o2 = u64 2 *. a2 in
let o3 = u64 2 *. a3 in
let o4 = u64 2 *. a4 in
make_u64_5 out o0 o1 o2 o3 o4;
(**) let h1 = ST.get() in
(**) assert (S51.felem_fits1 a0 1);
(**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2));
calc (==) {
(2 * (F51.fevalh h0 a)) % SC.prime;
(==) { calc (==) {
F51.fevalh h0 a;
(==) { }
S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime;
}
}
(2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime;
(==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime }
(2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime;
(==) { calc (==) {
2 * S51.as_nat5 (a0, a1, a2, a3, a4);
(==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) }
2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 +
2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 +
2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51;
(==) {
assert_norm (2 * S51.pow51 < pow2 64);
assert_norm (4 * S51.pow51 < pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64)
}
S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4);
}
}
S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime;
(==) { }
F51.fevalh h1 out;
} | {
"file_name": "code/ed25519/Hacl.Bignum25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 176,
"start_col": 0,
"start_line": 126
} | module Hacl.Bignum25519
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module S51 = Hacl.Spec.Curve25519.Field51.Definition
module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas
module BN = Hacl.Impl.Curve25519.Field51
module SC = Spec.Curve25519
friend Hacl.Curve25519_51
#reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let mask_51 = u64 0x7ffffffffffff
let make_u64_5 b s0 s1 s2 s3 s4 =
b.(0ul) <- s0;
b.(1ul) <- s1;
b.(2ul) <- s2;
b.(3ul) <- s3;
b.(4ul) <- s4
let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 =
b.(0ul) <- s0;
b.(1ul) <- s1;
b.(2ul) <- s2;
b.(3ul) <- s3;
b.(4ul) <- s4;
b.(5ul) <- s5;
b.(6ul) <- s6;
b.(7ul) <- s7;
b.(8ul) <- s8;
b.(9ul) <- s9
let make_zero b =
b.(0ul) <- u64 0;
b.(1ul) <- u64 0;
b.(2ul) <- u64 0;
b.(3ul) <- u64 0;
b.(4ul) <- u64 0;
assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0)
let make_one b =
b.(0ul) <- u64 1;
b.(1ul) <- u64 0;
b.(2ul) <- u64 0;
b.(3ul) <- u64 0;
b.(4ul) <- u64 0;
assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1)
[@CInline]
let fsum out a b =
BN.fadd out a b
[@CInline]
let fdifference out a b =
BN.fsub out a b
inline_for_extraction noextract
val carry51:
#m:S51.scale64{m < 8192}
-> l:uint64
-> cin:uint64 ->
Pure (uint64 & uint64)
(requires
S51.felem_fits1 l m /\
S51.felem_fits1 cin 1)
(ensures fun (l0, l1) ->
v l + v cin == v l1 * pow2 51 + v l0 /\
S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1)
let carry51 l cin =
let l' = l +! cin in
mod_mask_lemma l' 51ul;
assert (v (mod_mask #U64 #SEC 51ul) == v mask_51);
FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64;
FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51);
FStar.Math.Lemmas.pow2_minus 64 51;
(l' &. mask_51, l' >>. 51ul)
let reduce_513 a =
let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in
let tmp0, c0 = carry51 #9 f0 (u64 0) in
let tmp1, c1 = carry51 #10 f1 c0 in
let tmp2, c2 = carry51 #9 f2 c1 in
let tmp3, c3 = carry51 #9 f3 c2 in
let tmp4, c4 = carry51 #9 f4 c3 in
assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1));
SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4;
assert (
S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime ==
(S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime);
[@inline_let]
let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in
[@inline_let]
let tmp1' = tmp1 +! c5 in
Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5;
make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4
[@CInline]
let fmul output input input2 =
push_frame();
let tmp = create 10ul (u128 0) in
BN.fmul output input input2 tmp;
pop_frame() | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field51.Definition.fst.checked",
"Hacl.Spec.Curve25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.Field51.fst.checked",
"Hacl.Curve25519_51.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum25519.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field51",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field51.Lemmas",
"short_module": "SL51"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field51.Definition",
"short_module": "S51"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field51.Definition",
"short_module": "S51"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum25519.felem",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Hacl.Impl.Ed25519.Field51.fevalh",
"Spec.Curve25519.prime",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Hacl.Spec.Curve25519.Field51.Definition.as_nat5",
"FStar.Pervasives.Native.Mktuple5",
"Lib.IntTypes.uint64",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.u64",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Spec.Curve25519.elem",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Hacl.Spec.Curve25519.Field51.Definition.pow51",
"Hacl.Spec.Curve25519.Field51.Lemmas.lemma_smul_felem5",
"FStar.Math.Lemmas.small_mod",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims._assert",
"Hacl.Impl.Ed25519.Field51.felem_fits",
"Prims.nat",
"Hacl.Spec.Curve25519.Field51.Definition.felem_fits1",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum25519.make_u64_5",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t"
] | [] | false | true | false | false | false | let times_2 out a =
| let h0 = ST.get () in
let a0 = a.(0ul) in
let a1 = a.(1ul) in
let a2 = a.(2ul) in
let a3 = a.(3ul) in
let a4 = a.(4ul) in
let o0 = u64 2 *. a0 in
let o1 = u64 2 *. a1 in
let o2 = u64 2 *. a2 in
let o3 = u64 2 *. a3 in
let o4 = u64 2 *. a4 in
make_u64_5 out o0 o1 o2 o3 o4;
let h1 = ST.get () in
assert (S51.felem_fits1 a0 1);
assert (F51.felem_fits h1 out (2, 4, 2, 2, 2));
calc ( == ) {
(2 * (F51.fevalh h0 a)) % SC.prime;
( == ) { calc ( == ) {
F51.fevalh h0 a;
( == ) { () }
S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime;
} }
(2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime;
( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime }
(2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime;
( == ) { calc ( == ) {
2 * S51.as_nat5 (a0, a1, a2, a3, a4);
( == ) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) }
2 * v a0 + (2 * v a1) * S51.pow51 + ((2 * v a2) * S51.pow51) * S51.pow51 +
(((2 * v a3) * S51.pow51) * S51.pow51) * S51.pow51 +
((((2 * v a4) * S51.pow51) * S51.pow51) * S51.pow51) * S51.pow51;
( == ) { (assert_norm (2 * S51.pow51 < pow2 64);
assert_norm (4 * S51.pow51 < pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64);
FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64)) }
S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4);
} }
S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime;
( == ) { () }
F51.fevalh h1 out;
} | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_unit_elim_f_id | val compute_gen_unit_elim_f_id (v: vprop) : Tot (gen_unit_elim_t (GUEId v)) | val compute_gen_unit_elim_f_id (v: vprop) : Tot (gen_unit_elim_t (GUEId v)) | let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val () | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 19,
"start_col": 0,
"start_line": 16
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Steel.Effect.Common.vprop -> Steel.ST.GenElim1.gen_unit_elim_t (Steel.ST.GenElim1.Base.GUEId v) | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.inames",
"FStar.Universe.raise_val",
"Prims.unit",
"FStar.Universe.raise_t",
"Steel.ST.Util.noop",
"Steel.ST.GenElim1.gen_unit_elim_t",
"Steel.ST.GenElim1.Base.GUEId"
] | [] | false | false | false | false | false | let compute_gen_unit_elim_f_id (v: vprop) : Tot (gen_unit_elim_t (GUEId v)) =
| fun _ ->
noop ();
U.raise_val () | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_unit_elim_f_pure | val compute_gen_unit_elim_f_pure (p: prop) : Tot (gen_unit_elim_t (GUEPure p)) | val compute_gen_unit_elim_f_pure (p: prop) : Tot (gen_unit_elim_t (GUEPure p)) | let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val () | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 27,
"start_col": 0,
"start_line": 21
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Prims.prop -> Steel.ST.GenElim1.gen_unit_elim_t (Steel.ST.GenElim1.Base.GUEPure p) | Prims.Tot | [
"total"
] | [] | [
"Prims.prop",
"Steel.Memory.inames",
"FStar.Universe.raise_val",
"Prims.unit",
"FStar.Universe.raise_t",
"Steel.ST.Util.elim_pure",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.ST.GenElim1.Base.GUEPure",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.gen_unit_elim_t"
] | [] | false | false | false | false | false | let compute_gen_unit_elim_f_pure (p: prop) : Tot (gen_unit_elim_t (GUEPure p)) =
| fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val () | false |
ArrayUtils.fst | ArrayUtils.init_at_seq | val init_at_seq (#a: Type0) (s: seq (option a)) (i: nat{i < length s}) : Type0 | val init_at_seq (#a: Type0) (s: seq (option a)) (i: nat{i < length s}) : Type0 | let init_at_seq (#a:Type0) (s:seq (option a)) (i:nat{i < length s}) :Type0
= Some? (index s i) | {
"file_name": "examples/preorders/ArrayUtils.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module ArrayUtils
open FStar.Seq
(*
* some utilities for the array library, mostly straightforward manipulations of sequences
*)
(*****) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "ArrayUtils.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq (FStar.Pervasives.Native.option a) ->
i: Prims.nat{i < FStar.Seq.Base.length s}
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.option",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Base.index"
] | [] | false | false | false | false | true | let init_at_seq (#a: Type0) (s: seq (option a)) (i: nat{i < length s}) : Type0 =
| Some? (index s i) | false |
ArrayUtils.fst | ArrayUtils.all_some | val all_some (#a: Type0) (s: seq (option a)) : Type0 | val all_some (#a: Type0) (s: seq (option a)) : Type0 | let all_some (#a:Type0) (s:seq (option a)) :Type0
= forall (i:nat). i < length s ==> Some? (index s i) | {
"file_name": "examples/preorders/ArrayUtils.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 30,
"start_col": 0,
"start_line": 29
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module ArrayUtils
open FStar.Seq
(*
* some utilities for the array library, mostly straightforward manipulations of sequences
*)
(*****)
let init_at_seq (#a:Type0) (s:seq (option a)) (i:nat{i < length s}) :Type0
= Some? (index s i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "ArrayUtils.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq (FStar.Pervasives.Native.option a) -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.option",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Base.index"
] | [] | false | false | false | true | true | let all_some (#a: Type0) (s: seq (option a)) : Type0 =
| forall (i: nat). i < length s ==> Some? (index s i) | false |
Vale.Def.Prop_s.fst | Vale.Def.Prop_s.prop0 | val prop0 : Type | let prop0 = Type0 | {
"file_name": "vale/specs/defs/Vale.Def.Prop_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 9,
"start_col": 0,
"start_line": 9
} | module Vale.Def.Prop_s
open FStar.Mul
// Prims.logical (which is private to Prims) and prop0 are synonyms for Type0 in F*,
// but are not synonyms in Vale's type system:
// - importFStarTypes.exe interprets Prims.logical and prop0 as "prop"
// - importFStarTypes.exe interprets Type0 as "Type(0)" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Prop_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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"
} | false | Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let prop0 =
| Type0 | false |
|
ArrayUtils.fst | ArrayUtils.some_equivalent_seqs | val some_equivalent_seqs (#a: Type0) (s1: Seq.seq (option a)) (s2: Seq.seq a) : Type0 | val some_equivalent_seqs (#a: Type0) (s1: Seq.seq (option a)) (s2: Seq.seq a) : Type0 | let some_equivalent_seqs (#a:Type0) (s1:Seq.seq (option a)) (s2:Seq.seq a) :Type0
= (Seq.length s1 == Seq.length s2) /\
(forall (i:nat). i < Seq.length s1 ==> Some (Seq.index s2 i) == Seq.index s1 i) | {
"file_name": "examples/preorders/ArrayUtils.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 83,
"end_line": 37,
"start_col": 0,
"start_line": 35
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module ArrayUtils
open FStar.Seq
(*
* some utilities for the array library, mostly straightforward manipulations of sequences
*)
(*****)
let init_at_seq (#a:Type0) (s:seq (option a)) (i:nat{i < length s}) :Type0
= Some? (index s i)
let all_some (#a:Type0) (s:seq (option a)) :Type0
= forall (i:nat). i < length s ==> Some? (index s i)
(*
* a sequence of option a is equivalent to a sequence of a, if all are Some and contained values match | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "ArrayUtils.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq (FStar.Pervasives.Native.option a) -> s2: FStar.Seq.Base.seq a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.option",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Some",
"FStar.Seq.Base.index"
] | [] | false | false | false | true | true | let some_equivalent_seqs (#a: Type0) (s1: Seq.seq (option a)) (s2: Seq.seq a) : Type0 =
| (Seq.length s1 == Seq.length s2) /\
(forall (i: nat). i < Seq.length s1 ==> Some (Seq.index s2 i) == Seq.index s1 i) | false |
ArrayUtils.fst | ArrayUtils.is_prefix_of | val is_prefix_of (#a: Type) (s1 s2: seq a) : Type0 | val is_prefix_of (#a: Type) (s1 s2: seq a) : Type0 | let is_prefix_of (#a:Type) (s1:seq a) (s2:seq a) :Type0
= length s1 <= length s2 /\
(forall (i:nat). i < length s1 ==> Seq.index s1 i == Seq.index s2 i) | {
"file_name": "examples/preorders/ArrayUtils.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 106,
"start_col": 0,
"start_line": 104
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module ArrayUtils
open FStar.Seq
(*
* some utilities for the array library, mostly straightforward manipulations of sequences
*)
(*****)
let init_at_seq (#a:Type0) (s:seq (option a)) (i:nat{i < length s}) :Type0
= Some? (index s i)
let all_some (#a:Type0) (s:seq (option a)) :Type0
= forall (i:nat). i < length s ==> Some? (index s i)
(*
* a sequence of option a is equivalent to a sequence of a, if all are Some and contained values match
*)
let some_equivalent_seqs (#a:Type0) (s1:Seq.seq (option a)) (s2:Seq.seq a) :Type0
= (Seq.length s1 == Seq.length s2) /\
(forall (i:nat). i < Seq.length s1 ==> Some (Seq.index s2 i) == Seq.index s1 i)
(*
* given a sequence of option a, where all indices have Some values, get a seq a
*)
assume val get_some_equivalent (#a:Type0) (s:Seq.seq (option a))
: Pure (seq a)
(requires (all_some s))
(ensures (fun r -> some_equivalent_seqs s r))
let lemma_get_some_equivalent_length (#a:Type0) (s:seq (option a))
:Lemma (requires (all_some s))
(ensures (all_some s /\
length (get_some_equivalent s) == length s))
[SMTPat (length (get_some_equivalent s))]
= ()
let lemma_get_some_equivalent_index (#a:Type0) (s:seq (option a)) (i:nat)
:Lemma (requires (all_some s /\ i < length s))
(ensures (all_some s /\ i < length s /\
Some? (index s i) /\ Some (index (get_some_equivalent s) i) == index s i))
[SMTPat (index (get_some_equivalent s) i)]
= ()
assume val lemma_get_some_equivalent_snoc (#a:Type0) (s:seq (option a)) (x:option a)
:Lemma (requires (all_some s /\ Some? x))
(ensures (all_some s /\ Some? x /\
get_some_equivalent (snoc s x) == snoc (get_some_equivalent s) (Some?.v x)))
[SMTPatOr [[SMTPat (get_some_equivalent (snoc s x))]; [SMTPat (snoc (get_some_equivalent s) (Some?.v x))]]]
assume val lemma_get_some_equivalent_append (#a:Type0) (s1:seq (option a)) (s2:seq (option a))
:Lemma (requires (all_some s1 /\ all_some s2))
(ensures (all_some s1 /\ all_some s2 /\
get_some_equivalent (append s1 s2) == append (get_some_equivalent s1) (get_some_equivalent s2)))
[SMTPatOr [[SMTPat (get_some_equivalent (append s1 s2))]; [SMTPat (append (get_some_equivalent s1) (get_some_equivalent s2))]]]
assume val lemma_get_some_equivalent_slice (#a:Type0) (s:seq (option a)) (i:nat) (j:nat)
:Lemma (requires (all_some s /\ j >= i /\ j <= Seq.length s))
(ensures (all_some s /\ j >= i /\ j <= Seq.length s /\
get_some_equivalent (slice s i j) == slice (get_some_equivalent s) i j))
[SMTPatOr [[SMTPat (get_some_equivalent (slice s i j))]; [SMTPat (slice (get_some_equivalent s) i j)]]]
let lemma_get_equivalent_sequence_slice
(#a:Type0) (s:seq (option a)) (i:nat) (j:nat)
(s':seq a)
:Lemma (requires (j >= i /\ j <= Seq.length s /\
Seq.length s' = j - i /\
(forall (k:nat). (k >= i /\ k < j) ==> Seq.index s k == Some (Seq.index s' (k - i)))))
(ensures (j >= i /\ j <= Seq.length s /\
Seq.length s' = j - i /\
(forall (k:nat). (k >= i /\ k < j) ==> Seq.index s k == Some (Seq.index s' (k - i))) /\
get_some_equivalent (Seq.slice s i j) == s'))
= admit ()
assume val copy_seq (#a:Type0) (s1:seq (option a)) (i:nat) (j:nat) (s2:seq a)
:Pure (seq (option a))
(requires (j >= i /\ j <= Seq.length s1 /\ Seq.length s2 = j - i))
(ensures (fun r -> j >= i /\ j <= Seq.length s1 /\ Seq.length s2 = j - i /\
Seq.length r == Seq.length s1 /\
(forall (off:nat) (n:nat). (off + n <= Seq.length s1 /\ (off + n <= i \/ j <= off)) ==>
Seq.slice s1 off (off + n) == Seq.slice r off (off + n)) /\
(forall (k:nat).
(k < i ==> (Seq.index r k == Seq.index s1 k)) /\
((k >= i /\ k < j) ==> (Seq.index r k == Some (Seq.index s2 (k - i)))) /\
((k >= j /\ k < Seq.length s1) ==> (Seq.index r k == Seq.index s1 k))))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "ArrayUtils.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.index"
] | [] | false | false | false | true | true | let is_prefix_of (#a: Type) (s1 s2: seq a) : Type0 =
| length s1 <= length s2 /\ (forall (i: nat). i < length s1 ==> Seq.index s1 i == Seq.index s2 i) | false |
LowParse.Tot.Base.fst | LowParse.Tot.Base.bare_parser | val bare_parser : t: Type -> Type | let bare_parser = tot_bare_parser | {
"file_name": "src/lowparse/LowParse.Tot.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 5,
"start_col": 0,
"start_line": 5
} | module LowParse.Tot.Base
include LowParse.Spec.Base | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Base.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Tot.Base.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.tot_bare_parser"
] | [] | false | false | false | true | true | let bare_parser =
| tot_bare_parser | false |
|
LowParse.Tot.Base.fst | LowParse.Tot.Base.parser | val parser : k: LowParse.Spec.Base.parser_kind -> t: Type -> Type | let parser = tot_parser | {
"file_name": "src/lowparse/LowParse.Tot.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 23,
"end_line": 8,
"start_col": 0,
"start_line": 8
} | module LowParse.Tot.Base
include LowParse.Spec.Base
inline_for_extraction
let bare_parser = tot_bare_parser | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Base.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Tot.Base.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: LowParse.Spec.Base.parser_kind -> t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.tot_parser"
] | [] | false | false | false | true | true | let parser =
| tot_parser | false |
|
Steel.ST.C.Types.Scalar.fsti | Steel.ST.C.Types.Scalar.scalar_unique | val scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t))
: STGhost unit
opened
((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1))
`star`
(pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)))
(fun _ ->
(pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1))
`star`
(pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)))
(True)
(fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) | val scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t))
: STGhost unit
opened
((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1))
`star`
(pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)))
(fun _ ->
(pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1))
`star`
(pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)))
(True)
(fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) | let scalar_unique
(#opened: _)
(#t: Type)
(v1 v2: t)
(p1 p2: P.perm)
(r: ref (scalar t))
: STGhost unit opened
(pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))
(fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))
(True)
(fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm)
= fractional_permissions_theorem (mk_scalar v1) (mk_scalar v2) p1 p2 r;
mk_scalar_inj v1 v2 P.full_perm P.full_perm | {
"file_name": "lib/steel/c/Steel.ST.C.Types.Scalar.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 48,
"start_col": 0,
"start_line": 36
} | module Steel.ST.C.Types.Scalar
open Steel.ST.Util
include Steel.ST.C.Types.Base
module P = Steel.FractionalPermission
// To be extracted as: t
[@@noextract_to "krml"] // primitive
val scalar_t ( [@@@strictly_positive] t: Type0) : Type0
[@@noextract_to "krml"] // proof-only
val scalar (t: Type) : typedef (scalar_t t)
val mk_scalar (#t: Type) (v: t) : Ghost (scalar_t t)
(requires True)
(ensures (fun y ->
fractionable (scalar t) y /\
full (scalar t) y
))
val mk_scalar_fractionable
(#t: Type)
(v: t)
(p: P.perm)
: Lemma
(requires (fractionable (scalar t) (mk_fraction (scalar t) (mk_scalar v) p)))
(ensures (p `P.lesser_equal_perm` P.full_perm))
val mk_scalar_inj
(#t: Type)
(v1 v2: t)
(p1 p2: P.perm)
: Lemma
(requires (mk_fraction (scalar t) (mk_scalar v1) p1 == mk_fraction (scalar t) (mk_scalar v2) p2))
(ensures (v1 == v2 /\ p1 == p2))
[SMTPat [mk_fraction (scalar t) (mk_scalar v1) p1; mk_fraction (scalar t) (mk_scalar v2) p2]] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.C.Types.Base.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.C.Types.Scalar.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
v1: t ->
v2: t ->
p1: Steel.FractionalPermission.perm ->
p2: Steel.FractionalPermission.perm ->
r: Steel.ST.C.Types.Base.ref (Steel.ST.C.Types.Scalar.scalar t)
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.C.Types.Base.ref",
"Steel.ST.C.Types.Scalar.scalar_t",
"Steel.ST.C.Types.Scalar.scalar",
"Steel.ST.C.Types.Scalar.mk_scalar_inj",
"Steel.FractionalPermission.full_perm",
"Prims.unit",
"Steel.ST.C.Types.Base.fractional_permissions_theorem",
"Steel.ST.C.Types.Scalar.mk_scalar",
"Steel.Effect.Common.star",
"Steel.ST.C.Types.Base.pts_to",
"FStar.Ghost.hide",
"Steel.ST.C.Types.Base.mk_fraction",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.b2t",
"Steel.FractionalPermission.lesser_equal_perm",
"Steel.FractionalPermission.sum_perm"
] | [] | false | true | false | false | false | let scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t))
: STGhost unit
opened
((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1))
`star`
(pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)))
(fun _ ->
(pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1))
`star`
(pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)))
(True)
(fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) =
| fractional_permissions_theorem (mk_scalar v1) (mk_scalar v2) p1 p2 r;
mk_scalar_inj v1 v2 P.full_perm P.full_perm | false |
LowParse.Tot.Base.fst | LowParse.Tot.Base.weaken | val weaken : k1: LowParse.Spec.Base.parser_kind -> p2: LowParse.Spec.Base.tot_parser k2 t
-> Prims.Pure (LowParse.Spec.Base.tot_parser k1 t) | let weaken = tot_weaken | {
"file_name": "src/lowparse/LowParse.Tot.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 23,
"end_line": 19,
"start_col": 0,
"start_line": 19
} | module LowParse.Tot.Base
include LowParse.Spec.Base
inline_for_extraction
let bare_parser = tot_bare_parser
inline_for_extraction
let parser = tot_parser
inline_for_extraction
let serializer
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= serializer #k p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Base.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Tot.Base.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k1: LowParse.Spec.Base.parser_kind -> p2: LowParse.Spec.Base.tot_parser k2 t
-> Prims.Pure (LowParse.Spec.Base.tot_parser k1 t) | Prims.Pure | [] | [] | [
"LowParse.Spec.Base.tot_weaken"
] | [] | false | false | false | false | false | let weaken =
| tot_weaken | false |
|
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct_default | val compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type)
(tq: list Type)
: Tot
(compute_gen_elim_nondep_correct_t i0
(t1 ::
t2 ::
t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq)) | val compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type)
(tq: list Type)
: Tot
(compute_gen_elim_nondep_correct_t i0
(t1 ::
t2 ::
t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq)) | let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 767,
"start_col": 0,
"start_line": 759
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i0: Steel.ST.GenElim1.Base.gen_elim_i ->
t1: Type ->
t2: Type ->
t3: Type ->
t4: Type ->
t5: Type ->
t6: Type ->
t7: Type ->
t8: Type ->
t9: Type ->
t10: Type ->
t11: Type ->
t12: Type ->
t13: Type ->
t14: Type ->
t15: Type ->
tq: Prims.list Type
-> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0
(t1 ::
t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq
) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Prims.list",
"Steel.ST.GenElim1.Base.curried_function_type",
"Prims.Cons",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.gen_elim_nondep_p",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a'",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.GenElim1.Base.compute_uncurry",
"Steel.ST.GenElim1.Base.compute_gen_elim_p'",
"FStar.Universe.raise_val",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type)
(tq: list Type)
: Tot
(compute_gen_elim_nondep_correct_t i0
(t1 ::
t2 ::
t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq)) =
| fun q post intro _ ->
let res:compute_gen_elim_nondep_a' (t1 ::
t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq)
=
(U.raise_val ())
in
rewrite_with_trefl (compute_gen_elim_p i0)
(compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_mask_t | val bn_lt_mask_t : t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_nat -> i: Prims.nat{i <= len}
-> Type0 | let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 72,
"start_col": 0,
"start_line": 72
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_nat -> i: Prims.nat{i <= len}
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | true | let bn_lt_mask_t (t: limb_t) (len: size_nat) (i: nat{i <= len}) =
| limb t | false |
|
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_star_correct_ret_r | val tele_star_correct_ret_r (i1: gen_elim_tele{~(TRet? i1)}) (v2: vprop) (p2: prop)
: Tot
(vprop_rewrite ((tele_p i1) `star` (tele_p (TRet v2 p2))) (tele_p (i1 `tele_star` (TRet v2 p2)))
) | val tele_star_correct_ret_r (i1: gen_elim_tele{~(TRet? i1)}) (v2: vprop) (p2: prop)
: Tot
(vprop_rewrite ((tele_p i1) `star` (tele_p (TRet v2 p2))) (tele_p (i1 `tele_star` (TRet v2 p2)))
) | let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2)) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 261,
"start_col": 0,
"start_line": 255
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i1: Steel.ST.GenElim1.Base.gen_elim_tele{~(TRet? i1)} ->
v2: Steel.Effect.Common.vprop ->
p2: Prims.prop
-> Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p i1)
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.TRet v2 p2)))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star i1
(Steel.ST.GenElim1.Base.TRet v2 p2))) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_tele",
"Prims.l_not",
"Prims.b2t",
"Steel.ST.GenElim1.Base.uu___is_TRet",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.Memory.inames",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.ST.GenElim1.Base.tele_star",
"Steel.ST.GenElim1.Base.TRet",
"Prims.unit",
"Steel.ST.GenElim1.tele_star_vprop_correct",
"Steel.Effect.Common.star",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.vprop_rewrite"
] | [] | false | false | false | false | false | let tele_star_correct_ret_r (i1: gen_elim_tele{~(TRet? i1)}) (v2: vprop) (p2: prop)
: Tot
(vprop_rewrite ((tele_p i1) `star` (tele_p (TRet v2 p2))) (tele_p (i1 `tele_star` (TRet v2 p2)))
) =
| fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` (pure p2));
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` (TRet v2 p2))) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct | val compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot
(gen_elim_f (compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)) | val compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot
(gen_elim_f (compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)) | let compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot (gen_elim_f
(compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)
)
= fun _ ->
let res0 = compute_gen_elim_nondep_correct_0 i0 i sq _ in
let res = Ghost.hide res0 in
rewrite (compute_gen_elim_nondep_q0 i0 i res0) (compute_gen_elim_nondep_q i0 i res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 827,
"start_col": 0,
"start_line": 813
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq
let compute_gen_elim_nondep_correct_0
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
= match i returns
(sq: squash (check_gen_elim_nondep_sem i0 i)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i)
)
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post -> fun _ ->
let intro : vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) = fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i0: Steel.ST.GenElim1.Base.gen_elim_i ->
i: Steel.ST.GenElim1.Base.gen_elim_nondep_t ->
sq: Prims.squash (Steel.ST.GenElim1.Base.check_gen_elim_nondep_sem i0 i)
-> Steel.ST.GenElim1.gen_elim_f (Steel.ST.GenElim1.Base.compute_gen_elim_p i0)
(FStar.Ghost.erased (Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a i0 i))
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q i0 i)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_post i0 i) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.Base.gen_elim_nondep_t",
"Prims.squash",
"Steel.ST.GenElim1.Base.check_gen_elim_nondep_sem",
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q0",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q",
"FStar.Ghost.hide",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_0",
"Steel.ST.GenElim1.gen_elim_f",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_post"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot
(gen_elim_f (compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)) =
| fun _ ->
let res0 = compute_gen_elim_nondep_correct_0 i0 i sq _ in
let res = Ghost.hide res0 in
rewrite (compute_gen_elim_nondep_q0 i0 i res0) (compute_gen_elim_nondep_q i0 i res);
res | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_eq_mask | val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 40,
"start_col": 0,
"start_line": 39
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Lib.ByteSequence.seq_eq_mask",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_eq_mask #t #len a b =
| BSeq.seq_eq_mask a b len | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_mask | val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 76,
"start_col": 0,
"start_line": 75
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Lib.LoopCombinators.repeat_gen",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_t",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_f",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_lt_mask #t #len a b =
| Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_mask_f | val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t | val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t | let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC)) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 70,
"start_col": 0,
"start_line": 67
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
i: Prims.nat{i < len} ->
acc: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.IntTypes.ones",
"Lib.IntTypes.SEC",
"Lib.IntTypes.zeros",
"Lib.IntTypes.int_t",
"Lib.IntTypes.lt_mask",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.eq_mask"
] | [] | false | false | false | false | false | let bn_lt_mask_f #t #len a b i acc =
| let beq = eq_mask a.[ i ] b.[ i ] in
let blt = lt_mask a.[ i ] b.[ i ] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC)) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma | val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0)) | val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0)) | let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 63,
"start_col": 0,
"start_line": 60
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.Comparison.bn_is_zero_mask a) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.Comparison.bn_is_zero_mask a) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v a <> 0
| _ -> Hacl.Spec.Bignum.Definitions.bn_v a = 0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval_zeroes",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint"
] | [] | true | false | true | false | false | let bn_is_zero_mask_lemma #t #len b =
| let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_star_correct_ret_l | val tele_star_correct_ret_l (v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot
(vprop_rewrite ((tele_p (TRet v1 p1)) `star` (tele_p i2)) (tele_p ((TRet v1 p1) `tele_star` i2))
) | val tele_star_correct_ret_l (v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot
(vprop_rewrite ((tele_p (TRet v1 p1)) `star` (tele_p i2)) (tele_p ((TRet v1 p1) `tele_star` i2))
) | let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 253,
"start_col": 0,
"start_line": 247
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v1: Steel.Effect.Common.vprop -> p1: Prims.prop -> i2: Steel.ST.GenElim1.Base.gen_elim_tele
-> Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.TRet
v1 p1))
(Steel.ST.GenElim1.tele_p i2))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star (Steel.ST.GenElim1.Base.TRet v1 p1
)
i2)) | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.Base.gen_elim_tele",
"Steel.Memory.inames",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.ST.GenElim1.Base.tele_star",
"Steel.ST.GenElim1.Base.TRet",
"Prims.unit",
"Steel.ST.GenElim1.tele_star_vprop_correct",
"Steel.Effect.Common.star",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.vprop_rewrite"
] | [] | false | false | false | false | false | let tele_star_correct_ret_l (v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot
(vprop_rewrite ((tele_p (TRet v1 p1)) `star` (tele_p i2)) (tele_p ((TRet v1 p1) `tele_star` i2))
) =
| fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` (pure p1));
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_is_zero_mask | val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t | val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t | let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 55,
"start_col": 0,
"start_line": 53
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_eq_mask",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint"
] | [] | false | false | false | false | false | let bn_is_zero_mask #t #len b =
| let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero | false |
Vale.AES.X64.AES128.fsti | Vale.AES.X64.AES128.va_wp_AES128EncryptBlock | val va_wp_AES128EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AES128EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.AES128.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 149,
"start_col": 0,
"start_line": 137
} | module Vale.AES.X64.AES128
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion128Stdcall
val va_code_KeyExpansion128Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion128Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read output_key_expansion_b j
(va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==> Vale.X64.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) j)) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0))))))))))
[@ va_qattr]
let va_wp_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall
(va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags
va_x_efl (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 1
(va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let
(key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet
0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion128Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall win)
([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64
rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) =
(va_QProc (va_code_KeyExpansion128Stdcall win) ([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion128Stdcall win input_key_b output_key_expansion_b))
//--
//-- AES128EncryptBlock
val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM
va_s0)))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES128.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
input: Vale.X64.Decls.quad32 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 ->
keys_buffer: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.quad32",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.buffer128",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.AES.AES_s.is_aes_key_LE",
"Vale.AES.AES_common_s.AES_128",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.AES.AES_s.key_to_round_keys_LE",
"Vale.X64.Decls.va_get_xmm",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Decls.va_get_mem_heaplet",
"Vale.X64.Decls.validSrcAddrs128",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Vale.X64.Decls.buffer128_read",
"FStar.Seq.Base.index",
"Vale.X64.Flags.t",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_s.aes_encrypt_LE",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_xmm"
] | [] | false | false | false | true | true | let va_wp_AES128EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\
round_keys == Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\
va_get_reg64 rR8 va_s0 ==
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0)
keys_buffer
11
(va_get_mem_layout va_s0)
Secret /\
(forall (i: nat).
i < 11 ==>
Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\
(forall (va_x_xmm0: quad32) (va_x_xmm2: quad32) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 0 va_x_xmm0 va_s0)) in
va_get_ok va_sM /\ va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input ==>
va_k va_sM (()))) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma | val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2)) | val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2)) | let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 35,
"start_col": 0,
"start_line": 26
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Hacl.Spec.Bignum.Comparison.bn_is_odd a) ==
Hacl.Spec.Bignum.Definitions.bn_v a % 2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.range_t",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mod_mask",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.uint",
"Prims.unit",
"Lib.IntTypes.mod_mask_lemma",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.int",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Subtraction",
"Lib.Sequence.slice",
"FStar.Math.Lemmas.pow2_plus",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Lib.IntTypes.bits"
] | [] | true | false | true | false | false | let bn_is_odd_lemma #t #len b =
| let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[ 0 ] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[ 0 ]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[ 0 ] % 2);
mod_mask_lemma b.[ 0 ] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_is_odd | val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t | val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t | let bn_is_odd #t #len b = b.[0] &. uint #t 1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
/// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.uint"
] | [] | false | false | false | false | false | let bn_is_odd #t #len b =
| b.[ 0 ] &. uint #t 1 | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma | val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b)) | val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b)) | let bn_lt_mask_lemma #t #len a b =
bn_lt_mask_lemma_loop a b len | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 153,
"start_col": 0,
"start_line": 152
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask))
let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end
val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k))
let rec bn_lt_mask_lemma_loop #t #len a b k =
let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0 then begin
Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b end
else begin
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 end
val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.Comparison.bn_lt_mask a b) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.Comparison.bn_lt_mask a b) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v a >= Hacl.Spec.Bignum.Definitions.bn_v b
| _ -> Hacl.Spec.Bignum.Definitions.bn_v a < Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma_loop",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_lt_mask_lemma #t #len a b =
| bn_lt_mask_lemma_loop a b len | false |
Vale.AES.X64.AES128.fsti | Vale.AES.X64.AES128.va_wp_KeyExpansion128Stdcall | val va_wp_KeyExpansion128Stdcall
(win: bool)
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_KeyExpansion128Stdcall
(win: bool)
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall
(va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags
va_x_efl (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 1
(va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let
(key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet
0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.AES128.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 96,
"start_col": 0,
"start_line": 62
} | module Vale.AES.X64.AES128
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion128Stdcall
val va_code_KeyExpansion128Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion128Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read output_key_expansion_b j
(va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==> Vale.X64.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) j)) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0)))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES128.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input_key_b: Vale.X64.Memory.buffer128 ->
output_key_expansion_b: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Memory.buffer128",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.X64.Decls.validSrcAddrs128",
"Vale.X64.Decls.va_get_mem_heaplet",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs128",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Arch.Types.quad32_to_seq",
"Vale.X64.Decls.buffer128_read",
"Vale.X64.Decls.va_int_range",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRdx",
"Prims.l_not",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Prims.l_Forall",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Memory.nat64",
"Vale.X64.Decls.quad32",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Vale.X64.Decls.modifies_buffer128",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_s.key_to_round_keys_LE",
"Vale.AES.AES_common_s.AES_128",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"FStar.Seq.Base.index",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_KeyExpansion128Stdcall
(win: bool)
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let key_expansion_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b
0
(va_get_mem_heaplet 0 va_s0))
in
aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr
input_key_b
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0)
key_expansion_ptr
output_key_expansion_b
11
(va_get_mem_layout va_s0)
Secret) /\
(forall (va_x_mem: vale_heap)
(va_x_rdx: nat64)
(va_x_heap1: vale_heap)
(va_x_xmm1: quad32)
(va_x_xmm2: quad32)
(va_x_xmm3: quad32)
(va_x_efl: Vale.X64.Flags.t).
let va_sM =
va_upd_flags va_x_efl
(va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 1
va_x_xmm1
(va_upd_mem_heaplet 1
va_x_heap1
(va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in
va_get_ok va_sM /\
(let key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let key_expansion_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b
0
(va_get_mem_heaplet 0 va_s0))
in
aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr
input_key_b
1
(va_get_mem_layout va_sM)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM)
key_expansion_ptr
output_key_expansion_b
11
(va_get_mem_layout va_sM)
Secret) /\
(let key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let key_expansion_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b
0
(va_get_mem_heaplet 0 va_s0))
in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\
(forall j. {:pattern (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}
0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==>
va_k va_sM (()))) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask | val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | let bn_lt_pow2_mask #t #len b x =
let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b b2 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 160,
"start_col": 0,
"start_line": 157
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask))
let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end
val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k))
let rec bn_lt_mask_lemma_loop #t #len a b k =
let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0 then begin
Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b end
else begin
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 end
val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b))
let bn_lt_mask_lemma #t #len a b =
bn_lt_mask_lemma_loop a b len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint"
] | [] | false | false | false | false | false | let bn_lt_pow2_mask #t #len b x =
| let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b b2 | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma | val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\
(if v (bn_lt_pow2_mask b x) = 0 then bn_v b >= pow2 x else bn_v b < pow2 x)) | val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\
(if v (bn_lt_pow2_mask b x) = 0 then bn_v b >= pow2 x else bn_v b < pow2 x)) | let bn_lt_pow2_mask_lemma #t #len b x =
bn_eval_bound b len;
assert (bn_v b < pow2 (bits t * len));
let b2 = create len (uint #t 0) in
bn_eval_zeroes #t len len;
assert (bn_v b2 = 0);
//assert (bn_v b2 < pow2 x);
let b2' = bn_set_ith_bit b2 x in
bn_set_ith_bit_lemma b2 x;
assert (bn_v b2' == pow2 x);
bn_lt_mask_lemma b b2' | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 175,
"start_col": 0,
"start_line": 165
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask))
let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end
val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k))
let rec bn_lt_mask_lemma_loop #t #len a b k =
let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0 then begin
Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b end
else begin
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 end
val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b))
let bn_lt_mask_lemma #t #len a b =
bn_lt_mask_lemma_loop a b len
val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t
let bn_lt_pow2_mask #t #len b x =
let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b b2
val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v b >= Prims.pow2 x
| _ -> Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThan",
"Prims.op_GreaterThanOrEqual",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit",
"Prims.op_Equality",
"Hacl.Spec.Bignum.Definitions.bn_eval_zeroes",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound"
] | [] | true | false | true | false | false | let bn_lt_pow2_mask_lemma #t #len b x =
| bn_eval_bound b len;
assert (bn_v b < pow2 (bits t * len));
let b2 = create len (uint #t 0) in
bn_eval_zeroes #t len len;
assert (bn_v b2 = 0);
let b2' = bn_set_ith_bit b2 x in
bn_set_ith_bit_lemma b2 x;
assert (bn_v b2' == pow2 x);
bn_lt_mask_lemma b b2' | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask | val bn_gt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | val bn_gt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | let bn_gt_pow2_mask #t #len b x =
let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b2 b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 182,
"start_col": 0,
"start_line": 179
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask))
let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end
val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k))
let rec bn_lt_mask_lemma_loop #t #len a b k =
let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0 then begin
Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b end
else begin
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 end
val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b))
let bn_lt_mask_lemma #t #len a b =
bn_lt_mask_lemma_loop a b len
val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t
let bn_lt_pow2_mask #t #len b x =
let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b b2
val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\
(if v (bn_lt_pow2_mask b x) = 0 then bn_v b >= pow2 x else bn_v b < pow2 x))
let bn_lt_pow2_mask_lemma #t #len b x =
bn_eval_bound b len;
assert (bn_v b < pow2 (bits t * len));
let b2 = create len (uint #t 0) in
bn_eval_zeroes #t len len;
assert (bn_v b2 = 0);
//assert (bn_v b2 < pow2 x);
let b2' = bn_set_ith_bit b2 x in
bn_set_ith_bit_lemma b2 x;
assert (bn_v b2' == pow2 x);
bn_lt_mask_lemma b b2' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint"
] | [] | false | false | false | false | false | let bn_gt_pow2_mask #t #len b x =
| let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b2 b | false |
Vale.AES.X64.AES128.fsti | Vale.AES.X64.AES128.va_quick_KeyExpansion128Stdcall | val va_quick_KeyExpansion128Stdcall (win: bool) (input_key_b output_key_expansion_b: buffer128)
: (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) | val va_quick_KeyExpansion128Stdcall (win: bool) (input_key_b output_key_expansion_b: buffer128)
: (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) | let va_quick_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) =
(va_QProc (va_code_KeyExpansion128Stdcall win) ([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)) | {
"file_name": "obj/Vale.AES.X64.AES128.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 112,
"start_col": 0,
"start_line": 107
} | module Vale.AES.X64.AES128
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion128Stdcall
val va_code_KeyExpansion128Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion128Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read output_key_expansion_b j
(va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==> Vale.X64.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) j)) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0))))))))))
[@ va_qattr]
let va_wp_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall
(va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags
va_x_efl (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 1
(va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let
(key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet
0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion128Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall win)
([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64
rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES128.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input_key_b: Vale.X64.Memory.buffer128 ->
output_key_expansion_b: Vale.X64.Memory.buffer128
-> Vale.X64.QuickCode.va_quickCode Prims.unit
(Vale.AES.X64.AES128.va_code_KeyExpansion128Stdcall win) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Memory.buffer128",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.X64.AES128.va_code_KeyExpansion128Stdcall",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_mem_heaplet",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.QuickCode.va_Mod_mem",
"Prims.Nil",
"Vale.AES.X64.AES128.va_wp_KeyExpansion128Stdcall",
"Vale.AES.X64.AES128.va_wpProof_KeyExpansion128Stdcall",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_KeyExpansion128Stdcall (win: bool) (input_key_b output_key_expansion_b: buffer128)
: (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) =
| (va_QProc (va_code_KeyExpansion128Stdcall win)
([
va_Mod_flags;
va_Mod_xmm 3;
va_Mod_xmm 2;
va_Mod_xmm 1;
va_Mod_mem_heaplet 1;
va_Mod_reg64 rRdx;
va_Mod_mem
])
(va_wp_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)) | false |
Vale.AES.X64.AES128.fsti | Vale.AES.X64.AES128.va_quick_AES128EncryptBlockStdcall | val va_quick_AES128EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES128EncryptBlockStdcall win)) | val va_quick_AES128EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES128EncryptBlockStdcall win)) | let va_quick_AES128EncryptBlockStdcall (win:bool) (input:quad32) (key:(seq nat32))
(input_buffer:buffer128) (output_buffer:buffer128) (keys_buffer:buffer128) : (va_quickCode unit
(va_code_AES128EncryptBlockStdcall win)) =
(va_QProc (va_code_AES128EncryptBlockStdcall win) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0;
va_Mod_mem_heaplet 1; va_Mod_reg64 rR8; va_Mod_mem]) (va_wp_AES128EncryptBlockStdcall win input
key input_buffer output_buffer keys_buffer) (va_wpProof_AES128EncryptBlockStdcall win input key
input_buffer output_buffer keys_buffer)) | {
"file_name": "obj/Vale.AES.X64.AES128.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 254,
"start_col": 0,
"start_line": 248
} | module Vale.AES.X64.AES128
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion128Stdcall
val va_code_KeyExpansion128Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion128Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read output_key_expansion_b j
(va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==> Vale.X64.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) j)) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0))))))))))
[@ va_qattr]
let va_wp_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall
(va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags
va_x_efl (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 1
(va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let
(key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet
0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion128Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall win)
([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64
rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) =
(va_QProc (va_code_KeyExpansion128Stdcall win) ([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion128Stdcall win input_key_b output_key_expansion_b))
//--
//-- AES128EncryptBlock
val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input ==> va_k va_sM (())))
val va_wpProof_AES128EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock ()) ([va_Mod_flags;
va_Mod_xmm 2; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) =
(va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0])
(va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock
input key round_keys keys_buffer))
//--
//-- AES128EncryptBlockStdcall
val va_code_AES128EncryptBlockStdcall : win:bool -> Tot va_code
val va_codegen_success_AES128EncryptBlockStdcall : win:bool -> Tot va_pbool
val va_lemma_AES128EncryptBlockStdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input:quad32 -> key:(seq nat32) -> input_buffer:buffer128 -> output_buffer:buffer128 ->
keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES128EncryptBlockStdcall win) va_s0 /\ va_get_ok
va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64
rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8
va_s0 else va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled /\
Vale.AES.AES_s.is_aes_key_LE AES_128 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 11
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) i))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = (if
win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0
else va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_sM) output_ptr output_buffer
1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.buffer128_read output_buffer 0
(va_get_mem_heaplet 1 va_sM) == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM
(va_update_mem_heaplet 1 va_sM (va_update_reg64 rR8 va_sM (va_update_ok va_sM (va_update_mem
va_sM va_s0)))))))))
[@ va_qattr]
let va_wp_AES128EncryptBlockStdcall (win:bool) (input:quad32) (key:(seq nat32))
(input_buffer:buffer128) (output_buffer:buffer128) (keys_buffer:buffer128) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled
/\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 11
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) i)) /\ (forall (va_x_mem:vale_heap)
(va_x_r8:nat64) (va_x_heap1:vale_heap) (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR8 va_x_r8 (va_upd_mem
va_x_mem va_s0))))) in va_get_ok va_sM /\ (let (output_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rR8
va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1
va_sM) output_ptr output_buffer 1 (va_get_mem_layout va_sM) Secret /\
Vale.X64.Decls.buffer128_read output_buffer 0 (va_get_mem_heaplet 1 va_sM) ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input) ==> va_k va_sM (())))
val va_wpProof_AES128EncryptBlockStdcall : win:bool -> input:quad32 -> key:(seq nat32) ->
input_buffer:buffer128 -> output_buffer:buffer128 -> keys_buffer:buffer128 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlockStdcall win input key input_buffer
output_buffer keys_buffer va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlockStdcall win)
([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0; va_Mod_mem_heaplet 1; va_Mod_reg64 rR8;
va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES128.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input: Vale.X64.Decls.quad32 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
input_buffer: Vale.X64.Memory.buffer128 ->
output_buffer: Vale.X64.Memory.buffer128 ->
keys_buffer: Vale.X64.Memory.buffer128
-> Vale.X64.QuickCode.va_quickCode Prims.unit
(Vale.AES.X64.AES128.va_code_AES128EncryptBlockStdcall win) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Decls.quad32",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.buffer128",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.X64.AES128.va_code_AES128EncryptBlockStdcall",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_mem_heaplet",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rR8",
"Vale.X64.QuickCode.va_Mod_mem",
"Prims.Nil",
"Vale.AES.X64.AES128.va_wp_AES128EncryptBlockStdcall",
"Vale.AES.X64.AES128.va_wpProof_AES128EncryptBlockStdcall",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_AES128EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES128EncryptBlockStdcall win)) =
| (va_QProc (va_code_AES128EncryptBlockStdcall win)
([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0; va_Mod_mem_heaplet 1; va_Mod_reg64 rR8; va_Mod_mem])
(va_wp_AES128EncryptBlockStdcall win input key input_buffer output_buffer keys_buffer)
(va_wpProof_AES128EncryptBlockStdcall win input key input_buffer output_buffer keys_buffer)) | false |
Vale.AES.X64.AES128.fsti | Vale.AES.X64.AES128.va_quick_AES128EncryptBlock | val va_quick_AES128EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES128EncryptBlock ())) | val va_quick_AES128EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES128EncryptBlock ())) | let va_quick_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) =
(va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0])
(va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock
input key round_keys keys_buffer)) | {
"file_name": "obj/Vale.AES.X64.AES128.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 163,
"start_col": 0,
"start_line": 159
} | module Vale.AES.X64.AES128
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion128Stdcall
val va_code_KeyExpansion128Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion128Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read output_key_expansion_b j
(va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==> Vale.X64.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) j)) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0))))))))))
[@ va_qattr]
let va_wp_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall
(va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags
va_x_efl (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 1
(va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let
(key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet
0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion128Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall win)
([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64
rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) =
(va_QProc (va_code_KeyExpansion128Stdcall win) ([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion128Stdcall win input_key_b output_key_expansion_b))
//--
//-- AES128EncryptBlock
val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input ==> va_k va_sM (())))
val va_wpProof_AES128EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock ()) ([va_Mod_flags;
va_Mod_xmm 2; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES128.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
input: Vale.X64.Decls.quad32 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 ->
keys_buffer: Vale.X64.Memory.buffer128
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.AES.X64.AES128.va_code_AES128EncryptBlock ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.quad32",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.buffer128",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.X64.AES128.va_code_AES128EncryptBlock",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_Mod_xmm",
"Prims.Nil",
"Vale.AES.X64.AES128.va_wp_AES128EncryptBlock",
"Vale.AES.X64.AES128.va_wpProof_AES128EncryptBlock",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_AES128EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES128EncryptBlock ())) =
| (va_QProc (va_code_AES128EncryptBlock ())
([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0])
(va_wp_AES128EncryptBlock input key round_keys keys_buffer)
(va_wpProof_AES128EncryptBlock input key round_keys keys_buffer)) | false |
Vale.AES.X64.AES128.fsti | Vale.AES.X64.AES128.va_wp_AES128EncryptBlockStdcall | val va_wp_AES128EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AES128EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AES128EncryptBlockStdcall (win:bool) (input:quad32) (key:(seq nat32))
(input_buffer:buffer128) (output_buffer:buffer128) (keys_buffer:buffer128) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled
/\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 11
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) i)) /\ (forall (va_x_mem:vale_heap)
(va_x_r8:nat64) (va_x_heap1:vale_heap) (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR8 va_x_r8 (va_upd_mem
va_x_mem va_s0))))) in va_get_ok va_sM /\ (let (output_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rR8
va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1
va_sM) output_ptr output_buffer 1 (va_get_mem_layout va_sM) Secret /\
Vale.X64.Decls.buffer128_read output_buffer 0 (va_get_mem_heaplet 1 va_sM) ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.AES128.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 236,
"start_col": 0,
"start_line": 205
} | module Vale.AES.X64.AES128
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion128Stdcall
val va_code_KeyExpansion128Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion128Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion128Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion128Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read output_key_expansion_b j
(va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==> Vale.X64.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) j)) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0))))))))))
[@ va_qattr]
let va_wp_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_s0) Secret) /\ (forall
(va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags
va_x_efl (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))
in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Words_s.nat32)) = Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read
input_key_b 0 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 1
(va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_sM) key_expansion_ptr output_key_expansion_b 11 (va_get_mem_layout va_sM) Secret) /\ (let
(key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Words_s.nat32)) =
Vale.Arch.Types.quad32_to_seq (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet
0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall j . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}0 <= j /\ j <= 10 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion128Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion128Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion128Stdcall win)
([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64
rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion128Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion128Stdcall win)) =
(va_QProc (va_code_KeyExpansion128Stdcall win) ([va_Mod_flags; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion128Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion128Stdcall win input_key_b output_key_expansion_b))
//--
//-- AES128EncryptBlock
val va_code_AES128EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES128EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES128EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES128EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
FStar.Seq.Base.length #quad32 round_keys == 11 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_128 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 11 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 11 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input ==> va_k va_sM (())))
val va_wpProof_AES128EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES128EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES128EncryptBlock ()) ([va_Mod_flags;
va_Mod_xmm 2; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AES128EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES128EncryptBlock ())) =
(va_QProc (va_code_AES128EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0])
(va_wp_AES128EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES128EncryptBlock
input key round_keys keys_buffer))
//--
//-- AES128EncryptBlockStdcall
val va_code_AES128EncryptBlockStdcall : win:bool -> Tot va_code
val va_codegen_success_AES128EncryptBlockStdcall : win:bool -> Tot va_pbool
val va_lemma_AES128EncryptBlockStdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input:quad32 -> key:(seq nat32) -> input_buffer:buffer128 -> output_buffer:buffer128 ->
keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES128EncryptBlockStdcall win) va_s0 /\ va_get_ok
va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64
rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8
va_s0 else va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled /\
Vale.AES.AES_s.is_aes_key_LE AES_128 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 11
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 11 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_128 key) i))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = (if
win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0
else va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_sM) output_ptr output_buffer
1 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.buffer128_read output_buffer 0
(va_get_mem_heaplet 1 va_sM) == Vale.AES.AES_s.aes_encrypt_LE AES_128 key input) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM
(va_update_mem_heaplet 1 va_sM (va_update_reg64 rR8 va_sM (va_update_ok va_sM (va_update_mem
va_sM va_s0))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES128.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input: Vale.X64.Decls.quad32 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
input_buffer: Vale.X64.Memory.buffer128 ->
output_buffer: Vale.X64.Memory.buffer128 ->
keys_buffer: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Decls.quad32",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.buffer128",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.AES.AES_s.is_aes_key_LE",
"Vale.AES.AES_common_s.AES_128",
"Prims.eq2",
"Vale.X64.Decls.buffer128_read",
"Vale.X64.Decls.va_get_mem_heaplet",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Decls.validSrcAddrs128",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs128",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.index",
"Vale.AES.AES_s.key_to_round_keys_LE",
"Vale.X64.Decls.va_int_range",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rR8",
"Prims.l_not",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Memory.nat64",
"Vale.X64.Flags.t",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Decls.loc_buffer",
"Vale.AES.AES_s.aes_encrypt_LE",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_AES128EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let output_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let input_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let expanded_key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)
in
aesni_enabled /\ sse_enabled /\ Vale.AES.AES_s.is_aes_key_LE AES_128 key /\
Vale.X64.Decls.buffer128_read input_buffer 0 (va_get_mem_heaplet 0 va_s0) == input /\
expanded_key_ptr ==
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
input_ptr
input_buffer
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0)
output_ptr
output_buffer
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
expanded_key_ptr
keys_buffer
11
(va_get_mem_layout va_s0)
Secret /\
(forall (i: nat).
i < 11 ==>
Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_128 key)
i)) /\
(forall (va_x_mem: vale_heap)
(va_x_r8: nat64)
(va_x_heap1: vale_heap)
(va_x_xmm0: quad32)
(va_x_xmm2: quad32)
(va_x_efl: Vale.X64.Flags.t).
let va_sM =
va_upd_flags va_x_efl
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 0
va_x_xmm0
(va_upd_mem_heaplet 1
va_x_heap1
(va_upd_reg64 rR8 va_x_r8 (va_upd_mem va_x_mem va_s0)))))
in
va_get_ok va_sM /\
(let output_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let input_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let expanded_key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)
in
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128
output_buffer)
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_sM)
output_ptr
output_buffer
1
(va_get_mem_layout va_sM)
Secret /\
Vale.X64.Decls.buffer128_read output_buffer 0 (va_get_mem_heaplet 1 va_sM) ==
Vale.AES.AES_s.aes_encrypt_LE AES_128 key input) ==>
va_k va_sM (()))) | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma_step | val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask)) | val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask)) | let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 123,
"start_col": 0,
"start_line": 93
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
k: Prims.pos{k <= len} ->
mask0: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(requires
(match Lib.IntTypes.v mask0 = 0 with
| true ->
Hacl.Spec.Bignum.Definitions.eval_ len a (k - 1) >=
Hacl.Spec.Bignum.Definitions.eval_ len b (k - 1)
| _ ->
Hacl.Spec.Bignum.Definitions.eval_ len a (k - 1) <
Hacl.Spec.Bignum.Definitions.eval_ len b (k - 1)) /\
Hacl.Spec.Bignum.Base.mask_values mask0)
(ensures
(let mask = Hacl.Spec.Bignum.Comparison.bn_lt_mask_f a b (k - 1) mask0 in
(match Lib.IntTypes.v mask = 0 with
| true ->
Hacl.Spec.Bignum.Definitions.eval_ len a k >=
Hacl.Spec.Bignum.Definitions.eval_ len b k
| _ ->
Hacl.Spec.Bignum.Definitions.eval_ len a k <
Hacl.Spec.Bignum.Definitions.eval_ len b k) /\ Hacl.Spec.Bignum.Base.mask_values mask)
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.unit",
"Prims.op_LessThan",
"Lib.Sequence.op_String_Access",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.Definitions.bn_eval_lt",
"Prims.bool",
"Prims._assert",
"Prims.op_GreaterThan",
"Hacl.Spec.Bignum.Base.mask_select_lemma",
"Lib.IntTypes.ones",
"Lib.IntTypes.zeros",
"Lib.IntTypes.range_t",
"Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i",
"Prims.eq2",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.IntTypes.int_t",
"Lib.IntTypes.lt_mask",
"Lib.IntTypes.eq_mask",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_f"
] | [] | false | false | true | false | false | let bn_lt_mask_lemma_step #t #len a b k mask0 =
| let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[ k - 1 ] in
let bi = b.[ k - 1 ] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0
then
(assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[ k - 1 ] < v b.[ k - 1 ] then bn_eval_lt len a b k else bn_eval_lt len b a k;
())
else
(assert (v mask = v mask0);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
()) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct_0 | val compute_gen_elim_nondep_correct_0 : i0: Steel.ST.GenElim1.Base.gen_elim_i -> i: Steel.ST.GenElim1.Base.gen_elim_nondep_t
-> Prims.GTot
(sq: Prims.squash (Steel.ST.GenElim1.Base.check_gen_elim_nondep_sem i0 i)
-> Prims.GTot
(Steel.ST.GenElim1.gen_elim_f (Steel.ST.GenElim1.Base.compute_gen_elim_p i0)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a i0 i)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q0 i0 i)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_post0 i0 i))) | let compute_gen_elim_nondep_correct_0
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
= match i returns
(sq: squash (check_gen_elim_nondep_sem i0 i)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i)
)
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post -> fun _ ->
let intro : vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) = fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 811,
"start_col": 0,
"start_line": 791
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i0: Steel.ST.GenElim1.Base.gen_elim_i -> i: Steel.ST.GenElim1.Base.gen_elim_nondep_t
-> Prims.GTot
(sq: Prims.squash (Steel.ST.GenElim1.Base.check_gen_elim_nondep_sem i0 i)
-> Prims.GTot
(Steel.ST.GenElim1.gen_elim_f (Steel.ST.GenElim1.Base.compute_gen_elim_p i0)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a i0 i)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q0 i0 i)
(Steel.ST.GenElim1.Base.compute_gen_elim_nondep_post0 i0 i))) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.Base.gen_elim_nondep_t",
"Prims.squash",
"Steel.ST.GenElim1.Base.check_gen_elim_nondep_sem",
"Steel.ST.GenElim1.gen_elim_f",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q0",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_post0",
"Steel.ST.GenElim1.Base.GEDep",
"Steel.ST.GenElim1.compute_gen_elim_f",
"Prims.list",
"Steel.ST.GenElim1.Base.curried_function_type",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.Base.GENonDep",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct'",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.ST.GenElim1.gen_elim_nondep_p",
"Steel.Memory.inames",
"Steel.ST.Util.rewrite_equiv",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.gen_elim_nondep_sem",
"Steel.ST.GenElim1.gen_elim_nondep_sem_correct",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.compute_gen_elim_tele_correct"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct_0 (i0: gen_elim_i) (i: gen_elim_nondep_t) =
| match
i
returns
sq: squash (check_gen_elim_nondep_sem i0 i)
-> GTot
(gen_elim_f (compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i))
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post ->
fun _ ->
let intro:vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) =
fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro | false |
|
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma | val bn_gt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_gt_pow2_mask b x) /\
(if v (bn_gt_pow2_mask b x) = 0 then pow2 x >= bn_v b else pow2 x < bn_v b)) | val bn_gt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_gt_pow2_mask b x) /\
(if v (bn_gt_pow2_mask b x) = 0 then pow2 x >= bn_v b else pow2 x < bn_v b)) | let bn_gt_pow2_mask_lemma #t #len b x =
bn_eval_bound b len;
assert (bn_v b < pow2 (bits t * len));
let b2 = create len (uint #t 0) in
bn_eval_zeroes #t len len;
assert (bn_v b2 = 0);
//assert (bn_v b2 < pow2 x);
let b2' = bn_set_ith_bit b2 x in
bn_set_ith_bit_lemma b2 x;
assert (bn_v b2' == pow2 x);
bn_lt_mask_lemma b2' b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 197,
"start_col": 0,
"start_line": 187
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask))
let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end
val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k))
let rec bn_lt_mask_lemma_loop #t #len a b k =
let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0 then begin
Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b end
else begin
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 end
val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b))
let bn_lt_mask_lemma #t #len a b =
bn_lt_mask_lemma_loop a b len
val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t
let bn_lt_pow2_mask #t #len b x =
let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b b2
val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\
(if v (bn_lt_pow2_mask b x) = 0 then bn_v b >= pow2 x else bn_v b < pow2 x))
let bn_lt_pow2_mask_lemma #t #len b x =
bn_eval_bound b len;
assert (bn_v b < pow2 (bits t * len));
let b2 = create len (uint #t 0) in
bn_eval_zeroes #t len len;
assert (bn_v b2 = 0);
//assert (bn_v b2 < pow2 x);
let b2' = bn_set_ith_bit b2 x in
bn_set_ith_bit_lemma b2 x;
assert (bn_v b2' == pow2 x);
bn_lt_mask_lemma b b2'
val bn_gt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t
let bn_gt_pow2_mask #t #len b x =
let b2 = create len (uint #t 0) in
let b2 = bn_set_ith_bit b2 x in
bn_lt_mask b2 b
val bn_gt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_gt_pow2_mask b x) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x) = 0 with
| true -> Prims.pow2 x >= Hacl.Spec.Bignum.Definitions.bn_v b
| _ -> Prims.pow2 x < Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThan",
"Prims.op_GreaterThanOrEqual",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit",
"Prims.op_Equality",
"Hacl.Spec.Bignum.Definitions.bn_eval_zeroes",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound"
] | [] | true | false | true | false | false | let bn_gt_pow2_mask_lemma #t #len b x =
| bn_eval_bound b len;
assert (bn_v b < pow2 (bits t * len));
let b2 = create len (uint #t 0) in
bn_eval_zeroes #t len len;
assert (bn_v b2 = 0);
let b2' = bn_set_ith_bit b2 x in
bn_set_ith_bit_lemma b2 x;
assert (bn_v b2' == pow2 x);
bn_lt_mask_lemma b2' b | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma_loop | val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k)) | val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k)) | let rec bn_lt_mask_lemma_loop #t #len a b k =
let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0 then begin
Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b end
else begin
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 end | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 146,
"start_col": 0,
"start_line": 135
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b))
let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b
val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t
let bn_is_zero_mask #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eq_mask b bn_zero
val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0))
let bn_is_zero_mask_lemma #t #len b =
let bn_zero = create len (uint #t 0) in
bn_eval_zeroes #t len len;
bn_eq_mask_lemma b bn_zero
val bn_lt_mask_f: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> i:nat{i < len} -> acc:limb t -> limb t
let bn_lt_mask_f #t #len a b i acc =
let beq = eq_mask a.[i] b.[i] in
let blt = lt_mask a.[i] b.[i] in
mask_select beq acc (mask_select blt (ones t SEC) (zeros t SEC))
let bn_lt_mask_t (t:limb_t) (len:size_nat) (i:nat{i <= len}) = limb t
val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_lt_mask #t #len a b =
Loops.repeat_gen len (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0)
val bn_lt_mask_lemma_step:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:pos{k <= len}
-> mask0:limb t -> Lemma
(requires
(if v mask0 = 0 then eval_ len a (k - 1) >= eval_ len b (k - 1) else eval_ len a (k - 1) < eval_ len b (k - 1)) /\
mask_values mask0)
(ensures (let mask = bn_lt_mask_f a b (k - 1) mask0 in
(if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k) /\
mask_values mask))
let bn_lt_mask_lemma_step #t #len a b k mask0 =
let mask = bn_lt_mask_f a b (k - 1) mask0 in
let ai = a.[k - 1] in
let bi = b.[k - 1] in
let beq = eq_mask ai bi in
assert (if v ai = v bi then v beq == v (ones t SEC) else v beq == 0);
let blt = lt_mask ai bi in
assert (if v ai < v bi then v blt == v (ones t SEC) else v blt == 0);
let res0 = mask_select blt (ones t SEC) (zeros t SEC) in
let mask = mask_select beq mask0 res0 in
//assert (mask == bn_lt_mask_f #len a b (k - 1) mask0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
mask_select_lemma beq mask0 res0;
if v beq = 0 then begin
assert (v mask = v res0);
mask_select_lemma blt (ones t SEC) (zeros t SEC);
//assert (v res0 == (if v blt = 0 then 0 else v (ones t SEC)));
assert (if v mask = 0 then v ai > v bi else v ai < v bi);
if v a.[k - 1] < v b.[k - 1] then bn_eval_lt len a b k else bn_eval_lt len b a k;
() end
else begin
assert (v mask = v mask0);
//assert (v beq == v (ones t SEC));
//assert (if v mask = v mask0 then v ai = v bi else v ai <> v bi);
assert (v ai == v bi);
bn_eval_unfold_i a k;
bn_eval_unfold_i b k;
() end
val bn_lt_mask_lemma_loop:
#t:limb_t
-> #len:size_nat
-> a:lbignum t len
-> b:lbignum t len
-> k:nat{k <= len} ->
Lemma (let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
mask_values mask /\ (if v mask = 0 then eval_ len a k >= eval_ len b k else eval_ len a k < eval_ len b k)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
k: Prims.nat{k <= len}
-> FStar.Pervasives.Lemma
(ensures
(let mask =
Lib.LoopCombinators.repeat_gen k
(Hacl.Spec.Bignum.Comparison.bn_lt_mask_t t len)
(Hacl.Spec.Bignum.Comparison.bn_lt_mask_f a b)
(Lib.IntTypes.uint 0)
in
Hacl.Spec.Bignum.Base.mask_values mask /\
(match Lib.IntTypes.v mask = 0 with
| true ->
Hacl.Spec.Bignum.Definitions.eval_ len a k >= Hacl.Spec.Bignum.Definitions.eval_ len b k
| _ ->
Hacl.Spec.Bignum.Definitions.eval_ len a k < Hacl.Spec.Bignum.Definitions.eval_ len b k)
)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_eval0",
"Prims.unit",
"Prims._assert",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Lib.LoopCombinators.eq_repeat_gen0",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_t",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_f",
"Lib.IntTypes.uint",
"Prims.bool",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma_step",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma_loop",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeat_gen",
"Lib.LoopCombinators.repeat_gen"
] | [
"recursion"
] | false | false | true | false | false | let rec bn_lt_mask_lemma_loop #t #len a b k =
| let mask = Loops.repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
if k = 0
then
(Loops.eq_repeat_gen0 k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0);
assert (v mask = 0);
bn_eval0 a;
bn_eval0 b)
else
let mask0 = Loops.repeat_gen (k - 1) (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) in
Loops.unfold_repeat_gen k (bn_lt_mask_t t len) (bn_lt_mask_f a b) (uint #t 0) (k - 1);
bn_lt_mask_lemma_loop a b (k - 1);
bn_lt_mask_lemma_step a b k mask0 | false |
Hacl.Spec.Bignum.Comparison.fst | Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma | val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b)) | val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b)) | let bn_eq_mask_lemma #t #len a b =
let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Comparison.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 49,
"start_col": 0,
"start_line": 45
} | module Hacl.Spec.Bignum.Comparison
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Lib
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Bignum comparison and test functions
///
val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t
let bn_is_odd #t #len b = b.[0] &. uint #t 1
val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2))
let bn_is_odd_lemma #t #len b =
let pbits = bits t in
bn_eval_split_i b 1;
bn_eval1 (slice b 0 1);
assert (bn_v b % 2 == (v b.[0] + pow2 pbits * bn_v (slice b 1 len)) % 2);
Math.Lemmas.pow2_plus 1 (pbits - 1);
Math.Lemmas.modulo_addition_lemma (v b.[0]) 2 (pow2 (pbits - 1) * bn_v (slice b 1 len));
assert (bn_v b % 2 == v b.[0] % 2);
mod_mask_lemma b.[0] 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1))
val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t
let bn_eq_mask #t #len a b =
BSeq.seq_eq_mask a b len
val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Comparison.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.Comparison.bn_eq_mask a b) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.Comparison.bn_eq_mask a b) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v a <> Hacl.Spec.Bignum.Definitions.bn_v b
| _ -> Hacl.Spec.Bignum.Definitions.bn_v a = Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Classical.move_requires_2",
"Prims.eq2",
"Prims.nat",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Sequence.equal",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Definitions.bn_eval_inj",
"Prims.unit",
"Prims._assert",
"Prims.l_imp",
"Prims.l_not",
"Lib.IntTypes.range_t",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Lib.IntTypes.zeros",
"Lib.IntTypes.ones",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Lib.Sequence.lseq",
"Prims.l_or",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"Prims.int",
"Lib.IntTypes.range",
"Lib.ByteSequence.seq_eq_mask"
] | [] | false | false | true | false | false | let bn_eq_mask_lemma #t #len a b =
| let mask = BSeq.seq_eq_mask a b len in
assert (a == b ==> v mask == v (ones t SEC));
assert (a =!= b ==> v mask == v (zeros t SEC));
Classical.move_requires_2 (bn_eval_inj len) a b | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.elim_exists' | val elim_exists': #a: Type -> #opened_invariants: _ -> #p: (a -> vprop) -> unit
-> STGhostT (a) opened_invariants (exists_ p) (fun x -> p x) | val elim_exists': #a: Type -> #opened_invariants: _ -> #p: (a -> vprop) -> unit
-> STGhostT (a) opened_invariants (exists_ p) (fun x -> p x) | let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 209,
"start_col": 0,
"start_line": 199
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Steel.ST.Effect.Ghost.STGhostT a | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.rewrite",
"FStar.Ghost.reveal",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.Util.exists_"
] | [] | false | true | false | false | false | let elim_exists' (#a: Type) (#opened_invariants: _) (#p: (a -> vprop)) (_: unit)
: STGhostT (a) opened_invariants (exists_ p) (fun x -> p x) =
| let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_exists_no_abs0 | val compute_gen_elim_f_exists_no_abs0 (a: Type0) (body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body)) | val compute_gen_elim_f_exists_no_abs0 (a: Type0) (body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body)) | let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 108,
"start_col": 0,
"start_line": 99
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> body: (_: a -> Steel.Effect.Common.vprop)
-> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEExistsNoAbs0 body)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEExistsNoAbs0",
"Prims.unit",
"Steel.ST.Util.rewrite",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"FStar.Universe.raise_val",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.gen_elim_t"
] | [] | false | false | false | false | false | let compute_gen_elim_f_exists_no_abs0 (a: Type0) (body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body)) =
| fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res:compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_unit | val compute_gen_elim_tele_correct_unit (v: gen_unit_elim_i) : Tot (ge_to_tele_t (GEUnit v)) | val compute_gen_elim_tele_correct_unit (v: gen_unit_elim_i) : Tot (ge_to_tele_t (GEUnit v)) | let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 73,
"end_line": 301,
"start_col": 0,
"start_line": 294
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Steel.ST.GenElim1.Base.gen_unit_elim_i
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEUnit v) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_post",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.GEUnit",
"Prims.unit",
"Steel.ST.Util.intro_pure",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.ST.GenElim1.ge_to_tele_t"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_unit (v: gen_unit_elim_i) : Tot (ge_to_tele_t (GEUnit v)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl ((compute_gen_unit_elim_q v) `star` (pure _)) (tele_p _) | false |
Lib.Vec.Lemmas.fsti | Lib.Vec.Lemmas.repeat_blocks_multi_vec_equiv_pre | val repeat_blocks_multi_vec_equiv_pre
(#a #b #b_vec: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(f: (lseq a blocksize -> b -> b))
(f_v: (lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v: (b_vec -> b))
(b_v: lseq a (w * blocksize))
(acc_v: b_vec)
: prop | val repeat_blocks_multi_vec_equiv_pre
(#a #b #b_vec: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(f: (lseq a blocksize -> b -> b))
(f_v: (lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v: (b_vec -> b))
(b_v: lseq a (w * blocksize))
(acc_v: b_vec)
: prop | let repeat_blocks_multi_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(f_v:(lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v:(b_vec -> b))
(b_v:lseq a (w * blocksize))
(acc_v:b_vec)
: prop
=
Math.Lemmas.cancel_mul_mod w blocksize;
normalize_v (f_v b_v acc_v) == repeat_blocks_multi blocksize b_v f (normalize_v acc_v) | {
"file_name": "lib/Lib.Vec.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 175,
"start_col": 0,
"start_line": 161
} | module Lib.Vec.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.Sequence.Lemmas
module Loops = Lib.LoopCombinators
#push-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \
--using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq -FStar.Seq.Properties.slice_slice \
+Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators +Lib.Vec.Lemmas'"
val lemma_repeat_gen_vec:
w:pos
-> n:nat
-> a:(i:nat{i <= w * n} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> f:(i:nat{i < w * n} -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> a_vec i -> a_vec (i + 1))
-> acc_v0:a_vec 0 ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec i).
(assert (w * (i + 1) <= w * n);
normalize_v (i + 1) (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) a f (normalize_v i acc_v))))
(ensures
normalize_v n (Loops.repeat_right 0 n a_vec f_v acc_v0) ==
Loops.repeat_right 0 (w * n) a f (normalize_v 0 acc_v0))
val lemma_repeati_vec:
#a:Type0
-> #a_vec:Type0
-> w:pos
-> n:nat
-> normalize_v:(a_vec -> a)
-> f:(i:nat{i < w * n} -> a -> a)
-> f_v:(i:nat{i < n} -> a_vec -> a_vec)
-> acc_v0:a_vec ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec).
(assert (w * (i + 1) <= w * n);
normalize_v (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) (Loops.fixed_a a) f (normalize_v acc_v))))
(ensures
normalize_v (Loops.repeati n f_v acc_v0) ==
Loops.repeati (w * n) f (normalize_v acc_v0))
///
/// Lemma
/// (repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
/// repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
val len_is_w_n_blocksize: w:pos -> blocksize:pos -> n:nat -> Lemma
(let len = w * n * blocksize in
len / blocksize = w * n /\ len / (w * blocksize) = n /\
len % blocksize = 0 /\ len % (w * blocksize) = 0)
let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(a:(i:nat{i <= hi_f} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(i:nat{i < n})
(b_v:lseq inp_t (w * blocksize))
(acc_v:a_vec i)
: prop
=
Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v)
val lemma_repeat_gen_blocks_multi_vec:
#inp_t:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> n:nat
-> hi_f:nat{w * n <= hi_f}
-> inp:seq inp_t{length inp = w * n * blocksize}
-> a:(i:nat{i <= hi_f} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n hi_f a a_vec f f_v normalize_v i b_v acc_v))
(ensures
(len_is_w_n_blocksize w blocksize n;
normalize_v n (repeat_gen_blocks_multi (w * blocksize) 0 n n inp a_vec f_v acc_v0) ==
repeat_gen_blocks_multi blocksize 0 hi_f (w * n) inp a f (normalize_v 0 acc_v0)))
let repeat_gen_blocks_vec_equiv_pre
(#inp_t:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(a:(i:nat{i <= w * n + w} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(rem:nat{rem < w * blocksize})
(b_v:lseq inp_t rem)
(acc_v:a_vec n)
: prop
=
l_v n rem b_v acc_v ==
repeat_gen_blocks #inp_t #c blocksize (w * n) (w * n + w) b_v a f l (normalize_v n acc_v)
val lemma_repeat_gen_blocks_vec:
#inp_t:Type0
-> #c:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq inp_t
-> n:nat{n = length inp / (w * blocksize)}
-> a:(i:nat{i <= w * n + w} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c)
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n (w * n + w) a a_vec f f_v normalize_v i b_v acc_v) /\
(forall (rem:nat{rem < w * blocksize}) (b_v:lseq inp_t rem) (acc_v:a_vec n).
repeat_gen_blocks_vec_equiv_pre w blocksize n a a_vec f l l_v normalize_v rem b_v acc_v))
(ensures
repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
/// Lemma
/// (repeat_blocks (w * blocksize) inp f_v l_v acc_v0 ==
/// repeat_blocks blocksize inp f l (normalize_v acc_v0))
/// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Vec.Lemmas.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
w: Prims.pos ->
blocksize: Prims.pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) ->
f_v: (_: Lib.Sequence.lseq a (w * blocksize) -> _: b_vec -> b_vec) ->
normalize_v: (_: b_vec -> b) ->
b_v: Lib.Sequence.lseq a (w * blocksize) ->
acc_v: b_vec
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Prims.eq2",
"Lib.Sequence.repeat_blocks_multi",
"Prims.unit",
"FStar.Math.Lemmas.cancel_mul_mod",
"Prims.prop"
] | [] | false | false | false | false | true | let repeat_blocks_multi_vec_equiv_pre
(#a #b #b_vec: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(f: (lseq a blocksize -> b -> b))
(f_v: (lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v: (b_vec -> b))
(b_v: lseq a (w * blocksize))
(acc_v: b_vec)
: prop =
| Math.Lemmas.cancel_mul_mod w blocksize;
normalize_v (f_v b_v acc_v) == repeat_blocks_multi blocksize b_v f (normalize_v acc_v) | false |
Lib.Vec.Lemmas.fsti | Lib.Vec.Lemmas.repeat_blocks_vec_equiv_pre | val repeat_blocks_vec_equiv_pre
(#a #b #b_vec #c: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(f: (lseq a blocksize -> b -> b))
(l: (len: nat{len < blocksize} -> lseq a len -> b -> c))
(l_v: (len: nat{len < w * blocksize} -> lseq a len -> b_vec -> c))
(normalize_v: (b_vec -> b))
(rem: nat{rem < w * blocksize})
(b_v: lseq a rem)
(acc_v: b_vec)
: prop | val repeat_blocks_vec_equiv_pre
(#a #b #b_vec #c: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(f: (lseq a blocksize -> b -> b))
(l: (len: nat{len < blocksize} -> lseq a len -> b -> c))
(l_v: (len: nat{len < w * blocksize} -> lseq a len -> b_vec -> c))
(normalize_v: (b_vec -> b))
(rem: nat{rem < w * blocksize})
(b_v: lseq a rem)
(acc_v: b_vec)
: prop | let repeat_blocks_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(l:(len:nat{len < blocksize} -> lseq a len -> b -> c))
(l_v:(len:nat{len < w * blocksize} -> lseq a len -> b_vec -> c))
(normalize_v:(b_vec -> b))
(rem:nat{rem < w * blocksize})
(b_v:lseq a rem)
(acc_v:b_vec)
: prop
=
l_v rem b_v acc_v ==
repeat_blocks blocksize b_v f l (normalize_v acc_v) | {
"file_name": "lib/Lib.Vec.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 215,
"start_col": 0,
"start_line": 198
} | module Lib.Vec.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.Sequence.Lemmas
module Loops = Lib.LoopCombinators
#push-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \
--using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq -FStar.Seq.Properties.slice_slice \
+Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators +Lib.Vec.Lemmas'"
val lemma_repeat_gen_vec:
w:pos
-> n:nat
-> a:(i:nat{i <= w * n} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> f:(i:nat{i < w * n} -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> a_vec i -> a_vec (i + 1))
-> acc_v0:a_vec 0 ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec i).
(assert (w * (i + 1) <= w * n);
normalize_v (i + 1) (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) a f (normalize_v i acc_v))))
(ensures
normalize_v n (Loops.repeat_right 0 n a_vec f_v acc_v0) ==
Loops.repeat_right 0 (w * n) a f (normalize_v 0 acc_v0))
val lemma_repeati_vec:
#a:Type0
-> #a_vec:Type0
-> w:pos
-> n:nat
-> normalize_v:(a_vec -> a)
-> f:(i:nat{i < w * n} -> a -> a)
-> f_v:(i:nat{i < n} -> a_vec -> a_vec)
-> acc_v0:a_vec ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec).
(assert (w * (i + 1) <= w * n);
normalize_v (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) (Loops.fixed_a a) f (normalize_v acc_v))))
(ensures
normalize_v (Loops.repeati n f_v acc_v0) ==
Loops.repeati (w * n) f (normalize_v acc_v0))
///
/// Lemma
/// (repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
/// repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
val len_is_w_n_blocksize: w:pos -> blocksize:pos -> n:nat -> Lemma
(let len = w * n * blocksize in
len / blocksize = w * n /\ len / (w * blocksize) = n /\
len % blocksize = 0 /\ len % (w * blocksize) = 0)
let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(a:(i:nat{i <= hi_f} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(i:nat{i < n})
(b_v:lseq inp_t (w * blocksize))
(acc_v:a_vec i)
: prop
=
Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v)
val lemma_repeat_gen_blocks_multi_vec:
#inp_t:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> n:nat
-> hi_f:nat{w * n <= hi_f}
-> inp:seq inp_t{length inp = w * n * blocksize}
-> a:(i:nat{i <= hi_f} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n hi_f a a_vec f f_v normalize_v i b_v acc_v))
(ensures
(len_is_w_n_blocksize w blocksize n;
normalize_v n (repeat_gen_blocks_multi (w * blocksize) 0 n n inp a_vec f_v acc_v0) ==
repeat_gen_blocks_multi blocksize 0 hi_f (w * n) inp a f (normalize_v 0 acc_v0)))
let repeat_gen_blocks_vec_equiv_pre
(#inp_t:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(a:(i:nat{i <= w * n + w} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(rem:nat{rem < w * blocksize})
(b_v:lseq inp_t rem)
(acc_v:a_vec n)
: prop
=
l_v n rem b_v acc_v ==
repeat_gen_blocks #inp_t #c blocksize (w * n) (w * n + w) b_v a f l (normalize_v n acc_v)
val lemma_repeat_gen_blocks_vec:
#inp_t:Type0
-> #c:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq inp_t
-> n:nat{n = length inp / (w * blocksize)}
-> a:(i:nat{i <= w * n + w} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c)
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n (w * n + w) a a_vec f f_v normalize_v i b_v acc_v) /\
(forall (rem:nat{rem < w * blocksize}) (b_v:lseq inp_t rem) (acc_v:a_vec n).
repeat_gen_blocks_vec_equiv_pre w blocksize n a a_vec f l l_v normalize_v rem b_v acc_v))
(ensures
repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
/// Lemma
/// (repeat_blocks (w * blocksize) inp f_v l_v acc_v0 ==
/// repeat_blocks blocksize inp f l (normalize_v acc_v0))
///
let repeat_blocks_multi_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(f_v:(lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v:(b_vec -> b))
(b_v:lseq a (w * blocksize))
(acc_v:b_vec)
: prop
=
Math.Lemmas.cancel_mul_mod w blocksize;
normalize_v (f_v b_v acc_v) == repeat_blocks_multi blocksize b_v f (normalize_v acc_v)
val lemma_repeat_blocks_multi_vec:
#a:Type0
-> #b:Type0
-> #b_vec:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq a{length inp % (w * blocksize) = 0 /\ length inp % blocksize = 0}
-> f:(lseq a blocksize -> b -> b)
-> f_v:(lseq a (w * blocksize) -> b_vec -> b_vec)
-> normalize_v:(b_vec -> b)
-> acc_v0:b_vec ->
Lemma
(requires
(forall (b_v:lseq a (w * blocksize)) (acc_v:b_vec).
repeat_blocks_multi_vec_equiv_pre w blocksize f f_v normalize_v b_v acc_v))
(ensures
normalize_v (repeat_blocks_multi #a #b_vec (w * blocksize) inp f_v acc_v0) ==
repeat_blocks_multi #a #b blocksize inp f (normalize_v acc_v0)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Vec.Lemmas.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
w: Prims.pos ->
blocksize: Prims.pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) ->
l: (len: Prims.nat{len < blocksize} -> _: Lib.Sequence.lseq a len -> _: b -> c) ->
l_v: (len: Prims.nat{len < w * blocksize} -> _: Lib.Sequence.lseq a len -> _: b_vec -> c) ->
normalize_v: (_: b_vec -> b) ->
rem: Prims.nat{rem < w * blocksize} ->
b_v: Lib.Sequence.lseq a rem ->
acc_v: b_vec
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Prims.nat",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.repeat_blocks",
"Prims.prop"
] | [] | false | false | false | false | true | let repeat_blocks_vec_equiv_pre
(#a #b #b_vec #c: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(f: (lseq a blocksize -> b -> b))
(l: (len: nat{len < blocksize} -> lseq a len -> b -> c))
(l_v: (len: nat{len < w * blocksize} -> lseq a len -> b_vec -> c))
(normalize_v: (b_vec -> b))
(rem: nat{rem < w * blocksize})
(b_v: lseq a rem)
(acc_v: b_vec)
: prop =
| l_v rem b_v acc_v == repeat_blocks blocksize b_v f l (normalize_v acc_v) | false |
Lib.Vec.Lemmas.fsti | Lib.Vec.Lemmas.repeat_gen_blocks_multi_vec_equiv_pre | val repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(hi_f: nat{w * n <= hi_f})
(a: (i: nat{i <= hi_f} -> Type))
(a_vec: (i: nat{i <= n} -> Type))
(f: (i: nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v: (i: nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v: (i: nat{i <= n} -> a_vec i -> a (w * i)))
(i: nat{i < n})
(b_v: lseq inp_t (w * blocksize))
(acc_v: a_vec i)
: prop | val repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(hi_f: nat{w * n <= hi_f})
(a: (i: nat{i <= hi_f} -> Type))
(a_vec: (i: nat{i <= n} -> Type))
(f: (i: nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v: (i: nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v: (i: nat{i <= n} -> a_vec i -> a (w * i)))
(i: nat{i < n})
(b_v: lseq inp_t (w * blocksize))
(acc_v: a_vec i)
: prop | let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(a:(i:nat{i <= hi_f} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(i:nat{i < n})
(b_v:lseq inp_t (w * blocksize))
(acc_v:a_vec i)
: prop
=
Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v) | {
"file_name": "lib/Lib.Vec.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 83,
"start_col": 0,
"start_line": 64
} | module Lib.Vec.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.Sequence.Lemmas
module Loops = Lib.LoopCombinators
#push-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \
--using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq -FStar.Seq.Properties.slice_slice \
+Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators +Lib.Vec.Lemmas'"
val lemma_repeat_gen_vec:
w:pos
-> n:nat
-> a:(i:nat{i <= w * n} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> f:(i:nat{i < w * n} -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> a_vec i -> a_vec (i + 1))
-> acc_v0:a_vec 0 ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec i).
(assert (w * (i + 1) <= w * n);
normalize_v (i + 1) (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) a f (normalize_v i acc_v))))
(ensures
normalize_v n (Loops.repeat_right 0 n a_vec f_v acc_v0) ==
Loops.repeat_right 0 (w * n) a f (normalize_v 0 acc_v0))
val lemma_repeati_vec:
#a:Type0
-> #a_vec:Type0
-> w:pos
-> n:nat
-> normalize_v:(a_vec -> a)
-> f:(i:nat{i < w * n} -> a -> a)
-> f_v:(i:nat{i < n} -> a_vec -> a_vec)
-> acc_v0:a_vec ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec).
(assert (w * (i + 1) <= w * n);
normalize_v (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) (Loops.fixed_a a) f (normalize_v acc_v))))
(ensures
normalize_v (Loops.repeati n f_v acc_v0) ==
Loops.repeati (w * n) f (normalize_v acc_v0))
///
/// Lemma
/// (repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
/// repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
val len_is_w_n_blocksize: w:pos -> blocksize:pos -> n:nat -> Lemma
(let len = w * n * blocksize in
len / blocksize = w * n /\ len / (w * blocksize) = n /\
len % blocksize = 0 /\ len % (w * blocksize) = 0) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Vec.Lemmas.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
w: Prims.pos ->
blocksize: Prims.pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
n: Prims.nat ->
hi_f: Prims.nat{w * n <= hi_f} ->
a: (i: Prims.nat{i <= hi_f} -> Type) ->
a_vec: (i: Prims.nat{i <= n} -> Type) ->
f: (i: Prims.nat{i < hi_f} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) ->
f_v:
(i: Prims.nat{i < n} -> _: Lib.Sequence.lseq inp_t (w * blocksize) -> _: a_vec i
-> a_vec (i + 1)) ->
normalize_v: (i: Prims.nat{i <= n} -> _: a_vec i -> a (w * i)) ->
i: Prims.nat{i < n} ->
b_v: Lib.Sequence.lseq inp_t (w * blocksize) ->
acc_v: a_vec i
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.op_Addition",
"Prims.eq2",
"Lib.Sequence.Lemmas.repeat_gen_blocks_multi",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mult_le_right",
"Prims.prop"
] | [] | false | false | false | false | true | let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(hi_f: nat{w * n <= hi_f})
(a: (i: nat{i <= hi_f} -> Type))
(a_vec: (i: nat{i <= n} -> Type))
(f: (i: nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v: (i: nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v: (i: nat{i <= n} -> a_vec i -> a (w * i)))
(i: nat{i < n})
(b_v: lseq inp_t (w * blocksize))
(acc_v: a_vec i)
: prop =
| Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v) | false |
Lib.Vec.Lemmas.fsti | Lib.Vec.Lemmas.repeat_gen_blocks_vec_equiv_pre | val repeat_gen_blocks_vec_equiv_pre
(#inp_t #c: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(a: (i: nat{i <= w * n + w} -> Type))
(a_vec: (i: nat{i <= n} -> Type))
(f: (i: nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l: (i: nat{i <= w * n + w} -> len: nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v: (i: nat{i <= n} -> len: nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v: (i: nat{i <= n} -> a_vec i -> a (w * i)))
(rem: nat{rem < w * blocksize})
(b_v: lseq inp_t rem)
(acc_v: a_vec n)
: prop | val repeat_gen_blocks_vec_equiv_pre
(#inp_t #c: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(a: (i: nat{i <= w * n + w} -> Type))
(a_vec: (i: nat{i <= n} -> Type))
(f: (i: nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l: (i: nat{i <= w * n + w} -> len: nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v: (i: nat{i <= n} -> len: nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v: (i: nat{i <= n} -> a_vec i -> a (w * i)))
(rem: nat{rem < w * blocksize})
(b_v: lseq inp_t rem)
(acc_v: a_vec n)
: prop | let repeat_gen_blocks_vec_equiv_pre
(#inp_t:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(a:(i:nat{i <= w * n + w} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(rem:nat{rem < w * blocksize})
(b_v:lseq inp_t rem)
(acc_v:a_vec n)
: prop
=
l_v n rem b_v acc_v ==
repeat_gen_blocks #inp_t #c blocksize (w * n) (w * n + w) b_v a f l (normalize_v n acc_v) | {
"file_name": "lib/Lib.Vec.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 127,
"start_col": 0,
"start_line": 109
} | module Lib.Vec.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.Sequence.Lemmas
module Loops = Lib.LoopCombinators
#push-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \
--using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq -FStar.Seq.Properties.slice_slice \
+Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators +Lib.Vec.Lemmas'"
val lemma_repeat_gen_vec:
w:pos
-> n:nat
-> a:(i:nat{i <= w * n} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> f:(i:nat{i < w * n} -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> a_vec i -> a_vec (i + 1))
-> acc_v0:a_vec 0 ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec i).
(assert (w * (i + 1) <= w * n);
normalize_v (i + 1) (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) a f (normalize_v i acc_v))))
(ensures
normalize_v n (Loops.repeat_right 0 n a_vec f_v acc_v0) ==
Loops.repeat_right 0 (w * n) a f (normalize_v 0 acc_v0))
val lemma_repeati_vec:
#a:Type0
-> #a_vec:Type0
-> w:pos
-> n:nat
-> normalize_v:(a_vec -> a)
-> f:(i:nat{i < w * n} -> a -> a)
-> f_v:(i:nat{i < n} -> a_vec -> a_vec)
-> acc_v0:a_vec ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec).
(assert (w * (i + 1) <= w * n);
normalize_v (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) (Loops.fixed_a a) f (normalize_v acc_v))))
(ensures
normalize_v (Loops.repeati n f_v acc_v0) ==
Loops.repeati (w * n) f (normalize_v acc_v0))
///
/// Lemma
/// (repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
/// repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
val len_is_w_n_blocksize: w:pos -> blocksize:pos -> n:nat -> Lemma
(let len = w * n * blocksize in
len / blocksize = w * n /\ len / (w * blocksize) = n /\
len % blocksize = 0 /\ len % (w * blocksize) = 0)
let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(a:(i:nat{i <= hi_f} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(i:nat{i < n})
(b_v:lseq inp_t (w * blocksize))
(acc_v:a_vec i)
: prop
=
Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v)
val lemma_repeat_gen_blocks_multi_vec:
#inp_t:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> n:nat
-> hi_f:nat{w * n <= hi_f}
-> inp:seq inp_t{length inp = w * n * blocksize}
-> a:(i:nat{i <= hi_f} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n hi_f a a_vec f f_v normalize_v i b_v acc_v))
(ensures
(len_is_w_n_blocksize w blocksize n;
normalize_v n (repeat_gen_blocks_multi (w * blocksize) 0 n n inp a_vec f_v acc_v0) ==
repeat_gen_blocks_multi blocksize 0 hi_f (w * n) inp a f (normalize_v 0 acc_v0))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Vec.Lemmas.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
w: Prims.pos ->
blocksize: Prims.pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
n: Prims.nat ->
a: (i: Prims.nat{i <= w * n + w} -> Type) ->
a_vec: (i: Prims.nat{i <= n} -> Type) ->
f: (i: Prims.nat{i < w * n + w} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) ->
l:
(
i: Prims.nat{i <= w * n + w} ->
len: Prims.nat{len < blocksize} ->
_: Lib.Sequence.lseq inp_t len ->
_: a i
-> c) ->
l_v:
(
i: Prims.nat{i <= n} ->
len: Prims.nat{len < w * blocksize} ->
_: Lib.Sequence.lseq inp_t len ->
_: a_vec i
-> c) ->
normalize_v: (i: Prims.nat{i <= n} -> _: a_vec i -> a (w * i)) ->
rem: Prims.nat{rem < w * blocksize} ->
b_v: Lib.Sequence.lseq inp_t rem ->
acc_v: a_vec n
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_Addition",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.eq2",
"Lib.Sequence.Lemmas.repeat_gen_blocks",
"Prims.prop"
] | [] | false | false | false | false | true | let repeat_gen_blocks_vec_equiv_pre
(#inp_t #c: Type0)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(a: (i: nat{i <= w * n + w} -> Type))
(a_vec: (i: nat{i <= n} -> Type))
(f: (i: nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l: (i: nat{i <= w * n + w} -> len: nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v: (i: nat{i <= n} -> len: nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v: (i: nat{i <= n} -> a_vec i -> a (w * i)))
(rem: nat{rem < w * blocksize})
(b_v: lseq inp_t rem)
(acc_v: a_vec n)
: prop =
| l_v n rem b_v acc_v ==
repeat_gen_blocks #inp_t #c blocksize (w * n) (w * n + w) b_v a f l (normalize_v n acc_v) | false |
Lib.Vec.Lemmas.fsti | Lib.Vec.Lemmas.map_blocks_multi_vec_equiv_pre_k | val map_blocks_multi_vec_equiv_pre_k
(#a: Type)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(hi_f: nat{w * n <= hi_f})
(f: (i: nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize))
(f_v: (i: nat{i < n} -> lseq a (w * blocksize) -> lseq a (w * blocksize)))
(i: nat{i < n})
(b_v: lseq a (w * blocksize))
(k: nat{k < w * blocksize})
: prop | val map_blocks_multi_vec_equiv_pre_k
(#a: Type)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(hi_f: nat{w * n <= hi_f})
(f: (i: nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize))
(f_v: (i: nat{i < n} -> lseq a (w * blocksize) -> lseq a (w * blocksize)))
(i: nat{i < n})
(b_v: lseq a (w * blocksize))
(k: nat{k < w * blocksize})
: prop | let map_blocks_multi_vec_equiv_pre_k
(#a:Type)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize))
(f_v:(i:nat{i < n} -> lseq a (w * blocksize) -> lseq a (w * blocksize)))
(i:nat{i < n})
(b_v:lseq a (w * blocksize))
(k:nat{k < w * blocksize})
: prop
=
Math.Lemmas.cancel_mul_div w blocksize;
let block = get_block_s #a #(w * blocksize) blocksize b_v k in
lemma_f_map_ind w blocksize n i k;
Seq.index (f_v i b_v) k == Seq.index (f (w * i + k / blocksize) block) (k % blocksize) | {
"file_name": "lib/Lib.Vec.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 267,
"start_col": 0,
"start_line": 251
} | module Lib.Vec.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.Sequence.Lemmas
module Loops = Lib.LoopCombinators
#push-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \
--using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq -FStar.Seq.Properties.slice_slice \
+Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators +Lib.Vec.Lemmas'"
val lemma_repeat_gen_vec:
w:pos
-> n:nat
-> a:(i:nat{i <= w * n} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> f:(i:nat{i < w * n} -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> a_vec i -> a_vec (i + 1))
-> acc_v0:a_vec 0 ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec i).
(assert (w * (i + 1) <= w * n);
normalize_v (i + 1) (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) a f (normalize_v i acc_v))))
(ensures
normalize_v n (Loops.repeat_right 0 n a_vec f_v acc_v0) ==
Loops.repeat_right 0 (w * n) a f (normalize_v 0 acc_v0))
val lemma_repeati_vec:
#a:Type0
-> #a_vec:Type0
-> w:pos
-> n:nat
-> normalize_v:(a_vec -> a)
-> f:(i:nat{i < w * n} -> a -> a)
-> f_v:(i:nat{i < n} -> a_vec -> a_vec)
-> acc_v0:a_vec ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec).
(assert (w * (i + 1) <= w * n);
normalize_v (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) (Loops.fixed_a a) f (normalize_v acc_v))))
(ensures
normalize_v (Loops.repeati n f_v acc_v0) ==
Loops.repeati (w * n) f (normalize_v acc_v0))
///
/// Lemma
/// (repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
/// repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
val len_is_w_n_blocksize: w:pos -> blocksize:pos -> n:nat -> Lemma
(let len = w * n * blocksize in
len / blocksize = w * n /\ len / (w * blocksize) = n /\
len % blocksize = 0 /\ len % (w * blocksize) = 0)
let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(a:(i:nat{i <= hi_f} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(i:nat{i < n})
(b_v:lseq inp_t (w * blocksize))
(acc_v:a_vec i)
: prop
=
Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v)
val lemma_repeat_gen_blocks_multi_vec:
#inp_t:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> n:nat
-> hi_f:nat{w * n <= hi_f}
-> inp:seq inp_t{length inp = w * n * blocksize}
-> a:(i:nat{i <= hi_f} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n hi_f a a_vec f f_v normalize_v i b_v acc_v))
(ensures
(len_is_w_n_blocksize w blocksize n;
normalize_v n (repeat_gen_blocks_multi (w * blocksize) 0 n n inp a_vec f_v acc_v0) ==
repeat_gen_blocks_multi blocksize 0 hi_f (w * n) inp a f (normalize_v 0 acc_v0)))
let repeat_gen_blocks_vec_equiv_pre
(#inp_t:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(a:(i:nat{i <= w * n + w} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(rem:nat{rem < w * blocksize})
(b_v:lseq inp_t rem)
(acc_v:a_vec n)
: prop
=
l_v n rem b_v acc_v ==
repeat_gen_blocks #inp_t #c blocksize (w * n) (w * n + w) b_v a f l (normalize_v n acc_v)
val lemma_repeat_gen_blocks_vec:
#inp_t:Type0
-> #c:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq inp_t
-> n:nat{n = length inp / (w * blocksize)}
-> a:(i:nat{i <= w * n + w} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c)
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n (w * n + w) a a_vec f f_v normalize_v i b_v acc_v) /\
(forall (rem:nat{rem < w * blocksize}) (b_v:lseq inp_t rem) (acc_v:a_vec n).
repeat_gen_blocks_vec_equiv_pre w blocksize n a a_vec f l l_v normalize_v rem b_v acc_v))
(ensures
repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
/// Lemma
/// (repeat_blocks (w * blocksize) inp f_v l_v acc_v0 ==
/// repeat_blocks blocksize inp f l (normalize_v acc_v0))
///
let repeat_blocks_multi_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(f_v:(lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v:(b_vec -> b))
(b_v:lseq a (w * blocksize))
(acc_v:b_vec)
: prop
=
Math.Lemmas.cancel_mul_mod w blocksize;
normalize_v (f_v b_v acc_v) == repeat_blocks_multi blocksize b_v f (normalize_v acc_v)
val lemma_repeat_blocks_multi_vec:
#a:Type0
-> #b:Type0
-> #b_vec:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq a{length inp % (w * blocksize) = 0 /\ length inp % blocksize = 0}
-> f:(lseq a blocksize -> b -> b)
-> f_v:(lseq a (w * blocksize) -> b_vec -> b_vec)
-> normalize_v:(b_vec -> b)
-> acc_v0:b_vec ->
Lemma
(requires
(forall (b_v:lseq a (w * blocksize)) (acc_v:b_vec).
repeat_blocks_multi_vec_equiv_pre w blocksize f f_v normalize_v b_v acc_v))
(ensures
normalize_v (repeat_blocks_multi #a #b_vec (w * blocksize) inp f_v acc_v0) ==
repeat_blocks_multi #a #b blocksize inp f (normalize_v acc_v0))
let repeat_blocks_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(l:(len:nat{len < blocksize} -> lseq a len -> b -> c))
(l_v:(len:nat{len < w * blocksize} -> lseq a len -> b_vec -> c))
(normalize_v:(b_vec -> b))
(rem:nat{rem < w * blocksize})
(b_v:lseq a rem)
(acc_v:b_vec)
: prop
=
l_v rem b_v acc_v ==
repeat_blocks blocksize b_v f l (normalize_v acc_v)
val lemma_repeat_blocks_vec:
#a:Type0
-> #b:Type0
-> #b_vec:Type0
-> #c:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq a
-> f:(lseq a blocksize -> b -> b)
-> l:(len:nat{len < blocksize} -> lseq a len -> b -> c)
-> f_v:(lseq a (w * blocksize) -> b_vec -> b_vec)
-> l_v:(len:nat{len < w * blocksize} -> lseq a len -> b_vec -> c)
-> normalize_v:(b_vec -> b)
-> acc_v0:b_vec ->
Lemma
(requires
(forall (b_v:lseq a (w * blocksize)) (acc_v:b_vec).
repeat_blocks_multi_vec_equiv_pre w blocksize f f_v normalize_v b_v acc_v) /\
(forall (rem:nat{rem < w * blocksize}) (b_v:lseq a rem) (acc_v:b_vec).
repeat_blocks_vec_equiv_pre w blocksize f l l_v normalize_v rem b_v acc_v))
(ensures
repeat_blocks (w * blocksize) inp f_v l_v acc_v0 ==
repeat_blocks blocksize inp f l (normalize_v acc_v0))
///
/// Lemma
/// (map_blocks (w * blocksize) inp f_v l_v == map_blocks blocksize inp f l)
///
val lemma_f_map_ind: w:pos -> blocksize:pos -> n:nat -> i:nat{i < n} -> k:nat{k < w * blocksize} ->
Lemma (w * i + k / blocksize < w * n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Vec.Lemmas.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
w: Prims.pos ->
blocksize: Prims.pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
n: Prims.nat ->
hi_f: Prims.nat{w * n <= hi_f} ->
f: (i: Prims.nat{i < hi_f} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) ->
f_v:
(i: Prims.nat{i < n} -> _: Lib.Sequence.lseq a (w * blocksize)
-> Lib.Sequence.lseq a (w * blocksize)) ->
i: Prims.nat{i < n} ->
b_v: Lib.Sequence.lseq a (w * blocksize) ->
k: Prims.nat{k < w * blocksize}
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.unit",
"Lib.Vec.Lemmas.lemma_f_map_ind",
"Lib.Sequence.Lemmas.get_block_s",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.prop"
] | [] | false | false | false | false | true | let map_blocks_multi_vec_equiv_pre_k
(#a: Type)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(hi_f: nat{w * n <= hi_f})
(f: (i: nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize))
(f_v: (i: nat{i < n} -> lseq a (w * blocksize) -> lseq a (w * blocksize)))
(i: nat{i < n})
(b_v: lseq a (w * blocksize))
(k: nat{k < w * blocksize})
: prop =
| Math.Lemmas.cancel_mul_div w blocksize;
let block = get_block_s #a #(w * blocksize) blocksize b_v k in
lemma_f_map_ind w blocksize n i k;
Seq.index (f_v i b_v) k == Seq.index (f (w * i + k / blocksize) block) (k % blocksize) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_exists_no_abs1 | val compute_gen_elim_f_exists_no_abs1 (a: Type) (body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body)) | val compute_gen_elim_f_exists_no_abs1 (a: Type) (body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body)) | let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 152,
"start_col": 0,
"start_line": 143
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> body: (_: a -> Steel.Effect.Common.vprop)
-> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEExistsNoAbs1 body)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEExistsNoAbs1",
"Prims.unit",
"Steel.ST.Util.rewrite",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.gen_elim_t"
] | [] | false | false | false | false | false | let compute_gen_elim_f_exists_no_abs1 (a: Type) (body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body)) =
| fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res:compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res | false |
Lib.Vec.Lemmas.fsti | Lib.Vec.Lemmas.map_blocks_vec_equiv_pre_k | val map_blocks_vec_equiv_pre_k
(#a: Type)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(f: (i: nat{i < w * n + w} -> lseq a blocksize -> lseq a blocksize))
(l: (i: nat{i <= w * n + w} -> rem: nat{rem < blocksize} -> lseq a rem -> lseq a rem))
(l_v: (i: nat{i <= n} -> rem: nat{rem < w * blocksize} -> lseq a rem -> lseq a rem))
(rem: nat{rem < w * blocksize})
(b_v: lseq a rem)
(k: nat{k < rem})
: prop | val map_blocks_vec_equiv_pre_k
(#a: Type)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(f: (i: nat{i < w * n + w} -> lseq a blocksize -> lseq a blocksize))
(l: (i: nat{i <= w * n + w} -> rem: nat{rem < blocksize} -> lseq a rem -> lseq a rem))
(l_v: (i: nat{i <= n} -> rem: nat{rem < w * blocksize} -> lseq a rem -> lseq a rem))
(rem: nat{rem < w * blocksize})
(b_v: lseq a rem)
(k: nat{k < rem})
: prop | let map_blocks_vec_equiv_pre_k
(#a:Type)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(f:(i:nat{i < w * n + w} -> lseq a blocksize -> lseq a blocksize))
(l:(i:nat{i <= w * n + w} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem))
(l_v:(i:nat{i <= n} -> rem:nat{rem < w * blocksize} -> lseq a rem -> lseq a rem))
(rem:nat{rem < w * blocksize})
(b_v:lseq a rem)
(k:nat{k < rem})
: prop
=
let j = w * n + k / blocksize in
div_mul_lt blocksize k w;
if k < rem / blocksize * blocksize then begin
let block = get_block_s #a #rem blocksize b_v k in
Seq.index (l_v n rem b_v) k == Seq.index (f j block) (k % blocksize) end
else begin
let block_l = get_last_s blocksize b_v in
mod_div_lt blocksize k rem;
assert (k % blocksize < rem % blocksize);
Seq.index (l_v n rem b_v) k == Seq.index (l j (rem % blocksize) block_l) (k % blocksize) end | {
"file_name": "lib/Lib.Vec.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 311,
"start_col": 0,
"start_line": 288
} | module Lib.Vec.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.Sequence.Lemmas
module Loops = Lib.LoopCombinators
#push-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \
--using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq -FStar.Seq.Properties.slice_slice \
+Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators +Lib.Vec.Lemmas'"
val lemma_repeat_gen_vec:
w:pos
-> n:nat
-> a:(i:nat{i <= w * n} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> f:(i:nat{i < w * n} -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> a_vec i -> a_vec (i + 1))
-> acc_v0:a_vec 0 ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec i).
(assert (w * (i + 1) <= w * n);
normalize_v (i + 1) (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) a f (normalize_v i acc_v))))
(ensures
normalize_v n (Loops.repeat_right 0 n a_vec f_v acc_v0) ==
Loops.repeat_right 0 (w * n) a f (normalize_v 0 acc_v0))
val lemma_repeati_vec:
#a:Type0
-> #a_vec:Type0
-> w:pos
-> n:nat
-> normalize_v:(a_vec -> a)
-> f:(i:nat{i < w * n} -> a -> a)
-> f_v:(i:nat{i < n} -> a_vec -> a_vec)
-> acc_v0:a_vec ->
Lemma
(requires (forall (i:nat{i < n}) (acc_v:a_vec).
(assert (w * (i + 1) <= w * n);
normalize_v (f_v i acc_v) ==
Loops.repeat_right (w * i) (w * (i + 1)) (Loops.fixed_a a) f (normalize_v acc_v))))
(ensures
normalize_v (Loops.repeati n f_v acc_v0) ==
Loops.repeati (w * n) f (normalize_v acc_v0))
///
/// Lemma
/// (repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
/// repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
val len_is_w_n_blocksize: w:pos -> blocksize:pos -> n:nat -> Lemma
(let len = w * n * blocksize in
len / blocksize = w * n /\ len / (w * blocksize) = n /\
len % blocksize = 0 /\ len % (w * blocksize) = 0)
let repeat_gen_blocks_multi_vec_equiv_pre
(#inp_t:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(a:(i:nat{i <= hi_f} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1)))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(i:nat{i < n})
(b_v:lseq inp_t (w * blocksize))
(acc_v:a_vec i)
: prop
=
Math.Lemmas.lemma_mult_le_right w (i + 1) n;
normalize_v (i + 1) (f_v i b_v acc_v) ==
repeat_gen_blocks_multi blocksize (w * i) hi_f w b_v a f (normalize_v i acc_v)
val lemma_repeat_gen_blocks_multi_vec:
#inp_t:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> n:nat
-> hi_f:nat{w * n <= hi_f}
-> inp:seq inp_t{length inp = w * n * blocksize}
-> a:(i:nat{i <= hi_f} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n hi_f a a_vec f f_v normalize_v i b_v acc_v))
(ensures
(len_is_w_n_blocksize w blocksize n;
normalize_v n (repeat_gen_blocks_multi (w * blocksize) 0 n n inp a_vec f_v acc_v0) ==
repeat_gen_blocks_multi blocksize 0 hi_f (w * n) inp a f (normalize_v 0 acc_v0)))
let repeat_gen_blocks_vec_equiv_pre
(#inp_t:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(a:(i:nat{i <= w * n + w} -> Type))
(a_vec:(i:nat{i <= n} -> Type))
(f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1)))
(l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c))
(l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c))
(normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i)))
(rem:nat{rem < w * blocksize})
(b_v:lseq inp_t rem)
(acc_v:a_vec n)
: prop
=
l_v n rem b_v acc_v ==
repeat_gen_blocks #inp_t #c blocksize (w * n) (w * n + w) b_v a f l (normalize_v n acc_v)
val lemma_repeat_gen_blocks_vec:
#inp_t:Type0
-> #c:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq inp_t
-> n:nat{n = length inp / (w * blocksize)}
-> a:(i:nat{i <= w * n + w} -> Type)
-> a_vec:(i:nat{i <= n} -> Type)
-> f:(i:nat{i < w * n + w} -> lseq inp_t blocksize -> a i -> a (i + 1))
-> l:(i:nat{i <= w * n + w} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c)
-> f_v:(i:nat{i < n} -> lseq inp_t (w * blocksize) -> a_vec i -> a_vec (i + 1))
-> l_v:(i:nat{i <= n} -> len:nat{len < w * blocksize} -> lseq inp_t len -> a_vec i -> c)
-> normalize_v:(i:nat{i <= n} -> a_vec i -> a (w * i))
-> acc_v0:a_vec 0 ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq inp_t (w * blocksize)) (acc_v:a_vec i).
repeat_gen_blocks_multi_vec_equiv_pre w blocksize n (w * n + w) a a_vec f f_v normalize_v i b_v acc_v) /\
(forall (rem:nat{rem < w * blocksize}) (b_v:lseq inp_t rem) (acc_v:a_vec n).
repeat_gen_blocks_vec_equiv_pre w blocksize n a a_vec f l l_v normalize_v rem b_v acc_v))
(ensures
repeat_gen_blocks (w * blocksize) 0 n inp a_vec f_v l_v acc_v0 ==
repeat_gen_blocks blocksize 0 (w * n + w) inp a f l (normalize_v 0 acc_v0))
///
/// Lemma
/// (repeat_blocks (w * blocksize) inp f_v l_v acc_v0 ==
/// repeat_blocks blocksize inp f l (normalize_v acc_v0))
///
let repeat_blocks_multi_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(f_v:(lseq a (w * blocksize) -> b_vec -> b_vec))
(normalize_v:(b_vec -> b))
(b_v:lseq a (w * blocksize))
(acc_v:b_vec)
: prop
=
Math.Lemmas.cancel_mul_mod w blocksize;
normalize_v (f_v b_v acc_v) == repeat_blocks_multi blocksize b_v f (normalize_v acc_v)
val lemma_repeat_blocks_multi_vec:
#a:Type0
-> #b:Type0
-> #b_vec:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq a{length inp % (w * blocksize) = 0 /\ length inp % blocksize = 0}
-> f:(lseq a blocksize -> b -> b)
-> f_v:(lseq a (w * blocksize) -> b_vec -> b_vec)
-> normalize_v:(b_vec -> b)
-> acc_v0:b_vec ->
Lemma
(requires
(forall (b_v:lseq a (w * blocksize)) (acc_v:b_vec).
repeat_blocks_multi_vec_equiv_pre w blocksize f f_v normalize_v b_v acc_v))
(ensures
normalize_v (repeat_blocks_multi #a #b_vec (w * blocksize) inp f_v acc_v0) ==
repeat_blocks_multi #a #b blocksize inp f (normalize_v acc_v0))
let repeat_blocks_vec_equiv_pre
(#a:Type0)
(#b:Type0)
(#b_vec:Type0)
(#c:Type0)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(f:(lseq a blocksize -> b -> b))
(l:(len:nat{len < blocksize} -> lseq a len -> b -> c))
(l_v:(len:nat{len < w * blocksize} -> lseq a len -> b_vec -> c))
(normalize_v:(b_vec -> b))
(rem:nat{rem < w * blocksize})
(b_v:lseq a rem)
(acc_v:b_vec)
: prop
=
l_v rem b_v acc_v ==
repeat_blocks blocksize b_v f l (normalize_v acc_v)
val lemma_repeat_blocks_vec:
#a:Type0
-> #b:Type0
-> #b_vec:Type0
-> #c:Type0
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> inp:seq a
-> f:(lseq a blocksize -> b -> b)
-> l:(len:nat{len < blocksize} -> lseq a len -> b -> c)
-> f_v:(lseq a (w * blocksize) -> b_vec -> b_vec)
-> l_v:(len:nat{len < w * blocksize} -> lseq a len -> b_vec -> c)
-> normalize_v:(b_vec -> b)
-> acc_v0:b_vec ->
Lemma
(requires
(forall (b_v:lseq a (w * blocksize)) (acc_v:b_vec).
repeat_blocks_multi_vec_equiv_pre w blocksize f f_v normalize_v b_v acc_v) /\
(forall (rem:nat{rem < w * blocksize}) (b_v:lseq a rem) (acc_v:b_vec).
repeat_blocks_vec_equiv_pre w blocksize f l l_v normalize_v rem b_v acc_v))
(ensures
repeat_blocks (w * blocksize) inp f_v l_v acc_v0 ==
repeat_blocks blocksize inp f l (normalize_v acc_v0))
///
/// Lemma
/// (map_blocks (w * blocksize) inp f_v l_v == map_blocks blocksize inp f l)
///
val lemma_f_map_ind: w:pos -> blocksize:pos -> n:nat -> i:nat{i < n} -> k:nat{k < w * blocksize} ->
Lemma (w * i + k / blocksize < w * n)
let map_blocks_multi_vec_equiv_pre_k
(#a:Type)
(w:pos)
(blocksize:pos{w * blocksize <= max_size_t})
(n:nat)
(hi_f:nat{w * n <= hi_f})
(f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize))
(f_v:(i:nat{i < n} -> lseq a (w * blocksize) -> lseq a (w * blocksize)))
(i:nat{i < n})
(b_v:lseq a (w * blocksize))
(k:nat{k < w * blocksize})
: prop
=
Math.Lemmas.cancel_mul_div w blocksize;
let block = get_block_s #a #(w * blocksize) blocksize b_v k in
lemma_f_map_ind w blocksize n i k;
Seq.index (f_v i b_v) k == Seq.index (f (w * i + k / blocksize) block) (k % blocksize)
val lemma_map_blocks_multi_vec:
#a:Type
-> w:pos
-> blocksize:pos{w * blocksize <= max_size_t}
-> n:nat
-> inp:seq a{length inp = w * n * blocksize}
-> f:(i:nat{i < w * n} -> lseq a blocksize -> lseq a blocksize)
-> f_v:(i:nat{i < n} -> lseq a (w * blocksize) -> lseq a (w * blocksize)) ->
Lemma
(requires
(forall (i:nat{i < n}) (b_v:lseq a (w * blocksize)) (k:nat{k < w * blocksize}).
map_blocks_multi_vec_equiv_pre_k w blocksize n (w * n) f f_v i b_v k))
(ensures
(len_is_w_n_blocksize w blocksize n;
map_blocks_multi (w * blocksize) n n inp f_v ==
map_blocks_multi blocksize (w * n) (w * n) inp f)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Vec.Lemmas.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.Sequence.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
w: Prims.pos ->
blocksize: Prims.pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
n: Prims.nat ->
f:
(i: Prims.nat{i < w * n + w} -> _: Lib.Sequence.lseq a blocksize
-> Lib.Sequence.lseq a blocksize) ->
l:
(i: Prims.nat{i <= w * n + w} -> rem: Prims.nat{rem < blocksize} -> _: Lib.Sequence.lseq a rem
-> Lib.Sequence.lseq a rem) ->
l_v:
(i: Prims.nat{i <= n} -> rem: Prims.nat{rem < w * blocksize} -> _: Lib.Sequence.lseq a rem
-> Lib.Sequence.lseq a rem) ->
rem: Prims.nat{rem < w * blocksize} ->
b_v: Lib.Sequence.lseq a rem ->
k: Prims.nat{k < rem}
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Prims.op_Division",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Modulus",
"Lib.Sequence.Lemmas.get_block_s",
"Prims.bool",
"Prims.unit",
"Prims._assert",
"Lib.Sequence.mod_div_lt",
"Lib.Sequence.Lemmas.get_last_s",
"Prims.prop",
"Lib.Sequence.div_mul_lt",
"Prims.int"
] | [] | false | false | false | false | true | let map_blocks_vec_equiv_pre_k
(#a: Type)
(w: pos)
(blocksize: pos{w * blocksize <= max_size_t})
(n: nat)
(f: (i: nat{i < w * n + w} -> lseq a blocksize -> lseq a blocksize))
(l: (i: nat{i <= w * n + w} -> rem: nat{rem < blocksize} -> lseq a rem -> lseq a rem))
(l_v: (i: nat{i <= n} -> rem: nat{rem < w * blocksize} -> lseq a rem -> lseq a rem))
(rem: nat{rem < w * blocksize})
(b_v: lseq a rem)
(k: nat{k < rem})
: prop =
| let j = w * n + k / blocksize in
div_mul_lt blocksize k w;
if k < (rem / blocksize) * blocksize
then
let block = get_block_s #a #rem blocksize b_v k in
Seq.index (l_v n rem b_v) k == Seq.index (f j block) (k % blocksize)
else
let block_l = get_last_s blocksize b_v in
mod_div_lt blocksize k rem;
assert (k % blocksize < rem % blocksize);
Seq.index (l_v n rem b_v) k == Seq.index (l j (rem % blocksize) block_l) (k % blocksize) | false |
Hacl.Impl.Ed25519.PointCompress.fst | Hacl.Impl.Ed25519.PointCompress.x_mod_2 | val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2
) | val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2
) | let x_mod_2 x =
(**) let h0 = ST.get() in
let x0 = x.(0ul) in
let z = x0 &. u64 1 in
mod_mask_lemma x0 1ul;
Lib.IntTypes.Compatibility.uintv_extensionality (u64 1) (mod_mask #U64 1ul);
z | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.PointCompress.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 32,
"start_col": 0,
"start_line": 26
} | module Hacl.Impl.Ed25519.PointCompress
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.ByteSequence
open Lib.Buffer
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2 | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.Compatibility.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.PointCompress.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Lib.IntTypes.uint64 | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum25519.felem",
"Prims.unit",
"Lib.IntTypes.Compatibility.uintv_extensionality",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.u64",
"Lib.IntTypes.mod_mask",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.mod_mask_lemma",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.uint64",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let x_mod_2 x =
| let h0 = ST.get () in
let x0 = x.(0ul) in
let z = x0 &. u64 1 in
mod_mask_lemma x0 1ul;
Lib.IntTypes.Compatibility.uintv_extensionality (u64 1) (mod_mask #U64 1ul);
z | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists1 | val compute_gen_elim_tele_correct_exists1
(ty: _)
(body: (ty -> gen_elim_i))
(ih: (x: ty -> GTot (ge_to_tele_t (body x))))
: Tot (ge_to_tele_t (GEExists1 #ty body)) | val compute_gen_elim_tele_correct_exists1
(ty: _)
(body: (ty -> gen_elim_i))
(ih: (x: ty -> GTot (ge_to_tele_t (body x))))
: Tot (ge_to_tele_t (GEExists1 #ty body)) | let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 413,
"start_col": 0,
"start_line": 403
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ty: Type ->
body: (_: ty -> Steel.ST.GenElim1.Base.gen_elim_i) ->
ih: (x: ty -> Prims.GTot (Steel.ST.GenElim1.ge_to_tele_t (body x)))
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEExists1 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.ge_to_tele_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.Base.GEExists1",
"Prims.unit",
"Steel.ST.Util.intro_exists",
"Steel.ST.GenElim1.elim_exists'",
"Steel.ST.GenElim1.Base.compute_gen_elim_p"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: (ty -> gen_elim_i))
(ih: (x: ty -> GTot (ge_to_tele_t (body x))))
: Tot (ge_to_tele_t (GEExists1 #ty body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_unit_elim_f_star | val compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2)) | val compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2)) | let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val () | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 39,
"start_col": 0,
"start_line": 29
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i1: Steel.ST.GenElim1.Base.gen_unit_elim_i ->
i2: Steel.ST.GenElim1.Base.gen_unit_elim_i ->
f1: Steel.ST.GenElim1.gen_unit_elim_t i1 ->
f2: Steel.ST.GenElim1.gen_unit_elim_t i2
-> Steel.ST.GenElim1.gen_unit_elim_t (Steel.ST.GenElim1.Base.GUEStar i1 i2) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.gen_unit_elim_t",
"Steel.Memory.inames",
"FStar.Universe.raise_val",
"Prims.unit",
"FStar.Universe.raise_t",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.GenElim1.Base.GUEStar",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p"
] | [] | false | false | false | false | false | let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2)) =
| fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2))
((compute_gen_unit_elim_p i1) `star` (compute_gen_unit_elim_p i2));
let _ = f1 _ in
let _ = f2 _ in
rewrite ((compute_gen_unit_elim_q i1) `star` (compute_gen_unit_elim_q i2))
(compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val () | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_star | val compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r)) | val compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r)) | let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 340,
"start_col": 0,
"start_line": 329
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: Steel.ST.GenElim1.Base.gen_elim_i ->
ihl: Steel.ST.GenElim1.ge_to_tele_t l ->
r: Steel.ST.GenElim1.Base.gen_elim_i ->
ihr: Steel.ST.GenElim1.ge_to_tele_t r
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEStar l r) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.ge_to_tele_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.GEStar",
"Prims.unit",
"Steel.ST.GenElim1.tele_star_correct",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.Effect.Common.star"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) ((compute_gen_elim_p l) `star` (compute_gen_elim_p r));
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_no_abs1 | val compute_gen_elim_tele_correct_exists_no_abs1 (ty: _) (body: (ty -> vprop))
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body)) | val compute_gen_elim_tele_correct_exists_no_abs1 (ty: _) (body: (ty -> vprop))
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body)) | let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 389,
"start_col": 0,
"start_line": 380
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ty: Type -> body: (_: ty -> Steel.Effect.Common.vprop)
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEExistsNoAbs1 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_",
"Steel.Effect.Common.star",
"Steel.ST.Util.pure",
"Prims.l_True",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.GEExistsNoAbs1",
"Prims.unit",
"Steel.ST.Util.intro_exists",
"Steel.ST.Util.intro_pure",
"Steel.ST.GenElim1.elim_exists'",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.ge_to_tele_t"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_exists_no_abs1 (ty: _) (body: (ty -> vprop))
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> (body x) `star` (pure True));
rewrite_with_trefl (exists_ _) (tele_p _) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_exists_unit0 | val compute_gen_elim_f_exists_unit0 (a: Type0) (body: (a -> gen_unit_elim_i))
: Tot (gen_elim_t (GEExistsUnit0 body)) | val compute_gen_elim_f_exists_unit0 (a: Type0) (body: (a -> gen_unit_elim_i))
: Tot (gen_elim_t (GEExistsUnit0 body)) | let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 128,
"start_col": 0,
"start_line": 118
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> body: (_: a -> Steel.ST.GenElim1.Base.gen_unit_elim_i)
-> Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEExistsUnit0 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEExistsUnit0",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"FStar.Universe.raise_val",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.gen_elim_t"
] | [] | false | false | false | false | false | let compute_gen_elim_f_exists_unit0 (a: Type0) (body: (a -> gen_unit_elim_i))
: Tot (gen_elim_t (GEExistsUnit0 body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body))
(exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res:compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res | false |
Hacl.Impl.Ed25519.PointCompress.fst | Hacl.Impl.Ed25519.PointCompress.point_compress_ | val point_compress_:
tmp:lbuffer uint64 15ul
-> p:point ->
Stack unit
(requires fun h -> live h tmp /\ live h p /\ disjoint tmp p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (
let zinv = Spec.Curve25519.finv (F51.fevalh h0 (gsub p 10ul 5ul)) in
let x = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 0ul 5ul)) zinv in
let y = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 5ul 5ul)) zinv in
F51.mul_inv_t h1 (gsub tmp 10ul 5ul) /\
F51.fevalh h1 (gsub tmp 10ul 5ul) == y /\
F51.as_nat h1 (gsub tmp 5ul 5ul) == x)
) | val point_compress_:
tmp:lbuffer uint64 15ul
-> p:point ->
Stack unit
(requires fun h -> live h tmp /\ live h p /\ disjoint tmp p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (
let zinv = Spec.Curve25519.finv (F51.fevalh h0 (gsub p 10ul 5ul)) in
let x = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 0ul 5ul)) zinv in
let y = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 5ul 5ul)) zinv in
F51.mul_inv_t h1 (gsub tmp 10ul 5ul) /\
F51.fevalh h1 (gsub tmp 10ul 5ul) == y /\
F51.as_nat h1 (gsub tmp 5ul 5ul) == x)
) | let point_compress_ tmp p =
let zinv = sub tmp 0ul 5ul in
let x = sub tmp 5ul 5ul in
let out = sub tmp 10ul 5ul in
let px = getx p in
let py = gety p in
let pz = getz p in
inverse zinv pz;
fmul x px zinv;
reduce x;
fmul out py zinv;
reduce_513 out | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.PointCompress.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 157,
"start_col": 0,
"start_line": 145
} | module Hacl.Impl.Ed25519.PointCompress
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.ByteSequence
open Lib.Buffer
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2
)
let x_mod_2 x =
(**) let h0 = ST.get() in
let x0 = x.(0ul) in
let z = x0 &. u64 1 in
mod_mask_lemma x0 1ul;
Lib.IntTypes.Compatibility.uintv_extensionality (u64 1) (mod_mask #U64 1ul);
z
open FStar.Calc
let lemma_fits_in_prime_last_byte (b:lbytes 32) : Lemma
(requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7)
= calc (==) {
nat_from_bytes_le b <: nat;
(==) { nat_from_intseq_le_slice_lemma b 31 }
nat_from_intseq_le (Seq.slice b 0 31) +
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice b 31 32);
(==) { nat_from_intseq_le_lemma0 (Seq.slice b 31 32) }
nat_from_intseq_le (Seq.slice b 0 31) + pow2 (31*8) * v (Seq.index b 31);
};
assert (nat_from_intseq_le (Seq.slice b 0 31) < pow2 (31 * 8));
calc (<) {
pow2 (31*8) * v (Seq.index b 31);
(<) { }
Spec.Curve25519.prime - nat_from_intseq_le (Seq.slice b 0 31);
(<=) { }
Spec.Curve25519.prime;
(<) { }
pow2 255;
};
FStar.Math.Lemmas.lemma_div_lt_nat (pow2 (31*8) * v (Seq.index b 31)) 255 (31*8);
calc (==) {
(pow2 (31 *8) * v (Seq.index b 31))/ (pow2 (31*8));
(==) { FStar.Math.Lemmas.swap_mul (pow2 (31*8)) (v (Seq.index b 31)) }
(v (Seq.index b 31) * pow2 (31 *8)) / (pow2 (31*8));
(==) { FStar.Math.Lemmas.cancel_mul_div (v (Seq.index b 31)) (pow2 (31*8)) }
v (Seq.index b 31);
};
assert_norm (255 - 31 * 8 == 7)
inline_for_extraction noextract
val add_sign:
out:lbuffer uint8 32ul
-> x:uint64{v x < 2} ->
Stack unit
(requires fun h -> live h out /\ nat_from_bytes_le (as_seq h out) < Spec.Curve25519.prime)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
nat_from_bytes_le (as_seq h1 out) == nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x)
)
let add_sign out x =
(**) let h0 = ST.get() in
let xbyte = to_u8 x in
let o31 = out.(31ul) in
(**) FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
(**) assert (pow2 7 * (v x) <= pow2 7);
(**) assert_norm (pow2 7 < pow2 8);
(**) assert (v (xbyte <<. 7ul) == pow2 7 * (v x));
out.(31ul) <- o31 +. (xbyte <<. 7ul);
(**) let h1 = ST.get() in
(**) calc (==) {
(**) nat_from_intseq_le (as_seq h1 out) <: nat;
(**) (==) { nat_from_intseq_le_slice_lemma (as_seq h1 out) 31 }
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
(**) (==) {
(**) calc (==) {
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
(**) (==) { calc (==) {
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32) <: nat;
(**) (==) { nat_from_intseq_le_lemma0 (Seq.slice (as_seq h1 out) 31 32) }
(**) v (o31 +. (xbyte <<. 7ul));
(**) (==) { calc (==) {
(**) v (o31 +. (xbyte <<. 7ul)) <: nat;
(**) (==) { }
(**) (v o31 + v (xbyte <<. 7ul)) % pow2 8;
(**) (==) { FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
(**) assert (pow2 7 * (v x) <= pow2 7);
(**) assert_norm (pow2 7 < pow2 8);
(**) lemma_fits_in_prime_last_byte (as_seq h0 out);
(**) assert_norm (pow2 7 + pow2 7 == pow2 8);
(**) FStar.Math.Lemmas.modulo_lemma (v o31 + pow2 7 * (v x)) (pow2 8)
(**) }
(**) v o31 + pow2 7 * (v x);
(**) }; nat_from_intseq_le_lemma0 (Seq.slice (as_seq h0 out) 31 32)
(**) }
(**) nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x);
(**) } }
(**) pow2 (31 * 8) * (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x));
(**) (==) { FStar.Math.Lemmas.distributivity_add_right (pow2 (31 * 8))
(**) (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32)) (pow2 7 * (v x)) }
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 (31 * 8) * pow2 7 * (v x);
(**) (==) { assert_norm (pow2 (31*8) * pow2 7 == pow2 255) }
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 255 * (v x);
(**) }
(**) }
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 255 * (v x);
(**) (==) { nat_from_intseq_le_slice_lemma (as_seq h0 out) 31 }
(**) nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x);
(**) }
inline_for_extraction noextract
val point_compress_:
tmp:lbuffer uint64 15ul
-> p:point ->
Stack unit
(requires fun h -> live h tmp /\ live h p /\ disjoint tmp p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (
let zinv = Spec.Curve25519.finv (F51.fevalh h0 (gsub p 10ul 5ul)) in
let x = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 0ul 5ul)) zinv in
let y = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 5ul 5ul)) zinv in
F51.mul_inv_t h1 (gsub tmp 10ul 5ul) /\
F51.fevalh h1 (gsub tmp 10ul 5ul) == y /\
F51.as_nat h1 (gsub tmp 5ul 5ul) == x) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.Compatibility.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.PointCompress.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | tmp: Lib.Buffer.lbuffer Lib.IntTypes.uint64 15ul -> p: Hacl.Bignum25519.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum25519.point",
"Hacl.Bignum25519.reduce_513",
"Prims.unit",
"Hacl.Bignum25519.fmul",
"Hacl.Bignum25519.reduce",
"Hacl.Bignum25519.inverse",
"Hacl.Bignum25519.felem",
"Hacl.Bignum25519.getz",
"Hacl.Bignum25519.gety",
"Hacl.Bignum25519.getx",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let point_compress_ tmp p =
| let zinv = sub tmp 0ul 5ul in
let x = sub tmp 5ul 5ul in
let out = sub tmp 10ul 5ul in
let px = getx p in
let py = gety p in
let pz = getz p in
inverse zinv pz;
fmul x px zinv;
reduce x;
fmul out py zinv;
reduce_513 out | false |
Vale.Poly1305.Util.fsti | Vale.Poly1305.Util.seqTo128_app | val seqTo128_app (s: Seq.seq nat64) (i: int) : nat128 | val seqTo128_app (s: Seq.seq nat64) (i: int) : nat128 | let seqTo128_app (s:Seq.seq nat64) (i:int) : nat128 = seqTo128 s i | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Util.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 37,
"start_col": 0,
"start_line": 37
} | module Vale.Poly1305.Util
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Poly1305.Spec_s
open Vale.X64.Machine_s
open Vale.Poly1305.Math
open Vale.X64.State
open Vale.X64.Decls
open Vale.Def.Opaque_s
open Vale.X64.Memory
let rec poly1305_heap_blocks'
(h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
if k = 0 then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r)
val poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : int
val reveal_poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : Lemma
(requires 0 <= k /\ k <= Seq.length s /\ k % 2 == 0)
(ensures poly1305_heap_blocks h pad r s k = poly1305_heap_blocks' h pad r s k)
type t_seqTo128 = int -> nat128
let seqTo128 (s:Seq.seq nat64) : t_seqTo128 =
let f (i:int) : nat128 =
if 0 <= i && i < Seq.length s / 2 then
(Seq.index s (2 * i)) + 0x10000000000000000 * (Seq.index s (2 * i + 1))
else
42 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Util.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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"
} | false | s: FStar.Seq.Base.seq Vale.X64.Memory.nat64 -> i: Prims.int -> Vale.X64.Machine_s.nat128 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat64",
"Prims.int",
"Vale.Poly1305.Util.seqTo128",
"Vale.X64.Machine_s.nat128"
] | [] | false | false | false | true | false | let seqTo128_app (s: Seq.seq nat64) (i: int) : nat128 =
| seqTo128 s i | false |
Hacl.Impl.Ed25519.PointCompress.fst | Hacl.Impl.Ed25519.PointCompress.point_compress | val point_compress:
out:lbuffer uint8 32ul
-> p:point ->
Stack unit
(requires fun h -> live h out /\ live h p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.Ed25519.point_compress (F51.point_eval h0 p)
) | val point_compress:
out:lbuffer uint8 32ul
-> p:point ->
Stack unit
(requires fun h -> live h out /\ live h p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.Ed25519.point_compress (F51.point_eval h0 p)
) | let point_compress z p =
push_frame();
let tmp = create 15ul (u64 0) in
let zinv = sub tmp 0ul 5ul in
let x = sub tmp 5ul 5ul in
let out = sub tmp 10ul 5ul in
point_compress_ tmp p;
let b = x_mod_2 x in
store_51 z out;
add_sign z b;
(**) let h3 = ST.get() in
(**) lemma_nat_from_to_bytes_le_preserves_value (as_seq h3 z) 32;
(**) lemma_nat_to_from_bytes_le_preserves_value (as_seq h3 z) 32 (F51.fevalh h3 out);
pop_frame() | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.PointCompress.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 185,
"start_col": 0,
"start_line": 169
} | module Hacl.Impl.Ed25519.PointCompress
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.ByteSequence
open Lib.Buffer
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2
)
let x_mod_2 x =
(**) let h0 = ST.get() in
let x0 = x.(0ul) in
let z = x0 &. u64 1 in
mod_mask_lemma x0 1ul;
Lib.IntTypes.Compatibility.uintv_extensionality (u64 1) (mod_mask #U64 1ul);
z
open FStar.Calc
let lemma_fits_in_prime_last_byte (b:lbytes 32) : Lemma
(requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7)
= calc (==) {
nat_from_bytes_le b <: nat;
(==) { nat_from_intseq_le_slice_lemma b 31 }
nat_from_intseq_le (Seq.slice b 0 31) +
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice b 31 32);
(==) { nat_from_intseq_le_lemma0 (Seq.slice b 31 32) }
nat_from_intseq_le (Seq.slice b 0 31) + pow2 (31*8) * v (Seq.index b 31);
};
assert (nat_from_intseq_le (Seq.slice b 0 31) < pow2 (31 * 8));
calc (<) {
pow2 (31*8) * v (Seq.index b 31);
(<) { }
Spec.Curve25519.prime - nat_from_intseq_le (Seq.slice b 0 31);
(<=) { }
Spec.Curve25519.prime;
(<) { }
pow2 255;
};
FStar.Math.Lemmas.lemma_div_lt_nat (pow2 (31*8) * v (Seq.index b 31)) 255 (31*8);
calc (==) {
(pow2 (31 *8) * v (Seq.index b 31))/ (pow2 (31*8));
(==) { FStar.Math.Lemmas.swap_mul (pow2 (31*8)) (v (Seq.index b 31)) }
(v (Seq.index b 31) * pow2 (31 *8)) / (pow2 (31*8));
(==) { FStar.Math.Lemmas.cancel_mul_div (v (Seq.index b 31)) (pow2 (31*8)) }
v (Seq.index b 31);
};
assert_norm (255 - 31 * 8 == 7)
inline_for_extraction noextract
val add_sign:
out:lbuffer uint8 32ul
-> x:uint64{v x < 2} ->
Stack unit
(requires fun h -> live h out /\ nat_from_bytes_le (as_seq h out) < Spec.Curve25519.prime)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
nat_from_bytes_le (as_seq h1 out) == nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x)
)
let add_sign out x =
(**) let h0 = ST.get() in
let xbyte = to_u8 x in
let o31 = out.(31ul) in
(**) FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
(**) assert (pow2 7 * (v x) <= pow2 7);
(**) assert_norm (pow2 7 < pow2 8);
(**) assert (v (xbyte <<. 7ul) == pow2 7 * (v x));
out.(31ul) <- o31 +. (xbyte <<. 7ul);
(**) let h1 = ST.get() in
(**) calc (==) {
(**) nat_from_intseq_le (as_seq h1 out) <: nat;
(**) (==) { nat_from_intseq_le_slice_lemma (as_seq h1 out) 31 }
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
(**) (==) {
(**) calc (==) {
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
(**) (==) { calc (==) {
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32) <: nat;
(**) (==) { nat_from_intseq_le_lemma0 (Seq.slice (as_seq h1 out) 31 32) }
(**) v (o31 +. (xbyte <<. 7ul));
(**) (==) { calc (==) {
(**) v (o31 +. (xbyte <<. 7ul)) <: nat;
(**) (==) { }
(**) (v o31 + v (xbyte <<. 7ul)) % pow2 8;
(**) (==) { FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
(**) assert (pow2 7 * (v x) <= pow2 7);
(**) assert_norm (pow2 7 < pow2 8);
(**) lemma_fits_in_prime_last_byte (as_seq h0 out);
(**) assert_norm (pow2 7 + pow2 7 == pow2 8);
(**) FStar.Math.Lemmas.modulo_lemma (v o31 + pow2 7 * (v x)) (pow2 8)
(**) }
(**) v o31 + pow2 7 * (v x);
(**) }; nat_from_intseq_le_lemma0 (Seq.slice (as_seq h0 out) 31 32)
(**) }
(**) nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x);
(**) } }
(**) pow2 (31 * 8) * (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x));
(**) (==) { FStar.Math.Lemmas.distributivity_add_right (pow2 (31 * 8))
(**) (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32)) (pow2 7 * (v x)) }
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 (31 * 8) * pow2 7 * (v x);
(**) (==) { assert_norm (pow2 (31*8) * pow2 7 == pow2 255) }
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 255 * (v x);
(**) }
(**) }
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 255 * (v x);
(**) (==) { nat_from_intseq_le_slice_lemma (as_seq h0 out) 31 }
(**) nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x);
(**) }
inline_for_extraction noextract
val point_compress_:
tmp:lbuffer uint64 15ul
-> p:point ->
Stack unit
(requires fun h -> live h tmp /\ live h p /\ disjoint tmp p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (
let zinv = Spec.Curve25519.finv (F51.fevalh h0 (gsub p 10ul 5ul)) in
let x = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 0ul 5ul)) zinv in
let y = Spec.Curve25519.fmul (F51.fevalh h0 (gsub p 5ul 5ul)) zinv in
F51.mul_inv_t h1 (gsub tmp 10ul 5ul) /\
F51.fevalh h1 (gsub tmp 10ul 5ul) == y /\
F51.as_nat h1 (gsub tmp 5ul 5ul) == x)
)
let point_compress_ tmp p =
let zinv = sub tmp 0ul 5ul in
let x = sub tmp 5ul 5ul in
let out = sub tmp 10ul 5ul in
let px = getx p in
let py = gety p in
let pz = getz p in
inverse zinv pz;
fmul x px zinv;
reduce x;
fmul out py zinv;
reduce_513 out
val point_compress:
out:lbuffer uint8 32ul
-> p:point ->
Stack unit
(requires fun h -> live h out /\ live h p /\ F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.Ed25519.point_compress (F51.point_eval h0 p)
) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.Compatibility.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.PointCompress.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> p: Hacl.Bignum25519.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum25519.point",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.ByteSequence.lemma_nat_to_from_bytes_le_preserves_value",
"Lib.IntTypes.SEC",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Impl.Ed25519.Field51.fevalh",
"Lib.ByteSequence.lemma_nat_from_to_bytes_le_preserves_value",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Ed25519.PointCompress.add_sign",
"Hacl.Bignum25519.store_51",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Hacl.Impl.Ed25519.PointCompress.x_mod_2",
"Lib.IntTypes.uint64",
"Hacl.Impl.Ed25519.PointCompress.point_compress_",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.Buffer.create",
"Lib.IntTypes.u64",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let point_compress z p =
| push_frame ();
let tmp = create 15ul (u64 0) in
let zinv = sub tmp 0ul 5ul in
let x = sub tmp 5ul 5ul in
let out = sub tmp 10ul 5ul in
point_compress_ tmp p;
let b = x_mod_2 x in
store_51 z out;
add_sign z b;
let h3 = ST.get () in
lemma_nat_from_to_bytes_le_preserves_value (as_seq h3 z) 32;
lemma_nat_to_from_bytes_le_preserves_value (as_seq h3 z) 32 (F51.fevalh h3 out);
pop_frame () | false |
Vale.Poly1305.Util.fsti | Vale.Poly1305.Util.modifies_buffer | val modifies_buffer : b: Vale.X64.Memory.buffer64 -> h1: Vale.X64.Memory.vale_heap -> h2: Vale.X64.Memory.vale_heap
-> Vale.Def.Prop_s.prop0 | let modifies_buffer (b:buffer64) (h1 h2:vale_heap) = modifies_mem (loc_buffer b) h1 h2 | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Util.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 93,
"end_line": 51,
"start_col": 7,
"start_line": 51
} | module Vale.Poly1305.Util
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Poly1305.Spec_s
open Vale.X64.Machine_s
open Vale.Poly1305.Math
open Vale.X64.State
open Vale.X64.Decls
open Vale.Def.Opaque_s
open Vale.X64.Memory
let rec poly1305_heap_blocks'
(h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
if k = 0 then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r)
val poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : int
val reveal_poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : Lemma
(requires 0 <= k /\ k <= Seq.length s /\ k % 2 == 0)
(ensures poly1305_heap_blocks h pad r s k = poly1305_heap_blocks' h pad r s k)
type t_seqTo128 = int -> nat128
let seqTo128 (s:Seq.seq nat64) : t_seqTo128 =
let f (i:int) : nat128 =
if 0 <= i && i < Seq.length s / 2 then
(Seq.index s (2 * i)) + 0x10000000000000000 * (Seq.index s (2 * i + 1))
else
42
in f
let seqTo128_app (s:Seq.seq nat64) (i:int) : nat128 = seqTo128 s i
val lemma_poly1305_heap_hash_blocks_alt (h:int) (pad:int) (r:int) (m:vale_heap) (b:buffer64) (n:int) : Lemma
(requires 0 <= n /\ n + n <= buffer_length b /\ n + n <= Seq.length (buffer64_as_seq m b))
(ensures
((n + n) % 2) == 0 /\ // REVIEW
poly1305_heap_blocks h pad r (buffer64_as_seq m b) (n + n) ==
poly1305_hash_blocks h pad r (seqTo128 (buffer64_as_seq m b)) n)
let rec buffers_readable (h:vale_heap) (l:list buffer64) : GTot Type0 (decreases l) =
match l with
| [] -> True
| b :: l' -> buffer_readable h b /\ buffers_readable h l' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Util.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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"
} | false | b: Vale.X64.Memory.buffer64 -> h1: Vale.X64.Memory.vale_heap -> h2: Vale.X64.Memory.vale_heap
-> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Memory.loc_buffer",
"Vale.X64.Memory.vuint64",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | true | false | let modifies_buffer (b: buffer64) (h1 h2: vale_heap) =
| modifies_mem (loc_buffer b) h1 h2 | false |
|
Vale.Poly1305.Util.fsti | Vale.Poly1305.Util.readable_words | val readable_words : len: Prims.nat -> Prims.int | let readable_words (len:nat) =
((len + 15) / 16) * 2 | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Util.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 54,
"start_col": 0,
"start_line": 53
} | module Vale.Poly1305.Util
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Poly1305.Spec_s
open Vale.X64.Machine_s
open Vale.Poly1305.Math
open Vale.X64.State
open Vale.X64.Decls
open Vale.Def.Opaque_s
open Vale.X64.Memory
let rec poly1305_heap_blocks'
(h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
if k = 0 then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r)
val poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : int
val reveal_poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : Lemma
(requires 0 <= k /\ k <= Seq.length s /\ k % 2 == 0)
(ensures poly1305_heap_blocks h pad r s k = poly1305_heap_blocks' h pad r s k)
type t_seqTo128 = int -> nat128
let seqTo128 (s:Seq.seq nat64) : t_seqTo128 =
let f (i:int) : nat128 =
if 0 <= i && i < Seq.length s / 2 then
(Seq.index s (2 * i)) + 0x10000000000000000 * (Seq.index s (2 * i + 1))
else
42
in f
let seqTo128_app (s:Seq.seq nat64) (i:int) : nat128 = seqTo128 s i
val lemma_poly1305_heap_hash_blocks_alt (h:int) (pad:int) (r:int) (m:vale_heap) (b:buffer64) (n:int) : Lemma
(requires 0 <= n /\ n + n <= buffer_length b /\ n + n <= Seq.length (buffer64_as_seq m b))
(ensures
((n + n) % 2) == 0 /\ // REVIEW
poly1305_heap_blocks h pad r (buffer64_as_seq m b) (n + n) ==
poly1305_hash_blocks h pad r (seqTo128 (buffer64_as_seq m b)) n)
let rec buffers_readable (h:vale_heap) (l:list buffer64) : GTot Type0 (decreases l) =
match l with
| [] -> True
| b :: l' -> buffer_readable h b /\ buffers_readable h l'
unfold let modifies_buffer (b:buffer64) (h1 h2:vale_heap) = modifies_mem (loc_buffer b) h1 h2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Util.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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"
} | false | len: Prims.nat -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Prims.op_Addition",
"Prims.int"
] | [] | false | false | false | true | false | let readable_words (len: nat) =
| ((len + 15) / 16) * 2 | false |
|
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct0 | val compute_gen_elim_nondep_correct0 (i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 []) | val compute_gen_elim_nondep_correct0 (i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 []) | let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 485,
"start_col": 0,
"start_line": 476
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i0: Steel.ST.GenElim1.Base.gen_elim_i -> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0 [] | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.Base.curried_function_type",
"Prims.Nil",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.gen_elim_nondep_p",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a'",
"Steel.ST.GenElim1.rewrite_with_trefl",
"FStar.Universe.raise_val",
"Steel.ST.GenElim1.Base.compute_uncurry",
"Steel.ST.GenElim1.Base.compute_gen_elim_p'",
"Steel.ST.Util.elim_pure",
"Steel.Effect.Common.star",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct0 (i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 []) =
| fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _)
((q (U.raise_val ())) `star` (pure (post (U.raise_val ()))));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ()))
(compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | false |
Vale.Poly1305.Util.fsti | Vale.Poly1305.Util.poly1305_heap_blocks' | val poly1305_heap_blocks'
(h pad r: int)
(s: Seq.seq nat64)
(k: int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) | val poly1305_heap_blocks'
(h pad r: int)
(s: Seq.seq nat64)
(k: int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) | let rec poly1305_heap_blocks'
(h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
if k = 0 then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Util.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 21,
"start_col": 0,
"start_line": 14
} | module Vale.Poly1305.Util
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Poly1305.Spec_s
open Vale.X64.Machine_s
open Vale.Poly1305.Math
open Vale.X64.State
open Vale.X64.Decls
open Vale.Def.Opaque_s
open Vale.X64.Memory | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Util.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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"
} | false |
h: Prims.int ->
pad: Prims.int ->
r: Prims.int ->
s: FStar.Seq.Base.seq Vale.X64.Memory.nat64 ->
k: Prims.int{0 <= k /\ k <= FStar.Seq.Base.length s /\ k % 2 == 0}
-> Prims.Tot Prims.int | Prims.Tot | [
"total",
""
] | [] | [
"Prims.int",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat64",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.op_Equality",
"Prims.bool",
"Vale.Poly1305.Spec_s.modp",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Vale.X64.Machine_s.pow2_64",
"FStar.Seq.Base.index",
"Vale.Poly1305.Util.poly1305_heap_blocks'",
"Prims.op_Subtraction"
] | [
"recursion"
] | false | false | false | false | false | let rec poly1305_heap_blocks'
(h pad r: int)
(s: Seq.seq nat64)
(k: int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
| if k = 0
then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r) | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_t | val mod_inv_limb_t : t: Hacl.Spec.Bignum.Definitions.limb_t -> i: Prims.nat{i <= Lib.IntTypes.bits t} -> Type0 | let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 34,
"start_col": 0,
"start_line": 34
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Spec.Bignum.Definitions.limb_t -> i: Prims.nat{i <= Lib.IntTypes.bits t} -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.bits",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | true | let mod_inv_limb_t (t: limb_t) (i: nat{i <= bits t}) =
| tuple2 (limb t) (limb t) | false |
|
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_star_vprop_correct_exists | val tele_star_vprop_correct_exists
(v: vprop)
(p: prop)
(ty: _)
(body: (ty -> gen_elim_tele))
(ih:
(x: ty
-> GTot
(vprop_rewrite (((tele_p (body x)) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (body x) v p)))))
: Tot
(vprop_rewrite (((tele_p (TExists ty body)) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (TExists ty body) v p))) | val tele_star_vprop_correct_exists
(v: vprop)
(p: prop)
(ty: _)
(body: (ty -> gen_elim_tele))
(ih:
(x: ty
-> GTot
(vprop_rewrite (((tele_p (body x)) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (body x) v p)))))
: Tot
(vprop_rewrite (((tele_p (TExists ty body)) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (TExists ty body) v p))) | let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 92,
"end_line": 233,
"start_col": 0,
"start_line": 224
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
v: Steel.Effect.Common.vprop ->
p: Prims.prop ->
ty: Type ->
body: (_: ty -> Steel.ST.GenElim1.Base.gen_elim_tele) ->
ih:
(x: ty
-> Prims.GTot
(Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p
(body x))
v)
(Steel.ST.Util.pure p))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star_vprop (body x) v p))))
-> Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p
(Steel.ST.GenElim1.Base.TExists ty body))
v)
(Steel.ST.Util.pure p))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star_vprop (Steel.ST.GenElim1.Base.TExists
ty body)
v
p)) | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.Base.gen_elim_tele",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.Base.TExists",
"Prims.unit",
"Steel.ST.Util.intro_exists",
"Steel.ST.GenElim1.elim_exists'"
] | [] | false | false | false | false | false | let tele_star_vprop_correct_exists
(v: vprop)
(p: prop)
(ty: _)
(body: (ty -> gen_elim_tele))
(ih:
(x: ty
-> GTot
(vprop_rewrite (((tele_p (body x)) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (body x) v p)))))
: Tot
(vprop_rewrite (((tele_p (TExists ty body)) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (TExists ty body) v p))) =
| fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _) | false |
Vale.Poly1305.Util.fsti | Vale.Poly1305.Util.buffers_readable | val buffers_readable (h: vale_heap) (l: list buffer64) : GTot Type0 (decreases l) | val buffers_readable (h: vale_heap) (l: list buffer64) : GTot Type0 (decreases l) | let rec buffers_readable (h:vale_heap) (l:list buffer64) : GTot Type0 (decreases l) =
match l with
| [] -> True
| b :: l' -> buffer_readable h b /\ buffers_readable h l' | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Util.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 49,
"start_col": 0,
"start_line": 46
} | module Vale.Poly1305.Util
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Poly1305.Spec_s
open Vale.X64.Machine_s
open Vale.Poly1305.Math
open Vale.X64.State
open Vale.X64.Decls
open Vale.Def.Opaque_s
open Vale.X64.Memory
let rec poly1305_heap_blocks'
(h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
if k = 0 then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r)
val poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : int
val reveal_poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : Lemma
(requires 0 <= k /\ k <= Seq.length s /\ k % 2 == 0)
(ensures poly1305_heap_blocks h pad r s k = poly1305_heap_blocks' h pad r s k)
type t_seqTo128 = int -> nat128
let seqTo128 (s:Seq.seq nat64) : t_seqTo128 =
let f (i:int) : nat128 =
if 0 <= i && i < Seq.length s / 2 then
(Seq.index s (2 * i)) + 0x10000000000000000 * (Seq.index s (2 * i + 1))
else
42
in f
let seqTo128_app (s:Seq.seq nat64) (i:int) : nat128 = seqTo128 s i
val lemma_poly1305_heap_hash_blocks_alt (h:int) (pad:int) (r:int) (m:vale_heap) (b:buffer64) (n:int) : Lemma
(requires 0 <= n /\ n + n <= buffer_length b /\ n + n <= Seq.length (buffer64_as_seq m b))
(ensures
((n + n) % 2) == 0 /\ // REVIEW
poly1305_heap_blocks h pad r (buffer64_as_seq m b) (n + n) ==
poly1305_hash_blocks h pad r (seqTo128 (buffer64_as_seq m b)) n) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Util.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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"
} | false | h: Vale.X64.Memory.vale_heap -> l: Prims.list Vale.X64.Memory.buffer64 -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial",
""
] | [] | [
"Vale.X64.Memory.vale_heap",
"Prims.list",
"Vale.X64.Memory.buffer64",
"Prims.l_True",
"Prims.l_and",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.vuint64",
"Vale.Poly1305.Util.buffers_readable"
] | [
"recursion"
] | false | false | false | false | true | let rec buffers_readable (h: vale_heap) (l: list buffer64) : GTot Type0 (decreases l) =
| match l with
| [] -> True
| b :: l' -> buffer_readable h b /\ buffers_readable h l' | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_star_r | val compute_gen_elim_f_star_r (i1: gen_unit_elim_i) (i2: gen_elim_i) (f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2)) | val compute_gen_elim_f_star_r (i1: gen_unit_elim_i) (i2: gen_elim_i) (f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2)) | let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res' | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 83,
"start_col": 0,
"start_line": 71
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i1: Steel.ST.GenElim1.Base.gen_unit_elim_i ->
i2: Steel.ST.GenElim1.Base.gen_elim_i ->
f2: Steel.ST.GenElim1.gen_elim_t i2
-> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEStarR i1 i2)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEStarR",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.ST.GenElim1.gen_unit_elim_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f"
] | [] | false | false | false | false | false | let compute_gen_elim_f_star_r (i1: gen_unit_elim_i) (i2: gen_elim_i) (f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2)) =
| let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2))
((compute_gen_unit_elim_p i1) `star` (compute_gen_elim_p i2));
let _ = f1 _ in
let res = f2 _ in
let res':compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite ((compute_gen_unit_elim_q i1) `star` (compute_gen_elim_q i2 res))
(compute_gen_elim_q (GEStarR i1 i2) res');
res' | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.