effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val quickProc_wp (a: Type0) : Type u#1
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let quickProc_wp (a:Type0) : Type u#1 = (s0:state) -> (wp_continue:state -> a -> Type0) -> Type0
val quickProc_wp (a: Type0) : Type u#1 let quickProc_wp (a: Type0) : Type u#1 =
false
null
false
s0: state -> (wp_continue: state -> a -> Type0) -> Type0
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.State.state" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr] unfold let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK) let va_lemma_norm_mods (mods:mods_t) (sM sK:state) : Lemma (ensures update_state_mods mods sM sK == update_state_mods_norm mods sM sK) = () [@va_qattr qmodattr] let va_mod_reg_opr (r:reg_opr) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec_opr (r:vec_opr) : mod_t = Mod_vec r [@va_qattr qmodattr] let va_mod_reg (r:reg) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec (x:vec) : mod_t = Mod_vec x [@va_qattr qmodattr] let va_mod_heaplet (h:heaplet_id) : mod_t = Mod_mem_heaplet h
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val quickProc_wp (a: Type0) : Type u#1
[]
Vale.PPC64LE.QuickCode.quickProc_wp
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type0 -> Type
{ "end_col": 96, "end_line": 93, "start_col": 40, "start_line": 93 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_Mod_reg (r:reg) = Mod_reg r
let va_Mod_reg (r: reg) =
false
null
false
Mod_reg r
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.QuickCode.Mod_reg", "Vale.PPC64LE.QuickCode.mod_t" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_Mod_reg : r: Vale.PPC64LE.Machine_s.reg -> Vale.PPC64LE.QuickCode.mod_t
[]
Vale.PPC64LE.QuickCode.va_Mod_reg
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: Vale.PPC64LE.Machine_s.reg -> Vale.PPC64LE.QuickCode.mod_t
{ "end_col": 53, "end_line": 28, "start_col": 44, "start_line": 28 }
Prims.Tot
val va_mod_reg (r: reg) : mod_t
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_mod_reg (r:reg) : mod_t = Mod_reg r
val va_mod_reg (r: reg) : mod_t let va_mod_reg (r: reg) : mod_t =
false
null
false
Mod_reg r
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.QuickCode.Mod_reg", "Vale.PPC64LE.QuickCode.mod_t" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr] unfold let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK) let va_lemma_norm_mods (mods:mods_t) (sM sK:state) : Lemma (ensures update_state_mods mods sM sK == update_state_mods_norm mods sM sK) = () [@va_qattr qmodattr] let va_mod_reg_opr (r:reg_opr) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec_opr (r:vec_opr) : mod_t = Mod_vec r
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_mod_reg (r: reg) : mod_t
[]
Vale.PPC64LE.QuickCode.va_mod_reg
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: Vale.PPC64LE.Machine_s.reg -> Vale.PPC64LE.QuickCode.mod_t
{ "end_col": 63, "end_line": 89, "start_col": 54, "start_line": 89 }
Prims.Tot
val va_mod_vec_opr (r: vec_opr) : mod_t
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_mod_vec_opr (r:vec_opr) : mod_t = Mod_vec r
val va_mod_vec_opr (r: vec_opr) : mod_t let va_mod_vec_opr (r: vec_opr) : mod_t =
false
null
false
Mod_vec r
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.Decls.vec_opr", "Vale.PPC64LE.QuickCode.Mod_vec", "Vale.PPC64LE.QuickCode.mod_t" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr] unfold let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK) let va_lemma_norm_mods (mods:mods_t) (sM sK:state) : Lemma (ensures update_state_mods mods sM sK == update_state_mods_norm mods sM sK) = () [@va_qattr qmodattr] let va_mod_reg_opr (r:reg_opr) : mod_t = Mod_reg r [@va_qattr qmodattr]
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_mod_vec_opr (r: vec_opr) : mod_t
[]
Vale.PPC64LE.QuickCode.va_mod_vec_opr
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: Vale.PPC64LE.Decls.vec_opr -> Vale.PPC64LE.QuickCode.mod_t
{ "end_col": 11, "end_line": 87, "start_col": 2, "start_line": 87 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_quickCode = quickCode
let va_quickCode =
false
null
false
quickCode
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.QuickCode.quickCode" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr] unfold let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK) let va_lemma_norm_mods (mods:mods_t) (sM sK:state) : Lemma (ensures update_state_mods mods sM sK == update_state_mods_norm mods sM sK) = () [@va_qattr qmodattr] let va_mod_reg_opr (r:reg_opr) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec_opr (r:vec_opr) : mod_t = Mod_vec r [@va_qattr qmodattr] let va_mod_reg (r:reg) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec (x:vec) : mod_t = Mod_vec x [@va_qattr qmodattr] let va_mod_heaplet (h:heaplet_id) : mod_t = Mod_mem_heaplet h let quickProc_wp (a:Type0) : Type u#1 = (s0:state) -> (wp_continue:state -> a -> Type0) -> Type0 let k_true (#a:Type0) (_:state) (_:a) = True let t_monotone (#a:Type0) (c:va_code) (wp:quickProc_wp a) : Type = s0:state -> k1:(state -> a -> Type0) -> k2:(state -> a -> Type0) -> Lemma (requires (forall (s:state) (g:a). k1 s g ==> k2 s g)) (ensures wp s0 k1 ==> wp s0 k2) let t_compute (#a:Type0) (c:va_code) (wp:quickProc_wp a) : Type = s0:state -> Ghost (state & va_fuel & a) (requires wp s0 k_true) (ensures fun _ -> True) let t_require (s0:va_state) = state_inv s0 unfold let va_t_require = t_require let va_t_ensure (#a:Type0) (c:va_code) (mods:mods_t) (s0:state) (k:(state -> a -> Type0)) = fun (sM, f0, g) -> eval_code c s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g let t_proof (#a:Type0) (c:va_code) (mods:mods_t) (wp:quickProc_wp a) : Type = s0:state -> k:(state -> a -> Type0) -> Ghost (state & va_fuel & a) (requires t_require s0 /\ wp s0 k) (ensures va_t_ensure c mods s0 k) // Code that returns a ghost value of type a [@va_qattr] noeq type quickCode (a:Type0) : va_code -> Type = | QProc: c:va_code -> mods:mods_t -> wp:quickProc_wp a -> proof:t_proof c mods wp -> quickCode a c
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_quickCode : a: Type0 -> _: Vale.PPC64LE.Machine_s.precode Vale.PPC64LE.Decls.ins Vale.PPC64LE.Decls.ocmp -> Type
[]
Vale.PPC64LE.QuickCode.va_quickCode
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type0 -> _: Vale.PPC64LE.Machine_s.precode Vale.PPC64LE.Decls.ins Vale.PPC64LE.Decls.ocmp -> Type
{ "end_col": 35, "end_line": 129, "start_col": 26, "start_line": 129 }
Prims.Tot
val va_mod_vec (x: vec) : mod_t
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_mod_vec (x:vec) : mod_t = Mod_vec x
val va_mod_vec (x: vec) : mod_t let va_mod_vec (x: vec) : mod_t =
false
null
false
Mod_vec x
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.Machine_s.vec", "Vale.PPC64LE.QuickCode.Mod_vec", "Vale.PPC64LE.QuickCode.mod_t" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr] unfold let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK) let va_lemma_norm_mods (mods:mods_t) (sM sK:state) : Lemma (ensures update_state_mods mods sM sK == update_state_mods_norm mods sM sK) = () [@va_qattr qmodattr] let va_mod_reg_opr (r:reg_opr) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec_opr (r:vec_opr) : mod_t = Mod_vec r
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_mod_vec (x: vec) : mod_t
[]
Vale.PPC64LE.QuickCode.va_mod_vec
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Vale.PPC64LE.Machine_s.vec -> Vale.PPC64LE.QuickCode.mod_t
{ "end_col": 63, "end_line": 90, "start_col": 54, "start_line": 90 }
Prims.Tot
val update_state_mods_norm (mods: mods_t) (sM sK: state) : state
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK)
val update_state_mods_norm (mods: mods_t) (sM sK: state) : state let update_state_mods_norm (mods: mods_t) (sM sK: state) : state =
false
null
false
norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK)
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "FStar.Pervasives.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil", "FStar.Pervasives.delta_only", "Vale.PPC64LE.QuickCode.update_state_mods" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr]
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_state_mods_norm (mods: mods_t) (sM sK: state) : state
[]
Vale.PPC64LE.QuickCode.update_state_mods_norm
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mods: Vale.PPC64LE.QuickCode.mods_t -> sM: Vale.PPC64LE.State.state -> sK: Vale.PPC64LE.State.state -> Vale.PPC64LE.State.state
{ "end_col": 129, "end_line": 76, "start_col": 2, "start_line": 76 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_t_require = t_require
let va_t_require =
false
null
false
t_require
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.QuickCode.t_require" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr] let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK) [@va_qattr] unfold let update_state_mods_norm (mods:mods_t) (sM sK:state) : state = norm [iota; zeta; delta_attr [`%qmodattr]; delta_only [`%update_state_mods; `%update_state_mod]] (update_state_mods mods sM sK) let va_lemma_norm_mods (mods:mods_t) (sM sK:state) : Lemma (ensures update_state_mods mods sM sK == update_state_mods_norm mods sM sK) = () [@va_qattr qmodattr] let va_mod_reg_opr (r:reg_opr) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec_opr (r:vec_opr) : mod_t = Mod_vec r [@va_qattr qmodattr] let va_mod_reg (r:reg) : mod_t = Mod_reg r [@va_qattr qmodattr] let va_mod_vec (x:vec) : mod_t = Mod_vec x [@va_qattr qmodattr] let va_mod_heaplet (h:heaplet_id) : mod_t = Mod_mem_heaplet h let quickProc_wp (a:Type0) : Type u#1 = (s0:state) -> (wp_continue:state -> a -> Type0) -> Type0 let k_true (#a:Type0) (_:state) (_:a) = True let t_monotone (#a:Type0) (c:va_code) (wp:quickProc_wp a) : Type = s0:state -> k1:(state -> a -> Type0) -> k2:(state -> a -> Type0) -> Lemma (requires (forall (s:state) (g:a). k1 s g ==> k2 s g)) (ensures wp s0 k1 ==> wp s0 k2) let t_compute (#a:Type0) (c:va_code) (wp:quickProc_wp a) : Type = s0:state -> Ghost (state & va_fuel & a) (requires wp s0 k_true) (ensures fun _ -> True)
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_t_require : s0: Vale.PPC64LE.Decls.va_state -> Vale.Def.Prop_s.prop0
[]
Vale.PPC64LE.QuickCode.va_t_require
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s0: Vale.PPC64LE.Decls.va_state -> Vale.Def.Prop_s.prop0
{ "end_col": 35, "end_line": 108, "start_col": 26, "start_line": 108 }
Prims.Tot
val update_state_mod (m: mod_t) (sM sK: state) : state
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK
val update_state_mod (m: mod_t) (sM sK: state) : state let update_state_mod (m: mod_t) (sM sK: state) : state =
false
null
false
match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.Decls.va_update_ok", "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.Decls.va_update_reg", "Vale.PPC64LE.Machine_s.vec", "Vale.PPC64LE.Decls.va_update_vec", "Vale.PPC64LE.Decls.va_update_cr0", "Vale.PPC64LE.Decls.va_update_xer", "Vale.PPC64LE.Decls.va_update_mem", "Vale.PPC64LE.Decls.va_update_mem_layout", "Vale.PPC64LE.Decls.heaplet_id", "Vale.PPC64LE.Decls.va_update_mem_heaplet", "Vale.PPC64LE.Decls.va_update_stack", "Vale.PPC64LE.Decls.va_update_stackTaint" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr]
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_state_mod (m: mod_t) (sM sK: state) : state
[]
Vale.PPC64LE.QuickCode.update_state_mod
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
m: Vale.PPC64LE.QuickCode.mod_t -> sM: Vale.PPC64LE.State.state -> sK: Vale.PPC64LE.State.state -> Vale.PPC64LE.State.state
{ "end_col": 48, "end_line": 66, "start_col": 2, "start_line": 55 }
Prims.Tot
val update_state_mods (mods: mods_t) (sM sK: state) : state
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec update_state_mods (mods:mods_t) (sM sK:state) : state = match mods with | [] -> sK | m::mods -> update_state_mod m sM (update_state_mods mods sM sK)
val update_state_mods (mods: mods_t) (sM sK: state) : state let rec update_state_mods (mods: mods_t) (sM sK: state) : state =
false
null
false
match mods with | [] -> sK | m :: mods -> update_state_mod m sM (update_state_mods mods sM sK)
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[ "total" ]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCode.mod_t", "Prims.list", "Vale.PPC64LE.QuickCode.update_state_mod", "Vale.PPC64LE.QuickCode.update_state_mods" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"] let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false) [@va_qattr] let update_state_mod (m:mod_t) (sM sK:state) : state = match m with | Mod_None -> sK | Mod_ok -> va_update_ok sM sK | Mod_reg r -> va_update_reg r sM sK | Mod_vec v -> va_update_vec v sM sK | Mod_cr0 -> va_update_cr0 sM sK | Mod_xer -> va_update_xer sM sK | Mod_mem -> va_update_mem sM sK | Mod_mem_layout -> va_update_mem_layout sM sK | Mod_mem_heaplet n -> va_update_mem_heaplet n sM sK | Mod_stack -> va_update_stack sM sK | Mod_stackTaint -> va_update_stackTaint sM sK [@va_qattr]
false
true
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_state_mods (mods: mods_t) (sM sK: state) : state
[ "recursion" ]
Vale.PPC64LE.QuickCode.update_state_mods
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mods: Vale.PPC64LE.QuickCode.mods_t -> sM: Vale.PPC64LE.State.state -> sK: Vale.PPC64LE.State.state -> Vale.PPC64LE.State.state
{ "end_col": 67, "end_line": 72, "start_col": 2, "start_line": 70 }
Prims.Pure
val mod_eq (x y: mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y))
[ { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_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.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_eq (x y:mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) = match x with | Mod_None -> (match y with Mod_None -> true | _ -> false) | Mod_ok -> (match y with Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with Mod_xer -> true | _ -> false) | Mod_mem -> (match y with Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with Mod_stackTaint -> true | _ -> false)
val mod_eq (x y: mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) let mod_eq (x y: mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y)) =
false
null
false
match x with | Mod_None -> (match y with | Mod_None -> true | _ -> false) | Mod_ok -> (match y with | Mod_ok -> true | _ -> false) | Mod_reg rx -> (match y with | Mod_reg ry -> rx = ry | _ -> false) | Mod_vec vx -> (match y with | Mod_vec vy -> vx = vy | _ -> false) | Mod_cr0 -> (match y with | Mod_cr0 -> true | _ -> false) | Mod_xer -> (match y with | Mod_xer -> true | _ -> false) | Mod_mem -> (match y with | Mod_mem -> true | _ -> false) | Mod_mem_layout -> (match y with | Mod_mem_layout -> true | _ -> false) | Mod_mem_heaplet nx -> (match y with | Mod_mem_heaplet ny -> nx = ny | _ -> false) | Mod_stack -> (match y with | Mod_stack -> true | _ -> false) | Mod_stackTaint -> (match y with | Mod_stackTaint -> true | _ -> false)
{ "checked_file": "Vale.PPC64LE.QuickCode.fst.checked", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.QuickCode.fst" }
[]
[ "Vale.PPC64LE.QuickCode.mod_t", "Prims.bool", "Vale.PPC64LE.Machine_s.reg", "Prims.op_Equality", "Vale.PPC64LE.Machine_s.vec", "Vale.PPC64LE.Decls.heaplet_id", "Prims.l_True", "Prims.eq2" ]
[]
module Vale.PPC64LE.QuickCode open FStar.Mul open Vale.Def.Prop_s open Vale.PPC64LE.Machine_s open Vale.Arch.HeapImpl open Vale.PPC64LE.State open Vale.PPC64LE.Decls irreducible let qmodattr = () type mod_t = | Mod_None : mod_t | Mod_ok: mod_t | Mod_reg: reg -> mod_t | Mod_vec: vec -> mod_t | Mod_cr0: mod_t | Mod_xer: mod_t | Mod_mem: mod_t | Mod_mem_layout: mod_t | Mod_mem_heaplet: heaplet_id -> mod_t | Mod_stack: mod_t | Mod_stackTaint: mod_t unfold let mods_t = list mod_t unfold let va_mods_t = mods_t [@va_qattr] unfold let va_Mod_None = Mod_None [@va_qattr] unfold let va_Mod_ok = Mod_ok [@va_qattr] unfold let va_Mod_reg (r:reg) = Mod_reg r [@va_qattr] unfold let va_Mod_vec (v:vec) = Mod_vec v [@va_qattr] unfold let va_Mod_cr0 = Mod_cr0 [@va_qattr] unfold let va_Mod_xer = Mod_xer [@va_qattr] unfold let va_Mod_mem = Mod_mem [@va_qattr] unfold let va_Mod_mem_layout = Mod_mem_layout [@va_qattr] unfold let va_Mod_mem_heaplet (n:heaplet_id) = Mod_mem_heaplet n [@va_qattr] unfold let va_Mod_stack = Mod_stack [@va_qattr] unfold let va_Mod_stackTaint = Mod_stackTaint [@va_qattr "opaque_to_smt"]
false
false
Vale.PPC64LE.QuickCode.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_eq (x y: mod_t) : Pure bool (requires True) (ensures fun b -> b == (x = y))
[]
Vale.PPC64LE.QuickCode.mod_eq
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCode.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Vale.PPC64LE.QuickCode.mod_t -> y: Vale.PPC64LE.QuickCode.mod_t -> Prims.Pure Prims.bool
{ "end_col": 72, "end_line": 51, "start_col": 2, "start_line": 40 }
Prims.Tot
val gf128_power (h:poly) (n:nat) : poly
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let gf128_power h n = shift_gf128_key_1 (g_power h n)
val gf128_power (h:poly) (n:nat) : poly let gf128_power h n =
false
null
false
shift_gf128_key_1 (g_power h n)
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Vale.AES.GHash_BE.shift_gf128_key_1", "Vale.AES.GHash_BE.g_power" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = ()
false
true
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gf128_power (h:poly) (n:nat) : poly
[]
Vale.AES.GHash_BE.gf128_power
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 53, "end_line": 21, "start_col": 22, "start_line": 21 }
Prims.Tot
val shift_gf128_key_1 (h: poly) : poly
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h
val shift_gf128_key_1 (h: poly) : poly let shift_gf128_key_1 (h: poly) : poly =
false
null
false
shift_key_1 128 gf128_modulus_low_terms h
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Vale.AES.GF128.shift_key_1", "Vale.AES.GF128_s.gf128_modulus_low_terms" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options
false
true
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val shift_gf128_key_1 (h: poly) : poly
[]
Vale.AES.GHash_BE.shift_gf128_key_1
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
{ "end_col": 43, "end_line": 11, "start_col": 2, "start_line": 11 }
Prims.Tot
val g_power (a:poly) (n:nat) : poly
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1)
val g_power (a:poly) (n:nat) : poly let rec g_power (a: poly) (n: nat) : poly =
false
null
false
if n = 0 then zero else if n = 1 then a else a *~ g_power a (n - 1)
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_Equality", "Prims.int", "Vale.Math.Poly2_s.zero", "Prims.bool", "Vale.AES.GF128.op_Star_Tilde", "Vale.AES.GHash_BE.g_power", "Prims.op_Subtraction" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h
false
true
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val g_power (a:poly) (n:nat) : poly
[ "recursion" ]
Vale.AES.GHash_BE.g_power
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 24, "end_line": 16, "start_col": 2, "start_line": 14 }
Prims.Tot
val ghash_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p
val ghash_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly let rec ghash_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly =
false
null
false
let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_Equality", "Vale.AES.GF128.op_Star_Tilde", "Vale.Math.Poly2.op_Plus_Dot", "Prims.bool", "Vale.AES.GHash_BE.ghash_poly_unroll", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.AES.GHash_BE.g_power" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = ()
false
true
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly
[ "recursion" ]
Vale.AES.GHash_BE.ghash_poly_unroll
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> m: Prims.nat -> n: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 59, "end_line": 28, "start_col": 95, "start_line": 24 }
FStar.Pervasives.Lemma
val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) )
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; ()
val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let lemma_ghash_poly_of_unroll h prev data k m =
false
null
true
lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.unit", "Vale.AES.GHash_BE.lemma_ghash_unroll_poly_unroll", "Vale.AES.GHash_BE.lemma_ghash_poly_unroll" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; }
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) )
[]
Vale.AES.GHash_BE.lemma_ghash_poly_of_unroll
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> m: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree h < 128 /\ Vale.Math.Poly2_s.degree prev < 128) (ensures Vale.AES.GF128.mod_rev 128 (Vale.AES.GHash_BE.ghash_unroll h prev data k m 0) Vale.AES.GF128_s.gf128_modulus == Vale.AES.GHash_BE.ghash_poly h prev data k (k + m + 1))
{ "end_col": 4, "end_line": 199, "start_col": 2, "start_line": 197 }
FStar.Pervasives.Lemma
val lemma_ghash_incremental_poly (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (ghash_incremental h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) (fun_seq_quad32_BE_poly128 x) 0 (length x) )
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x)
val lemma_ghash_incremental_poly (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (ghash_incremental h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) (fun_seq_quad32_BE_poly128 x) 0 (length x) ) let lemma_ghash_incremental_poly h_BE y_prev x =
false
null
true
ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x)
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.GHash_BE.lemma_ghash_incremental_poly_rec", "Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128", "Prims.unit", "Vale.AES.GHash_BE.ghash_incremental_reveal" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; }
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_incremental_poly (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (ghash_incremental h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) (fun_seq_quad32_BE_poly128 x) 0 (length x) )
[]
Vale.AES.GHash_BE.lemma_ghash_incremental_poly
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h_BE: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Bits_s.of_quad32 (Vale.AES.GHash_BE.ghash_incremental h_BE y_prev x) == Vale.AES.GHash_BE.ghash_poly (Vale.Math.Poly2.Bits_s.of_quad32 h_BE) (Vale.Math.Poly2.Bits_s.of_quad32 y_prev) (Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 x) 0 (FStar.Seq.Base.length x))
{ "end_col": 78, "end_line": 238, "start_col": 2, "start_line": 237 }
FStar.Pervasives.Lemma
val lemma_swap128_mask_shift (a:poly) : Lemma (requires degree a < 128) (ensures ( let a_sw = swap a 64 in mask a 64 == shift a_sw (-64) /\ shift a (-64) == mask a_sw 64 ))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_swap128_mask_shift (a:poly) : Lemma (requires degree a < 128) (ensures ( let a_sw = swap a 64 in mask a 64 == shift a_sw (-64) /\ shift a (-64) == mask a_sw 64 )) = lemma_quad32_double_swap a; lemma_quad32_double a; lemma_quad32_double (swap a 64); lemma_mask_is_mod a 64; lemma_shift_is_div (swap a 64) 64; lemma_shift_is_div a 64; lemma_mask_is_mod (swap a 64) 64
val lemma_swap128_mask_shift (a:poly) : Lemma (requires degree a < 128) (ensures ( let a_sw = swap a 64 in mask a 64 == shift a_sw (-64) /\ shift a (-64) == mask a_sw 64 )) let lemma_swap128_mask_shift (a: poly) : Lemma (requires degree a < 128) (ensures (let a_sw = swap a 64 in mask a 64 == shift a_sw (- 64) /\ shift a (- 64) == mask a_sw 64)) =
false
null
true
lemma_quad32_double_swap a; lemma_quad32_double a; lemma_quad32_double (swap a 64); lemma_mask_is_mod a 64; lemma_shift_is_div (swap a 64) 64; lemma_shift_is_div a 64; lemma_mask_is_mod (swap a 64) 64
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Lemmas.lemma_mask_is_mod", "Vale.Math.Poly2.swap", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_shift_is_div", "Vale.Math.Poly2.Bits.lemma_quad32_double", "Vale.Math.Poly2.Words.lemma_quad32_double_swap", "Prims.b2t", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree", "Prims.squash", "Prims.l_and", "Prims.eq2", "Vale.Math.Poly2.mask", "Vale.Math.Poly2_s.shift", "Prims.op_Minus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); () let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); () let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) = if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then ( let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; () ) else () ; () #reset-options "--z3rlimit 30" let lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) // Precondition definitions = let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in // Postcondition definitions let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes' = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes' in lemma_hash_append2 h y_init y_mid y_final full_blocks final_padded; assert (y_final == ghash_incremental h y_init (full_blocks @| (create 1 final_padded))); //// Need to show that input_quads == full_blocks @| (create 1 final_padded) // First show that the inputs to input_quads corresponds pad_to_128_bits_be_quad32_to_bytes input num_bytes; assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice input 0 num_blocks)) @| pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16))); assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) @| padded_bytes); // Start deconstructing input_quads append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks)) padded_bytes; // Distribute the be_bytes_to_seq_quad32 assert (input_quads == (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks))) @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad32_to_bytes (slice input 0 num_blocks); assert (input_quads == full_blocks @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad_of_singleton final_padded padded_bytes; assert (input_quads == full_blocks @| (create 1 final_padded)); () let lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) = let q_in = append input_blocks (create 1 final) in let num_blocks = num_bytes / 16 in let full_blocks = slice q_in 0 num_blocks in assert (equal full_blocks input_blocks); lemma_ghash_incremental_bytes_extra_helper h y_init y_mid y_final q_in final final_padded num_bytes let lemma_div_distribute a b c = let ab = a +. b in let a' = a /. c in let b' = b /. c in let ab' = ab /. c in let a'' = a %. c in let b'' = b %. c in let ab'' = ab %. c in lemma_div_mod a c; lemma_div_mod b c; lemma_div_mod ab c; // (a +. b) == (a) +. (b) assert ((ab' *. c +. ab'') == (a' *. c +. a'') +. (b' *. c +. b'')); lemma_add_define_all (); lemma_equal (ab' *. c +. a' *. c +. b' *. c) (ab'' +. a'' +. b''); lemma_mul_distribute_left ab' a' c; lemma_mul_distribute_left (ab' +. a') b' c; assert ((ab' +. a' +. b') *. c == ab'' +. a'' +. b''); lemma_mul_smaller_is_zero (ab' +. a' +. b') c; assert (ab' +. a' +. b' == zero); lemma_zero_define (); lemma_equal ab' (a' +. b'); () let lemma_swap128_mask_shift (a:poly) : Lemma (requires degree a < 128) (ensures ( let a_sw = swap a 64 in mask a 64 == shift a_sw (-64) /\ shift a (-64) == mask a_sw 64 ))
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_swap128_mask_shift (a:poly) : Lemma (requires degree a < 128) (ensures ( let a_sw = swap a 64 in mask a 64 == shift a_sw (-64) /\ shift a (-64) == mask a_sw 64 ))
[]
Vale.AES.GHash_BE.lemma_swap128_mask_shift
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree a < 128) (ensures (let a_sw = Vale.Math.Poly2.swap a 64 in Vale.Math.Poly2.mask a 64 == Vale.Math.Poly2_s.shift a_sw (- 64) /\ Vale.Math.Poly2_s.shift a (- 64) == Vale.Math.Poly2.mask a_sw 64))
{ "end_col": 34, "end_line": 406, "start_col": 2, "start_line": 400 }
FStar.Pervasives.Lemma
val lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); ()
val lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) let lemma_ghash_incremental0_append (h y0 y1 y2: quad32) (s1 s2: seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) =
false
null
true
let s12 = s1 @| s2 in if length s1 = 0 then (assert (equal s12 s2)) else (if length s2 = 0 then (assert (equal s12 s1)) else (lemma_hash_append h y0 s1 s2)); ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.unit", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims._assert", "FStar.Seq.Base.equal", "Prims.bool", "Vale.AES.GHash_BE.lemma_hash_append", "FStar.Seq.Base.op_At_Bar", "Prims.l_and", "Prims.b2t", "Vale.AES.GHash_BE.ghash_incremental0", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2))
[]
Vale.AES.GHash_BE.lemma_ghash_incremental0_append
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y0: Vale.Def.Types_s.quad32 -> y1: Vale.Def.Types_s.quad32 -> y2: Vale.Def.Types_s.quad32 -> s1: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> s2: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires y1 = Vale.AES.GHash_BE.ghash_incremental0 h y0 s1 /\ y2 = Vale.AES.GHash_BE.ghash_incremental0 h y1 s2) (ensures y2 = Vale.AES.GHash_BE.ghash_incremental0 h y0 (s1 @| s2))
{ "end_col": 4, "end_line": 281, "start_col": 3, "start_line": 270 }
FStar.Pervasives.Lemma
val lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) : Lemma (requires y_mid = ghash_incremental0 h y_init s1 /\ y_final = ghash_incremental h y_mid (create 1 q)) (ensures y_final == ghash_incremental h y_init (s1 @| (create 1 q)))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); ()
val lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) : Lemma (requires y_mid = ghash_incremental0 h y_init s1 /\ y_final = ghash_incremental h y_mid (create 1 q)) (ensures y_final == ghash_incremental h y_init (s1 @| (create 1 q))) let lemma_hash_append2 (h y_init y_mid y_final: quad32) (s1: seq quad32) (q: quad32) =
false
null
true
let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then (assert (equal s12 qs)) else (lemma_hash_append h y_init s1 qs); ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.unit", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims._assert", "FStar.Seq.Base.equal", "Prims.bool", "Vale.AES.GHash_BE.lemma_hash_append", "FStar.Seq.Base.op_At_Bar", "FStar.Seq.Base.create" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); ()
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) : Lemma (requires y_mid = ghash_incremental0 h y_init s1 /\ y_final = ghash_incremental h y_mid (create 1 q)) (ensures y_final == ghash_incremental h y_init (s1 @| (create 1 q)))
[]
Vale.AES.GHash_BE.lemma_hash_append2
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y_init: Vale.Def.Types_s.quad32 -> y_mid: Vale.Def.Types_s.quad32 -> y_final: Vale.Def.Types_s.quad32 -> s1: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> q: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires y_mid = Vale.AES.GHash_BE.ghash_incremental0 h y_init s1 /\ y_final = Vale.AES.GHash_BE.ghash_incremental h y_mid (FStar.Seq.Base.create 1 q)) (ensures y_final == Vale.AES.GHash_BE.ghash_incremental h y_init (s1 @| FStar.Seq.Base.create 1 q))
{ "end_col": 4, "end_line": 292, "start_col": 3, "start_line": 284 }
FStar.Pervasives.Lemma
val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b])
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); ()
val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b]) let rec lemma_hash_append (h y_prev: quad32) (a b: ghash_plain_BE) =
false
null
true
ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert (all_but_last ab == append a (all_but_last b)); ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma", "" ]
[ "Vale.Def.Types_s.quad32", "Vale.AES.GHash_BE_s.ghash_plain_BE", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.seq", "Vale.Lib.Seqs_s.all_but_last", "FStar.Seq.Base.append", "Vale.Lib.Seqs.lemma_all_but_last_append", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Vale.Lib.Seqs.lemma_slice_first_exactly_in_append", "Prims.bool", "Vale.AES.GHash_BE.lemma_hash_append", "FStar.Seq.Properties.last", "Vale.AES.GHash_BE.ghash_incremental_reveal" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b])
[ "recursion" ]
Vale.AES.GHash_BE.lemma_hash_append
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> a: Vale.AES.GHash_BE_s.ghash_plain_BE -> b: Vale.AES.GHash_BE_s.ghash_plain_BE -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash_BE.ghash_incremental h y_prev (FStar.Seq.Base.append a b) == (let y_a = Vale.AES.GHash_BE.ghash_incremental h y_prev a in Vale.AES.GHash_BE.ghash_incremental h y_a b)) (decreases FStar.Seq.Base.length b)
{ "end_col": 4, "end_line": 264, "start_col": 2, "start_line": 253 }
FStar.Pervasives.Lemma
val lemma_div_distribute (a b c:poly) : Lemma (requires degree c >= 0) (ensures (a +. b) /. c == (a /. c) +. (b /. c))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_div_distribute a b c = let ab = a +. b in let a' = a /. c in let b' = b /. c in let ab' = ab /. c in let a'' = a %. c in let b'' = b %. c in let ab'' = ab %. c in lemma_div_mod a c; lemma_div_mod b c; lemma_div_mod ab c; // (a +. b) == (a) +. (b) assert ((ab' *. c +. ab'') == (a' *. c +. a'') +. (b' *. c +. b'')); lemma_add_define_all (); lemma_equal (ab' *. c +. a' *. c +. b' *. c) (ab'' +. a'' +. b''); lemma_mul_distribute_left ab' a' c; lemma_mul_distribute_left (ab' +. a') b' c; assert ((ab' +. a' +. b') *. c == ab'' +. a'' +. b''); lemma_mul_smaller_is_zero (ab' +. a' +. b') c; assert (ab' +. a' +. b' == zero); lemma_zero_define (); lemma_equal ab' (a' +. b'); ()
val lemma_div_distribute (a b c:poly) : Lemma (requires degree c >= 0) (ensures (a +. b) /. c == (a /. c) +. (b /. c)) let lemma_div_distribute a b c =
false
null
true
let ab = a +. b in let a' = a /. c in let b' = b /. c in let ab' = ab /. c in let a'' = a %. c in let b'' = b %. c in let ab'' = ab %. c in lemma_div_mod a c; lemma_div_mod b c; lemma_div_mod ab c; assert ((ab' *. c +. ab'') == (a' *. c +. a'') +. (b' *. c +. b'')); lemma_add_define_all (); lemma_equal (ab' *. c +. a' *. c +. b' *. c) (ab'' +. a'' +. b''); lemma_mul_distribute_left ab' a' c; lemma_mul_distribute_left (ab' +. a') b' c; assert ((ab' +. a' +. b') *. c == ab'' +. a'' +. b''); lemma_mul_smaller_is_zero (ab' +. a' +. b') c; assert (ab' +. a' +. b' == zero); lemma_zero_define (); lemma_equal ab' (a' +. b'); ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.unit", "Vale.Math.Poly2.lemma_equal", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2.Lemmas.lemma_zero_define", "Prims._assert", "Prims.eq2", "Vale.Math.Poly2_s.zero", "Vale.Math.Poly2.Lemmas.lemma_mul_smaller_is_zero", "Vale.Math.Poly2.op_Star_Dot", "Vale.Math.Poly2.Lemmas.lemma_mul_distribute_left", "Vale.Math.Poly2.Lemmas.lemma_add_define_all", "Vale.Math.Poly2.lemma_div_mod", "Vale.Math.Poly2.op_Percent_Dot", "Vale.Math.Poly2.op_Slash_Dot" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); () let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); () let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) = if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then ( let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; () ) else () ; () #reset-options "--z3rlimit 30" let lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) // Precondition definitions = let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in // Postcondition definitions let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes' = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes' in lemma_hash_append2 h y_init y_mid y_final full_blocks final_padded; assert (y_final == ghash_incremental h y_init (full_blocks @| (create 1 final_padded))); //// Need to show that input_quads == full_blocks @| (create 1 final_padded) // First show that the inputs to input_quads corresponds pad_to_128_bits_be_quad32_to_bytes input num_bytes; assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice input 0 num_blocks)) @| pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16))); assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) @| padded_bytes); // Start deconstructing input_quads append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks)) padded_bytes; // Distribute the be_bytes_to_seq_quad32 assert (input_quads == (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks))) @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad32_to_bytes (slice input 0 num_blocks); assert (input_quads == full_blocks @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad_of_singleton final_padded padded_bytes; assert (input_quads == full_blocks @| (create 1 final_padded)); () let lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) = let q_in = append input_blocks (create 1 final) in let num_blocks = num_bytes / 16 in let full_blocks = slice q_in 0 num_blocks in assert (equal full_blocks input_blocks); lemma_ghash_incremental_bytes_extra_helper h y_init y_mid y_final q_in final final_padded num_bytes
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_div_distribute (a b c:poly) : Lemma (requires degree c >= 0) (ensures (a +. b) /. c == (a /. c) +. (b /. c))
[]
Vale.AES.GHash_BE.lemma_div_distribute
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> c: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree c >= 0) (ensures (a +. b) /. c == a /. c +. b /. c)
{ "end_col": 4, "end_line": 390, "start_col": 32, "start_line": 368 }
FStar.Pervasives.Lemma
val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n)
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1)
val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) let lemma_ghash_unroll_back_forward (h prev: poly) (data: (int -> poly128)) (k: int) (n: nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) =
false
null
true
lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1)
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_GreaterThan", "Vale.AES.GHash_BE.lemma_ghash_unroll_back_forward_rec", "Prims.op_Subtraction", "Prims.bool", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_add_all", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.AES.GHash_BE.ghash_unroll", "Vale.AES.GHash_BE.ghash_unroll_back", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n)
[]
Vale.AES.GHash_BE.lemma_ghash_unroll_back_forward
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash_BE.ghash_unroll h prev data k n 0 == Vale.AES.GHash_BE.ghash_unroll_back h prev data k (n + 1) n)
{ "end_col": 75, "end_line": 47, "start_col": 2, "start_line": 46 }
FStar.Pervasives.Lemma
val lemma_gf128_mul_rev_mod_rev (a h: poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus)
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); }
val lemma_gf128_mul_rev_mod_rev (a h: poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) let lemma_gf128_mul_rev_mod_rev (a h: poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) =
false
null
true
let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc ( == ) { rev ((rev a *. rev h) %. g); ( == ) { lemma_mod_mul_mod_right (rev a) (rev h) g } rev ((rev a *. (rev h %. g)) %. g); ( == ) { lemma_shift_key_1 128 gf128_modulus_low_terms h } rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); ( == ) { lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g } rev ((rev a *. (shift (rev h1) 1)) %. g); ( == ) { lemma_shift_is_mul (rev h1) 1 } rev ((rev a *. (rev h1 *. monomial 1)) %. g); ( == ) { lemma_mul_all () } rev (((rev a *. rev h1) *. monomial 1) %. g); ( == ) { lemma_shift_is_mul (rev a *. rev h1) 1 } rev (shift (rev a *. rev h1) 1 %. g); ( == ) { lemma_mul_reverse_shift_1 a h1 127 } rev (reverse (a *. h1) 255 %. g); }
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "FStar.Calc.calc_finish", "Prims.eq2", "Vale.Math.Poly2.op_Percent_Dot", "Vale.Math.Poly2.op_Star_Dot", "Vale.Math.Poly2_s.reverse", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Vale.Math.Poly2_s.shift", "Vale.Math.Poly2_s.monomial", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Vale.Math.Poly2.Lemmas.lemma_mod_mul_mod_right", "Prims.squash", "Vale.AES.GF128.lemma_shift_key_1", "Vale.AES.GF128_s.gf128_modulus_low_terms", "Vale.Math.Poly2.lemma_shift_is_mul", "Vale.Math.Poly2.Lemmas.lemma_mul_all", "Vale.Math.Poly2.Lemmas.lemma_mul_reverse_shift_1", "Vale.AES.GF128.lemma_gf128_degree", "Vale.AES.GF128_s.gf128_modulus", "Vale.AES.GHash_BE.shift_gf128_key_1", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree", "Vale.AES.GF128.gf128_mul_rev", "Vale.AES.GF128.mod_rev", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_gf128_mul_rev_mod_rev (a h: poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus)
[]
Vale.AES.GHash_BE.lemma_gf128_mul_rev_mod_rev
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Vale.Math.Poly2_s.poly -> h: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree a < 128 /\ Vale.Math.Poly2_s.degree h < 128) (ensures Vale.AES.GF128.gf128_mul_rev a h == Vale.AES.GF128.mod_rev 128 (a *. Vale.AES.GHash_BE.shift_gf128_key_1 h) Vale.AES.GF128_s.gf128_modulus)
{ "end_col": 3, "end_line": 74, "start_col": 3, "start_line": 52 }
FStar.Pervasives.Lemma
val lemma_ghash_poly_unroll (h0 prev: poly) (data: (int -> poly128)) (k: int) (m: nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1))
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); }
val lemma_ghash_poly_unroll (h0 prev: poly) (data: (int -> poly128)) (k: int) (m: nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) let rec lemma_ghash_poly_unroll (h0 prev: poly) (data: (int -> poly128)) (k: int) (m: nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) =
false
null
true
let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc ( == ) { ghash_poly_unroll h0 prev data k m 0; ( == ) { () } (prev +. d) *~ p1; ( == ) { () } (ghash0 +. d) *~ h0; ( == ) { () } ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc ( == ) { ghash_poly_unroll h0 prev data k m 0; ( == ) { () } unroll1 +. d *~ p1; ( == ) { calc ( == ) { unroll1; ( == ) { lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0 } unroll0 *~ h0; ( == ) { lemma_ghash_poly_unroll h0 prev data k (m - 1) } ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; ( == ) { lemma_gf128_mul_rev_distribute_left ghash0 d h0 } (ghash0 +. d) *~ h0; ( == ) { () } ghash_poly h0 prev data k (k + m + 1); }
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_Equality", "FStar.Calc.calc_finish", "Prims.eq2", "Vale.AES.GHash_BE.ghash_poly_unroll", "Vale.AES.GHash_BE.ghash_poly", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Vale.AES.GF128.op_Star_Tilde", "Vale.Math.Poly2.op_Plus_Dot", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Prims.bool", "Vale.AES.GHash_BE.lemma_ghash_poly_unroll_n", "Prims.op_Subtraction", "Vale.AES.GHash_BE.lemma_ghash_poly_unroll", "Vale.AES.GF128.lemma_gf128_mul_rev_distribute_left", "Vale.AES.GHash_BE.g_power", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_poly_unroll (h0 prev: poly) (data: (int -> poly128)) (k: int) (m: nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1))
[ "recursion" ]
Vale.AES.GHash_BE.lemma_ghash_poly_unroll
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> m: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree h0 < 128 /\ Vale.Math.Poly2_s.degree prev < 128) (ensures Vale.AES.GHash_BE.ghash_poly_unroll h0 prev data k m 0 == Vale.AES.GHash_BE.ghash_poly h0 prev data k (k + m + 1))
{ "end_col": 5, "end_line": 155, "start_col": 3, "start_line": 120 }
FStar.Pervasives.Lemma
val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_BE h x) (decreases %[length x])
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x)
val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_BE h x) (decreases %[length x]) let rec ghash_incremental_to_ghash (h: quad32) (x: seq quad32) =
false
null
true
ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x)
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma", "" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GHash_BE.ghash_incremental_to_ghash", "Vale.Lib.Seqs_s.all_but_last", "Prims.unit", "Vale.AES.GHash_BE_s.ghash_BE_reveal", "Vale.AES.GHash_BE.ghash_incremental_reveal" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_BE h x) (decreases %[length x])
[ "recursion" ]
Vale.AES.GHash_BE.ghash_incremental_to_ghash
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length x > 0) (ensures Vale.AES.GHash_BE.ghash_incremental h (Vale.Def.Words_s.Mkfour 0 0 0 0) x == Vale.AES.GHash_BE_s.ghash_BE h x) (decreases FStar.Seq.Base.length x)
{ "end_col": 52, "end_line": 249, "start_col": 2, "start_line": 246 }
FStar.Pervasives.Lemma
val lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) = let q_in = append input_blocks (create 1 final) in let num_blocks = num_bytes / 16 in let full_blocks = slice q_in 0 num_blocks in assert (equal full_blocks input_blocks); lemma_ghash_incremental_bytes_extra_helper h y_init y_mid y_final q_in final final_padded num_bytes
val lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) let lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final: quad32) (input_blocks: seq quad32) (final final_padded: quad32) (num_bytes: nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) =
false
null
true
let q_in = append input_blocks (create 1 final) in let num_blocks = num_bytes / 16 in let full_blocks = slice q_in 0 num_blocks in assert (equal full_blocks input_blocks); lemma_ghash_incremental_bytes_extra_helper h y_init y_mid y_final q_in final final_padded num_bytes
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.nat", "Vale.AES.GHash_BE.lemma_ghash_incremental_bytes_extra_helper", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.int", "Prims.op_Division", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Prims.op_disEquality", "Prims.op_Modulus", "Prims.op_Equality", "Vale.AES.GHash_BE.ghash_incremental0", "Prims.eq2", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.be_bytes_to_quad32", "Vale.AES.GHash_BE.ghash_incremental", "Vale.Def.Words_s.nat8", "Vale.AES.GCTR_BE_s.pad_to_128_bits", "Vale.Arch.Types.be_quad32_to_bytes", "Prims.squash", "Vale.Def.Types_s.be_bytes_to_seq_quad32", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Types_s.nat32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); () let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); () let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) = if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then ( let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; () ) else () ; () #reset-options "--z3rlimit 30" let lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) // Precondition definitions = let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in // Postcondition definitions let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes' = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes' in lemma_hash_append2 h y_init y_mid y_final full_blocks final_padded; assert (y_final == ghash_incremental h y_init (full_blocks @| (create 1 final_padded))); //// Need to show that input_quads == full_blocks @| (create 1 final_padded) // First show that the inputs to input_quads corresponds pad_to_128_bits_be_quad32_to_bytes input num_bytes; assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice input 0 num_blocks)) @| pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16))); assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) @| padded_bytes); // Start deconstructing input_quads append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks)) padded_bytes; // Distribute the be_bytes_to_seq_quad32 assert (input_quads == (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks))) @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad32_to_bytes (slice input 0 num_blocks); assert (input_quads == full_blocks @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad_of_singleton final_padded padded_bytes; assert (input_quads == full_blocks @| (create 1 final_padded)); () let lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads))
[]
Vale.AES.GHash_BE.lemma_ghash_incremental_bytes_extra_helper_alt
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y_init: Vale.Def.Types_s.quad32 -> y_mid: Vale.Def.Types_s.quad32 -> y_final: Vale.Def.Types_s.quad32 -> input_blocks: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> final: Vale.Def.Types_s.quad32 -> final_padded: Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length input_blocks + 16 /\ 16 * FStar.Seq.Base.length input_blocks < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = Vale.AES.GHash_BE.ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes final) 0 (num_bytes % 16)) in FStar.Seq.Base.length padded_bytes == 16 /\ final_padded == Vale.Def.Types_s.be_bytes_to_quad32 padded_bytes /\ y_final = Vale.AES.GHash_BE.ghash_incremental h y_mid (FStar.Seq.Base.create 1 final_padded))) (ensures (let input_bytes = FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.append input_blocks (FStar.Seq.Base.create 1 final)))) 0 num_bytes in let padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in let input_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 padded_bytes in FStar.Seq.Base.length padded_bytes == 16 * FStar.Seq.Base.length input_quads /\ y_final == Vale.AES.GHash_BE.ghash_incremental h y_init input_quads))
{ "end_col": 101, "end_line": 366, "start_col": 3, "start_line": 361 }
FStar.Pervasives.Lemma
val lemma_ghash_unroll_back_forward_rec (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m)
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1)
val lemma_ghash_unroll_back_forward_rec (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) let rec lemma_ghash_unroll_back_forward_rec (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) =
false
null
true
lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1)
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_GreaterThan", "Vale.AES.GHash_BE.lemma_ghash_unroll_back_forward_rec", "Prims.op_Subtraction", "Prims.bool", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_add_all", "Prims.b2t", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "Vale.AES.GHash_BE.ghash_unroll", "Vale.Math.Poly2.op_Plus_Dot", "Prims.op_Addition", "Vale.AES.GHash_BE.ghash_unroll_back", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m)
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_unroll_back_forward_rec (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m)
[ "recursion" ]
Vale.AES.GHash_BE.lemma_ghash_unroll_back_forward_rec
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> n: Prims.nat -> m: Prims.nat -> FStar.Pervasives.Lemma (requires m < n) (ensures Vale.AES.GHash_BE.ghash_unroll h prev data k n 0 == Vale.AES.GHash_BE.ghash_unroll h prev data k (n - 1 - m) (m + 1) +. Vale.AES.GHash_BE.ghash_unroll_back h prev data k (n + 1) m)
{ "end_col": 75, "end_line": 41, "start_col": 2, "start_line": 40 }
FStar.Pervasives.Lemma
val ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) = if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then ( let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; () ) else () ; ()
val ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) let ghash_incremental_bytes_pure_no_extra (old_io io h: quad32) (in_quads: seq quad32) (num_bytes: nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) =
false
null
true
if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then (let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; ()); ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat64", "Prims.unit", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.op_Division", "Prims.op_Modulus", "Prims.op_GreaterThan", "Vale.Arch.Types.be_bytes_to_seq_quad32_to_bytes", "Vale.AES.GCM_helpers_BE.no_extra_bytes_helper", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.slice", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Prims.bool", "Prims.b2t", "Vale.AES.GHash_BE.ghash_incremental0", "Prims.squash", "Prims.l_imp", "Prims.l_and", "Prims.eq2", "Vale.AES.GHash_BE.ghash_incremental", "Vale.Def.Types_s.be_bytes_to_seq_quad32", "Vale.AES.GCTR_BE_s.pad_to_128_bits", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Types_s.nat32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); () let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); () let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads))
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads))
[]
Vale.AES.GHash_BE.ghash_incremental_bytes_pure_no_extra
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
old_io: Vale.Def.Types_s.quad32 -> io: Vale.Def.Types_s.quad32 -> h: Vale.Def.Types_s.quad32 -> in_quads: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Vale.Def.Types_s.nat64 -> FStar.Pervasives.Lemma (requires io = Vale.AES.GHash_BE.ghash_incremental0 h old_io in_quads) (ensures FStar.Seq.Base.length in_quads == num_bytes / 16 /\ num_bytes % 16 == 0 ==> (let input_bytes = FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in let input_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> FStar.Seq.Base.length input_quads > 0 /\ io == Vale.AES.GHash_BE.ghash_incremental h old_io input_quads))
{ "end_col": 4, "end_line": 311, "start_col": 2, "start_line": 304 }
FStar.Pervasives.Lemma
val lemma_ghash_unroll_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n)
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; }
val lemma_ghash_unroll_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n) let rec lemma_ghash_unroll_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n) =
false
null
true
let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc ( == ) { mod_rev 128 (ghash_unroll h prev data k m n) g; ( == ) { () } mod_rev 128 ((prev +. d) *. sp) g; ( == ) { lemma_gf128_mul_rev_mod_rev (prev +. d) p } (prev +. d) *~ p; ( == ) { () } ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc ( == ) { mod_rev 128 (ghash_unroll h prev data k m n) g; ( == ) { () } mod_rev 128 (unroll1 +. d *. sp) g; ( == ) { lemma_add_mod_rev 128 unroll1 (d *. sp) g } mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; ( == ) { lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1) } ghash0 +. mod_rev 128 (d *. sp) g; ( == ) { lemma_gf128_mul_rev_mod_rev d p } ghash0 +. d *~ p; ( == ) { () } ghash_poly_unroll h prev data k m n; }
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_Equality", "FStar.Calc.calc_finish", "Prims.eq2", "Vale.AES.GF128.mod_rev", "Vale.AES.GHash_BE.ghash_unroll", "Vale.AES.GHash_BE.ghash_poly_unroll", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Vale.AES.GF128.op_Star_Tilde", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2.op_Star_Dot", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Vale.AES.GHash_BE.lemma_gf128_mul_rev_mod_rev", "Prims.bool", "Vale.AES.GF128.lemma_add_mod_rev", "Vale.AES.GHash_BE.lemma_ghash_unroll_poly_unroll", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.AES.GF128.lemma_gf128_degree", "Vale.AES.GHash_BE.shift_gf128_key_1", "Vale.AES.GHash_BE.g_power", "Vale.AES.GF128_s.gf128_modulus", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_unroll_poly_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n)
[ "recursion" ]
Vale.AES.GHash_BE.lemma_ghash_unroll_poly_unroll
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> m: Prims.nat -> n: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree h < 128 /\ Vale.Math.Poly2_s.degree prev < 128) (ensures Vale.AES.GF128.mod_rev 128 (Vale.AES.GHash_BE.ghash_unroll h prev data k m n) Vale.AES.GF128_s.gf128_modulus == Vale.AES.GHash_BE.ghash_poly_unroll h prev data k m n)
{ "end_col": 5, "end_line": 194, "start_col": 3, "start_line": 163 }
FStar.Pervasives.Lemma
val lemma_gf128_constant_shift_rev (_:unit) : Lemma (mask (of_quad32 (Mkfour 0 0xc2000000 0 0)) 64 == reverse gf128_low_shift 63 /\ shift (of_quad32 (Mkfour 0 0xc2000000 0 0)) (-64) == zero)
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_gf128_constant_shift_rev () = let n0:nat32 = 0 in let n1:nat32 = 0xc2000000 in let n2:nat32 = 0 in let n3:nat32 = 0 in let r3 = gf128_low_shift in calc (==) { of_quad32 (Mkfour n0 n1 n2 n3); == { calc (==) { Mkfour n0 n1 n2 n3; == {lemma_quad32_of_nat32s n0 n1 n2 n3} to_quad32 (poly128_of_nat32s n0 n1 n2 n3); == { lemma_bitwise_all (); lemma_to_nat 32 (reverse r3 31) n1; lemma_equal (poly128_of_nat32s n0 n1 n2 n3) (reverse r3 63) } to_quad32 (reverse r3 63); } } of_quad32 (to_quad32 (reverse r3 63)); == {lemma_of_to_quad32 (reverse r3 63)} reverse r3 63; }; lemma_bitwise_all (); lemma_split_define (reverse gf128_low_shift 63) 64; lemma_equal (mask (reverse gf128_low_shift 63) 64) (reverse gf128_low_shift 63); lemma_equal (shift (reverse gf128_low_shift 63) (-64)) zero
val lemma_gf128_constant_shift_rev (_:unit) : Lemma (mask (of_quad32 (Mkfour 0 0xc2000000 0 0)) 64 == reverse gf128_low_shift 63 /\ shift (of_quad32 (Mkfour 0 0xc2000000 0 0)) (-64) == zero) let lemma_gf128_constant_shift_rev () =
false
null
true
let n0:nat32 = 0 in let n1:nat32 = 0xc2000000 in let n2:nat32 = 0 in let n3:nat32 = 0 in let r3 = gf128_low_shift in calc ( == ) { of_quad32 (Mkfour n0 n1 n2 n3); ( == ) { calc ( == ) { Mkfour n0 n1 n2 n3; ( == ) { lemma_quad32_of_nat32s n0 n1 n2 n3 } to_quad32 (poly128_of_nat32s n0 n1 n2 n3); ( == ) { (lemma_bitwise_all (); lemma_to_nat 32 (reverse r3 31) n1; lemma_equal (poly128_of_nat32s n0 n1 n2 n3) (reverse r3 63)) } to_quad32 (reverse r3 63); } } of_quad32 (to_quad32 (reverse r3 63)); ( == ) { lemma_of_to_quad32 (reverse r3 63) } reverse r3 63; }; lemma_bitwise_all (); lemma_split_define (reverse gf128_low_shift 63) 64; lemma_equal (mask (reverse gf128_low_shift 63) 64) (reverse gf128_low_shift 63); lemma_equal (shift (reverse gf128_low_shift 63) (- 64)) zero
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Prims.unit", "Vale.Math.Poly2.lemma_equal", "Vale.Math.Poly2_s.shift", "Vale.Math.Poly2_s.reverse", "Vale.AES.GF128.gf128_low_shift", "Prims.op_Minus", "Vale.Math.Poly2_s.zero", "Vale.Math.Poly2.mask", "Vale.Math.Poly2.Lemmas.lemma_split_define", "Vale.Math.Poly2.Lemmas.lemma_bitwise_all", "FStar.Calc.calc_finish", "Vale.Math.Poly2_s.poly", "Prims.eq2", "Vale.Math.Poly2.Bits_s.of_quad32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Vale.Math.Poly2.Bits_s.to_quad32", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "Vale.Math.Poly2.Bits.poly128_of_nat32s", "Vale.Math.Poly2.Bits.lemma_quad32_of_nat32s", "Prims.squash", "Vale.Math.Poly2.Bits.lemma_to_nat", "Vale.Math.Poly2.Bits.lemma_of_to_quad32" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); () let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); () let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) = if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then ( let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; () ) else () ; () #reset-options "--z3rlimit 30" let lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) // Precondition definitions = let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in // Postcondition definitions let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes' = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes' in lemma_hash_append2 h y_init y_mid y_final full_blocks final_padded; assert (y_final == ghash_incremental h y_init (full_blocks @| (create 1 final_padded))); //// Need to show that input_quads == full_blocks @| (create 1 final_padded) // First show that the inputs to input_quads corresponds pad_to_128_bits_be_quad32_to_bytes input num_bytes; assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice input 0 num_blocks)) @| pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16))); assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) @| padded_bytes); // Start deconstructing input_quads append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks)) padded_bytes; // Distribute the be_bytes_to_seq_quad32 assert (input_quads == (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks))) @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad32_to_bytes (slice input 0 num_blocks); assert (input_quads == full_blocks @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad_of_singleton final_padded padded_bytes; assert (input_quads == full_blocks @| (create 1 final_padded)); () let lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) = let q_in = append input_blocks (create 1 final) in let num_blocks = num_bytes / 16 in let full_blocks = slice q_in 0 num_blocks in assert (equal full_blocks input_blocks); lemma_ghash_incremental_bytes_extra_helper h y_init y_mid y_final q_in final final_padded num_bytes let lemma_div_distribute a b c = let ab = a +. b in let a' = a /. c in let b' = b /. c in let ab' = ab /. c in let a'' = a %. c in let b'' = b %. c in let ab'' = ab %. c in lemma_div_mod a c; lemma_div_mod b c; lemma_div_mod ab c; // (a +. b) == (a) +. (b) assert ((ab' *. c +. ab'') == (a' *. c +. a'') +. (b' *. c +. b'')); lemma_add_define_all (); lemma_equal (ab' *. c +. a' *. c +. b' *. c) (ab'' +. a'' +. b''); lemma_mul_distribute_left ab' a' c; lemma_mul_distribute_left (ab' +. a') b' c; assert ((ab' +. a' +. b') *. c == ab'' +. a'' +. b''); lemma_mul_smaller_is_zero (ab' +. a' +. b') c; assert (ab' +. a' +. b' == zero); lemma_zero_define (); lemma_equal ab' (a' +. b'); () let lemma_swap128_mask_shift (a:poly) : Lemma (requires degree a < 128) (ensures ( let a_sw = swap a 64 in mask a 64 == shift a_sw (-64) /\ shift a (-64) == mask a_sw 64 )) = lemma_quad32_double_swap a; lemma_quad32_double a; lemma_quad32_double (swap a 64); lemma_mask_is_mod a 64; lemma_shift_is_div (swap a 64) 64; lemma_shift_is_div a 64; lemma_mask_is_mod (swap a 64) 64
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_gf128_constant_shift_rev (_:unit) : Lemma (mask (of_quad32 (Mkfour 0 0xc2000000 0 0)) 64 == reverse gf128_low_shift 63 /\ shift (of_quad32 (Mkfour 0 0xc2000000 0 0)) (-64) == zero)
[]
Vale.AES.GHash_BE.lemma_gf128_constant_shift_rev
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.mask (Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Words_s.Mkfour 0 0xc2000000 0 0)) 64 == Vale.Math.Poly2_s.reverse Vale.AES.GF128.gf128_low_shift 63 /\ Vale.Math.Poly2_s.shift (Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Words_s.Mkfour 0 0xc2000000 0 0)) (- 64) == Vale.Math.Poly2_s.zero)
{ "end_col": 61, "end_line": 437, "start_col": 3, "start_line": 409 }
FStar.Pervasives.Lemma
val lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length input /\ 16 * (length input - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ //4096 * num_bytes < pow2_32 /\ (let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in y_mid = ghash_incremental0 h y_init full_blocks /\ final == index input num_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded))))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) // Precondition definitions = let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in // Postcondition definitions let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes' = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes' in lemma_hash_append2 h y_init y_mid y_final full_blocks final_padded; assert (y_final == ghash_incremental h y_init (full_blocks @| (create 1 final_padded))); //// Need to show that input_quads == full_blocks @| (create 1 final_padded) // First show that the inputs to input_quads corresponds pad_to_128_bits_be_quad32_to_bytes input num_bytes; assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice input 0 num_blocks)) @| pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16))); assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) @| padded_bytes); // Start deconstructing input_quads append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks)) padded_bytes; // Distribute the be_bytes_to_seq_quad32 assert (input_quads == (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks))) @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad32_to_bytes (slice input 0 num_blocks); assert (input_quads == full_blocks @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad_of_singleton final_padded padded_bytes; assert (input_quads == full_blocks @| (create 1 final_padded)); ()
val lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length input /\ 16 * (length input - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ //4096 * num_bytes < pow2_32 /\ (let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in y_mid = ghash_incremental0 h y_init full_blocks /\ final == index input num_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded))))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) let lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final: quad32) (input: seq quad32) (final final_padded: quad32) (num_bytes: nat) =
false
null
true
let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes' = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes' in lemma_hash_append2 h y_init y_mid y_final full_blocks final_padded; assert (y_final == ghash_incremental h y_init (full_blocks @| (create 1 final_padded))); pad_to_128_bits_be_quad32_to_bytes input num_bytes; assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice input 0 num_blocks)) @| pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16))); assert (padded_bytes' == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) @| padded_bytes); append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks) ) padded_bytes; assert (input_quads == (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_blocks))) @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad32_to_bytes (slice input 0 num_blocks); assert (input_quads == full_blocks @| (be_bytes_to_seq_quad32 padded_bytes)); be_bytes_to_seq_quad_of_singleton final_padded padded_bytes; assert (input_quads == full_blocks @| (create 1 final_padded)); ()
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.nat", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.op_At_Bar", "FStar.Seq.Base.create", "Vale.Arch.Types.be_bytes_to_seq_quad_of_singleton", "Vale.Def.Types_s.be_bytes_to_seq_quad32", "Vale.Arch.Types.be_bytes_to_seq_quad32_to_bytes", "FStar.Seq.Base.slice", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Types_s.nat32", "Vale.Arch.Types.append_distributes_be_bytes_to_seq_quad32", "Vale.Def.Types_s.nat8", "Vale.Def.Words_s.nat8", "Vale.AES.GCTR_BE_s.pad_to_128_bits", "Vale.Arch.Types.be_quad32_to_bytes", "Prims.op_Modulus", "Vale.AES.GCM_helpers_BE.pad_to_128_bits_be_quad32_to_bytes", "Vale.AES.GHash_BE.ghash_incremental", "Vale.AES.GHash_BE.lemma_hash_append2", "Prims.int", "Prims.op_Division" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; } let lemma_ghash_incremental_poly h_BE y_prev x = ghash_incremental_reveal (); lemma_ghash_incremental_poly_rec h_BE y_prev x (fun_seq_quad32_BE_poly128 x) let lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) = () let rec ghash_incremental_to_ghash (h:quad32) (x:seq quad32) = ghash_incremental_reveal (); ghash_BE_reveal (); if length x = 1 then () else ghash_incremental_to_ghash h (all_but_last x) let rec lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) = ghash_incremental_reveal (); let ab = append a b in assert (last ab == last b); if length b = 1 then (lemma_slice_first_exactly_in_append a b; assert (all_but_last ab == a); ()) else lemma_hash_append h y_prev a (all_but_last b); lemma_all_but_last_append a b; assert(all_but_last ab == append a (all_but_last b)); () let lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) = let s12 = s1 @| s2 in if length s1 = 0 then ( assert (equal s12 s2) ) else ( if length s2 = 0 then ( assert (equal s12 s1) ) else ( lemma_hash_append h y0 s1 s2 ) ); () let lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) = let qs = create 1 q in let s12 = s1 @| qs in if length s1 = 0 then ( assert(equal s12 qs) ) else ( lemma_hash_append h y_init s1 qs ); () let ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) = if length in_quads = (num_bytes / 16) && num_bytes % 16 = 0 && num_bytes > 0 then ( let input_bytes = slice (le_seq_quad32_to_bytes in_quads) 0 num_bytes in no_extra_bytes_helper in_quads num_bytes; be_bytes_to_seq_quad32_to_bytes in_quads; () ) else () ; () #reset-options "--z3rlimit 30"
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length input /\ 16 * (length input - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ //4096 * num_bytes < pow2_32 /\ (let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in y_mid = ghash_incremental0 h y_init full_blocks /\ final == index input num_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded))))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads))
[]
Vale.AES.GHash_BE.lemma_ghash_incremental_bytes_extra_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y_init: Vale.Def.Types_s.quad32 -> y_mid: Vale.Def.Types_s.quad32 -> y_final: Vale.Def.Types_s.quad32 -> input: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> final: Vale.Def.Types_s.quad32 -> final_padded: Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length input /\ 16 * (FStar.Seq.Base.length input - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ (let num_blocks = num_bytes / 16 in let full_blocks = FStar.Seq.Base.slice input 0 num_blocks in y_mid = Vale.AES.GHash_BE.ghash_incremental0 h y_init full_blocks /\ final == FStar.Seq.Base.index input num_blocks /\ (let padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes final) 0 (num_bytes % 16)) in FStar.Seq.Base.length padded_bytes == 16 /\ final_padded == Vale.Def.Types_s.be_bytes_to_quad32 padded_bytes /\ y_final = Vale.AES.GHash_BE.ghash_incremental h y_mid (FStar.Seq.Base.create 1 final_padded)))) (ensures (let input_bytes = FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in let input_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 padded_bytes in FStar.Seq.Base.length padded_bytes == 16 * FStar.Seq.Base.length input_quads /\ y_final == Vale.AES.GHash_BE.ghash_incremental h y_init input_quads))
{ "end_col": 4, "end_line": 343, "start_col": 3, "start_line": 315 }
FStar.Pervasives.Lemma
val lemma_ghash_incremental_poly_rec (h_BE y_prev: quad32) (x: seq quad32) (data: (int -> poly128)) : Lemma (requires (forall (i: int). {:pattern data i\/index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i))) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x)) (decreases (length x))
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x)) = ghash_incremental_reveal (); let (~~) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc (==) { ~~(ghash_incremental_def h_BE y_prev x); == {} ~~(gf128_mul_BE xor_BE h_BE); == {lemma_of_to_quad32 (~~xor_BE *~ h)} ~~xor_BE *~ h; == {lemma_add_quad32 y_i_minus_1 x_i} (~~y_i_minus_1 +. ~~x_i) *~ h; == {lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data} (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; == {} ghash_poly h prev data 0 m; }
val lemma_ghash_incremental_poly_rec (h_BE y_prev: quad32) (x: seq quad32) (data: (int -> poly128)) : Lemma (requires (forall (i: int). {:pattern data i\/index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i))) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x)) (decreases (length x)) let rec lemma_ghash_incremental_poly_rec (h_BE y_prev: quad32) (x: seq quad32) (data: (int -> poly128)) : Lemma (requires (forall (i: int). {:pattern data i\/index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i))) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x)) (decreases (length x)) =
false
null
true
ghash_incremental_reveal (); let ( ~~ ) = of_quad32 in let h = ~~h_BE in let prev = ~~y_prev in let m = length x in if m > 0 then let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in let g = gf128_modulus in calc ( == ) { ~~(ghash_incremental_def h_BE y_prev x); ( == ) { () } ~~(gf128_mul_BE xor_BE h_BE); ( == ) { lemma_of_to_quad32 (~~xor_BE *~ h) } ~~xor_BE *~ h; ( == ) { lemma_add_quad32 y_i_minus_1 x_i } (~~y_i_minus_1 +. ~~x_i) *~ h; ( == ) { lemma_ghash_incremental_poly_rec h_BE y_prev (all_but_last x) data } (ghash_poly h prev data 0 (m - 1) +. data (m - 1)) *~ h; ( == ) { () } ghash_poly h prev data 0 m; }
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma", "" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.op_GreaterThan", "FStar.Calc.calc_finish", "Vale.Math.Poly2_s.poly", "Prims.eq2", "Vale.AES.GHash_BE.ghash_incremental_def", "Vale.AES.GHash_BE.ghash_poly", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Vale.AES.GF128.op_Star_Tilde", "Vale.Math.Poly2.op_Plus_Dot", "Prims.op_Subtraction", "Vale.AES.GHash_BE_s.gf128_mul_BE", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Vale.Math.Poly2.Bits.lemma_of_to_quad32", "Vale.Math.Poly2.Words.lemma_add_quad32", "Vale.AES.GHash_BE.lemma_ghash_incremental_poly_rec", "Vale.Lib.Seqs_s.all_but_last", "Vale.AES.GF128_s.gf128_modulus", "Vale.Def.Types_s.quad32_xor", "FStar.Seq.Properties.last", "Prims.bool", "Prims.nat", "FStar.Seq.Base.length", "Vale.Math.Poly2.Bits_s.of_quad32", "Vale.AES.GHash_BE.ghash_incremental_reveal", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.index", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } let rec lemma_ghash_poly_unroll (h0:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h0 < 128 /\ degree prev < 128) (ensures ghash_poly_unroll h0 prev data k m 0 == ghash_poly h0 prev data k (k + m + 1)) = let d = data (k + m) in let p1 = g_power h0 1 in let ghash0 = ghash_poly h0 prev data k (k + m) in if m = 0 then calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} (prev +. d) *~ p1; == {} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } else let unroll0 = ghash_poly_unroll h0 prev data k (m - 1) 0 in let unroll1 = ghash_poly_unroll h0 prev data k (m - 1) 1 in calc (==) { ghash_poly_unroll h0 prev data k m 0; == {} unroll1 +. d *~ p1; == { calc (==) { unroll1; == {lemma_ghash_poly_unroll_n h0 prev data k (m - 1) 0} unroll0 *~ h0; == {lemma_ghash_poly_unroll h0 prev data k (m - 1)} ghash0 *~ h0; } } ghash0 *~ h0 +. d *~ h0; == {lemma_gf128_mul_rev_distribute_left ghash0 d h0} (ghash0 +. d) *~ h0; == {} ghash_poly h0 prev data k (k + m + 1); } let rec lemma_ghash_unroll_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m n) gf128_modulus == ghash_poly_unroll h prev data k m n ) = let g = gf128_modulus in let d = data (k + m) in let p = g_power h (n + 1) in let sp = shift_gf128_key_1 p in lemma_gf128_degree (); if m = 0 then calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 ((prev +. d) *. sp) g; == {lemma_gf128_mul_rev_mod_rev (prev +. d) p} (prev +. d) *~ p; == {} ghash_poly_unroll h prev data k m n; } else let unroll1 = ghash_unroll h prev data k (m - 1) (n + 1) in let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in calc (==) { mod_rev 128 (ghash_unroll h prev data k m n) g; == {} mod_rev 128 (unroll1 +. d *. sp) g; == {lemma_add_mod_rev 128 unroll1 (d *. sp) g} mod_rev 128 unroll1 g +. mod_rev 128 (d *. sp) g; == {lemma_ghash_unroll_poly_unroll h prev data k (m - 1) (n + 1)} ghash0 +. mod_rev 128 (d *. sp) g; == {lemma_gf128_mul_rev_mod_rev d p} ghash0 +. d *~ p; == {} ghash_poly_unroll h prev data k m n; } let lemma_ghash_poly_of_unroll h prev data k m = lemma_ghash_poly_unroll h prev data k m; lemma_ghash_unroll_poly_unroll h prev data k m 0; () let rec lemma_ghash_incremental_poly_rec (h_BE:quad32) (y_prev:quad32) (x:seq quad32) (data:int -> poly128) : Lemma (requires (forall (i:int).{:pattern data i \/ index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i)) ) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x) ) (decreases (length x))
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_incremental_poly_rec (h_BE y_prev: quad32) (x: seq quad32) (data: (int -> poly128)) : Lemma (requires (forall (i: int). {:pattern data i\/index x i} 0 <= i && i < length x ==> data i == of_quad32 (index x i))) (ensures of_quad32 (ghash_incremental_def h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) data 0 (length x)) (decreases (length x))
[ "recursion" ]
Vale.AES.GHash_BE.lemma_ghash_incremental_poly_rec
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h_BE: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern data i\/FStar.Seq.Base.index x i} 0 <= i && i < FStar.Seq.Base.length x ==> data i == Vale.Math.Poly2.Bits_s.of_quad32 (FStar.Seq.Base.index x i)) (ensures Vale.Math.Poly2.Bits_s.of_quad32 (Vale.AES.GHash_BE.ghash_incremental_def h_BE y_prev x) == Vale.AES.GHash_BE.ghash_poly (Vale.Math.Poly2.Bits_s.of_quad32 h_BE) (Vale.Math.Poly2.Bits_s.of_quad32 y_prev) data 0 (FStar.Seq.Base.length x)) (decreases FStar.Seq.Base.length x)
{ "end_col": 5, "end_line": 234, "start_col": 2, "start_line": 212 }
FStar.Pervasives.Lemma
val lemma_ghash_poly_unroll_n (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h)
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) = let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} (prev +. d) *~ p1; == {} (prev +. d) *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} (prev +. d) *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate (prev +. d) p0 h} ((prev +. d) *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc (==) { ghash_poly_unroll h prev data k m (n + 1); == {} ghash1 +. d *~ p1; == {lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1)} ghash0 *~ h +. d *~ p1; == {} ghash0 *~ h +. d *~ (h *~ p0); == {lemma_gf128_mul_rev_commute p0 h} ghash0 *~ h +. d *~ (p0 *~ h); == {lemma_gf128_mul_rev_associate d p0 h} ghash0 *~ h +. (d *~ p0) *~ h; == {lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h} (ghash0 +. d *~ p0) *~ h; == {} ghash_poly_unroll h prev data k m n *~ h; }
val lemma_ghash_poly_unroll_n (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) let rec lemma_ghash_poly_unroll_n (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h) =
false
null
true
let d = data (k + m) in let p0 = g_power h (n + 1) in let p1 = g_power h (n + 2) in if m = 0 then calc ( == ) { ghash_poly_unroll h prev data k m (n + 1); ( == ) { () } (prev +. d) *~ p1; ( == ) { () } (prev +. d) *~ (h *~ p0); ( == ) { lemma_gf128_mul_rev_commute p0 h } (prev +. d) *~ (p0 *~ h); ( == ) { lemma_gf128_mul_rev_associate (prev +. d) p0 h } ((prev +. d) *~ p0) *~ h; ( == ) { () } ghash_poly_unroll h prev data k m n *~ h; } else let ghash0 = ghash_poly_unroll h prev data k (m - 1) (n + 1) in let ghash1 = ghash_poly_unroll h prev data k (m - 1) (n + 2) in calc ( == ) { ghash_poly_unroll h prev data k m (n + 1); ( == ) { () } ghash1 +. d *~ p1; ( == ) { lemma_ghash_poly_unroll_n h prev data k (m - 1) (n + 1) } ghash0 *~ h +. d *~ p1; ( == ) { () } ghash0 *~ h +. d *~ (h *~ p0); ( == ) { lemma_gf128_mul_rev_commute p0 h } ghash0 *~ h +. d *~ (p0 *~ h); ( == ) { lemma_gf128_mul_rev_associate d p0 h } ghash0 *~ h +. (d *~ p0) *~ h; ( == ) { lemma_gf128_mul_rev_distribute_left ghash0 (d *~ p0) h } (ghash0 +. d *~ p0) *~ h; ( == ) { () } ghash_poly_unroll h prev data k m n *~ h; }
{ "checked_file": "Vale.AES.GHash_BE.fst.checked", "dependencies": [ "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.AES.OptPublic_BE.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GHash_BE.fst" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_Equality", "FStar.Calc.calc_finish", "Prims.eq2", "Vale.AES.GHash_BE.ghash_poly_unroll", "Prims.op_Addition", "Vale.AES.GF128.op_Star_Tilde", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Vale.Math.Poly2.op_Plus_Dot", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Vale.AES.GF128.lemma_gf128_mul_rev_commute", "Vale.AES.GF128.lemma_gf128_mul_rev_associate", "Prims.bool", "Vale.AES.GHash_BE.lemma_ghash_poly_unroll_n", "Prims.op_Subtraction", "Vale.AES.GF128.lemma_gf128_mul_rev_distribute_left", "Vale.AES.GHash_BE.g_power", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open FStar.Mul open Vale.Math.Poly2.Lemmas open Vale.Math.Poly2.Words friend Vale.AES.OptPublic_BE #reset-options let shift_gf128_key_1 (h:poly) : poly = shift_key_1 128 gf128_modulus_low_terms h let rec g_power (a:poly) (n:nat) : poly = if n = 0 then zero else // arbitrary value for n = 0 if n = 1 then a else a *~ g_power a (n - 1) let lemma_g_power_1 a = () let lemma_g_power_n a n = () let gf128_power h n = shift_gf128_key_1 (g_power h n) let lemma_gf128_power h n = () let rec ghash_poly_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = g_power h (n + 1) in if m = 0 then (prev +. d) *~ p else ghash_poly_unroll h prev data k (m - 1) (n + 1) +. d *~ p let lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) = () let rec lemma_ghash_unroll_back_forward_rec (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : Lemma (requires m < n) (ensures ghash_unroll h prev data k n 0 == ghash_unroll h prev data k (n - 1 - m) (m + 1) +. ghash_unroll_back h prev data k (n + 1) m) = lemma_add_all (); if m > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (m - 1) let lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) = lemma_add_all (); if n > 0 then lemma_ghash_unroll_back_forward_rec h prev data k n (n - 1) let lemma_gf128_mul_rev_mod_rev (a h:poly) : Lemma (requires degree a < 128 /\ degree h < 128) (ensures gf128_mul_rev a h == mod_rev 128 (a *. shift_gf128_key_1 h) gf128_modulus) = let h1 = shift_gf128_key_1 h in let rev x = reverse x 127 in let g = gf128_modulus in lemma_gf128_degree (); calc (==) { // gf128_mul_rev a h rev ((rev a *. rev h) %. g); == {lemma_mod_mul_mod_right (rev a) (rev h) g} rev ((rev a *. (rev h %. g)) %. g); == {lemma_shift_key_1 128 gf128_modulus_low_terms h} rev ((rev a *. (shift (rev h1) 1 %. g)) %. g); == {lemma_mod_mul_mod_right (rev a) (shift (rev h1) 1) g} rev ((rev a *. (shift (rev h1) 1)) %. g); == {lemma_shift_is_mul (rev h1) 1} rev ((rev a *. (rev h1 *. monomial 1)) %. g); == {lemma_mul_all ()} rev (((rev a *. rev h1) *. monomial 1) %. g); == {lemma_shift_is_mul (rev a *. rev h1) 1} rev (shift (rev a *. rev h1) 1 %. g); == {lemma_mul_reverse_shift_1 a h1 127} rev (reverse (a *. h1) 255 %. g); } let rec lemma_ghash_poly_unroll_n (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : Lemma
false
false
Vale.AES.GHash_BE.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_ghash_poly_unroll_n (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : Lemma (ghash_poly_unroll h prev data k m (n + 1) == ghash_poly_unroll h prev data k m n *~ h)
[ "recursion" ]
Vale.AES.GHash_BE.lemma_ghash_poly_unroll_n
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> m: Prims.nat -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash_BE.ghash_poly_unroll h prev data k m (n + 1) == Vale.AES.GHash_BE.ghash_poly_unroll h prev data k m n *~ h)
{ "end_col": 5, "end_line": 115, "start_col": 3, "start_line": 78 }
FStar.Pervasives.Lemma
val init_next (#a: Type) (s: S.seq a) (f: (i: nat{i < S.length s} -> a)) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f)))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let init_next (#a: Type) (s: S.seq a) (f: (i:nat { i < S.length s }) -> a) (i: nat): Lemma (requires ( i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f))) = lemma_slice_ijk s 0 i (i + 1)
val init_next (#a: Type) (s: S.seq a) (f: (i: nat{i < S.length s} -> a)) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f))) let init_next (#a: Type) (s: S.seq a) (f: (i: nat{i < S.length s} -> a)) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f))) =
false
null
true
lemma_slice_ijk s 0 i (i + 1)
{ "checked_file": "Hacl.Hash.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Hash.Lemmas.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Hacl.Hash.Lemmas.lemma_slice_ijk", "Prims.op_Addition", "Prims.unit", "Prims.l_and", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Seq.Base.init", "Prims.eq2", "FStar.Seq.Base.index", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Hacl.Hash.Lemmas module S = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 (** Two sequence lemmas required for pad, among others. *) let lemma_slice (#a: Type) (s: S.seq a) (i: nat): Lemma (requires (i <= S.length s)) (ensures (S.equal (S.append (S.slice s 0 i) (S.slice s i (S.length s))) s)) [ SMTPat (S.append (S.slice s 0 i) (S.slice s i (S.length s))) ] = () let lemma_slice_ijk (#a: Type) (s: S.seq a) (i j k: nat): Lemma (requires (i <= j /\ j <= k /\ k <= S.length s)) (ensures (S.equal (S.append (S.slice s i j) (S.slice s j k)) (S.slice s i k))) [ SMTPat (S.append (S.slice s i j) (S.slice s j k)) ] = () (** Two sequence lemmas required for the pre-computation of Spec.ws *) // Note: a similar lemma exists in FStar.Seq.Base but yields a forall in the // ensures clauses which doesn't work, really. let init_index (#a: Type) (j: nat) (f: (i:nat { i < j }) -> a) (i: nat): Lemma (requires ( i < j)) (ensures (S.index (S.init j f) i == f i)) [ SMTPat (S.index (S.init j f) i) ] = () let init_next (#a: Type) (s: S.seq a) (f: (i:nat { i < S.length s }) -> a) (i: nat): Lemma (requires ( i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f)))
false
false
Hacl.Hash.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_next (#a: Type) (s: S.seq a) (f: (i: nat{i < S.length s} -> a)) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f)))
[]
Hacl.Hash.Lemmas.init_next
{ "file_name": "code/hash/Hacl.Hash.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq a -> f: (i: Prims.nat{i < FStar.Seq.Base.length s} -> a) -> i: Prims.nat -> FStar.Pervasives.Lemma (requires i < FStar.Seq.Base.length s /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice s 0 i) (FStar.Seq.Base.init i f) /\ FStar.Seq.Base.index s i == f i) (ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice s 0 (i + 1)) (FStar.Seq.Base.init (i + 1) f))
{ "end_col": 31, "end_line": 45, "start_col": 2, "start_line": 45 }
FStar.Pervasives.Lemma
val create_next (#a: Type) (s: S.seq a) (v: a) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.create i v) /\ S.index s i == v)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.create (i + 1) v)))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create_next (#a: Type) (s: S.seq a) (v: a) (i: nat): Lemma (requires ( i < S.length s /\ S.equal (S.slice s 0 i) (S.create i v) /\ S.index s i == v)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.create (i + 1) v))) = lemma_slice_ijk s 0 i (i + 1)
val create_next (#a: Type) (s: S.seq a) (v: a) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.create i v) /\ S.index s i == v)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.create (i + 1) v))) let create_next (#a: Type) (s: S.seq a) (v: a) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.create i v) /\ S.index s i == v)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.create (i + 1) v))) =
false
null
true
lemma_slice_ijk s 0 i (i + 1)
{ "checked_file": "Hacl.Hash.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Hash.Lemmas.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Prims.nat", "Hacl.Hash.Lemmas.lemma_slice_ijk", "Prims.op_Addition", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Seq.Base.create", "Prims.eq2", "FStar.Seq.Base.index", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Hacl.Hash.Lemmas module S = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 (** Two sequence lemmas required for pad, among others. *) let lemma_slice (#a: Type) (s: S.seq a) (i: nat): Lemma (requires (i <= S.length s)) (ensures (S.equal (S.append (S.slice s 0 i) (S.slice s i (S.length s))) s)) [ SMTPat (S.append (S.slice s 0 i) (S.slice s i (S.length s))) ] = () let lemma_slice_ijk (#a: Type) (s: S.seq a) (i j k: nat): Lemma (requires (i <= j /\ j <= k /\ k <= S.length s)) (ensures (S.equal (S.append (S.slice s i j) (S.slice s j k)) (S.slice s i k))) [ SMTPat (S.append (S.slice s i j) (S.slice s j k)) ] = () (** Two sequence lemmas required for the pre-computation of Spec.ws *) // Note: a similar lemma exists in FStar.Seq.Base but yields a forall in the // ensures clauses which doesn't work, really. let init_index (#a: Type) (j: nat) (f: (i:nat { i < j }) -> a) (i: nat): Lemma (requires ( i < j)) (ensures (S.index (S.init j f) i == f i)) [ SMTPat (S.index (S.init j f) i) ] = () let init_next (#a: Type) (s: S.seq a) (f: (i:nat { i < S.length s }) -> a) (i: nat): Lemma (requires ( i < S.length s /\ S.equal (S.slice s 0 i) (S.init i f) /\ S.index s i == f i)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.init (i + 1) f))) = lemma_slice_ijk s 0 i (i + 1) (** One lemma required for the commutations of seq_uint*_of_be and append. *) let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) [ SMTPat (S.tail (S.cons hd tl)) ] = () (** One lemma needed for our for loop for padding *) let create_next (#a: Type) (s: S.seq a) (v: a) (i: nat): Lemma (requires ( i < S.length s /\ S.equal (S.slice s 0 i) (S.create i v) /\ S.index s i == v)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.create (i + 1) v)))
false
false
Hacl.Hash.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val create_next (#a: Type) (s: S.seq a) (v: a) (i: nat) : Lemma (requires (i < S.length s /\ S.equal (S.slice s 0 i) (S.create i v) /\ S.index s i == v)) (ensures (S.equal (S.slice s 0 (i + 1)) (S.create (i + 1) v)))
[]
Hacl.Hash.Lemmas.create_next
{ "file_name": "code/hash/Hacl.Hash.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq a -> v: a -> i: Prims.nat -> FStar.Pervasives.Lemma (requires i < FStar.Seq.Base.length s /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice s 0 i) (FStar.Seq.Base.create i v) /\ FStar.Seq.Base.index s i == v) (ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice s 0 (i + 1)) (FStar.Seq.Base.create (i + 1) v))
{ "end_col": 31, "end_line": 65, "start_col": 2, "start_line": 65 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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 } ]
false
let bn_mod_exp_st (t:limb_t) (len:BN.bn_len t) = nBits:size_nat -> n:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ nBits / bits t < len /\ pow2 nBits < bn_v n) (ensures fun res -> bn_mod_exp_post n a bBits b res)
let bn_mod_exp_st (t: limb_t) (len: BN.bn_len t) =
false
null
false
nBits: size_nat -> n: lbignum t len -> a: lbignum t len -> bBits: size_nat -> b: lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ nBits / bits t < len /\ pow2 nBits < bn_v n) (ensures fun res -> bn_mod_exp_post n a bBits b res)
{ "checked_file": "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Exponentiation.fsti" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.l_and", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Prims.pow2", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post" ]
[]
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BN = Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_mod_exp_pre (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) = bn_v n % 2 = 1 /\ 1 < bn_v n /\ bn_v b < pow2 bBits /\ bn_v a < bn_v n let bn_mod_exp_post (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) (res:lbignum t len) = bn_mod_exp_pre n a bBits b /\ bn_v res == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b) val bn_check_mod_exp: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> res:limb t{ let b = bn_v n % 2 = 1 && 1 < bn_v n && bn_v b < pow2 bBits && bn_v a < bn_v n in v res == (if b then v (ones t SEC) else v (zeros t SEC))} let bn_mod_exp_precomp_st (t:limb_t) (len:BN.bn_len t) = n:lbignum t len -> mu:limb t -> r2:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 (2 * bits t * len) % bn_v n /\ (1 + bn_v n * v mu) % pow2 (bits t) == 0) (ensures fun res -> bn_mod_exp_post n a bBits b res) val bn_mod_exp_rl_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len val bn_mod_exp_mont_ladder_swap_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len val bn_mod_exp_fw_precomp: #t:limb_t -> len:BN.bn_len t -> l:size_pos{l < bits t /\ pow2 l * len <= max_size_t} -> bn_mod_exp_precomp_st t len //no need to distinguish between vartime and consttime in the spec val bn_mod_exp_vartime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len val bn_mod_exp_consttime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len let bn_mod_exp_precompr2_st (t:limb_t) (len:BN.bn_len t) = n:lbignum t len -> r2:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 (2 * bits t * len) % bn_v n) (ensures fun res -> bn_mod_exp_post n a bBits b res) val bn_mod_exp_vartime_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precompr2_st t len val bn_mod_exp_consttime_precompr2: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precompr2_st t len
false
false
Hacl.Spec.Bignum.Exponentiation.fsti
{ "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" }
null
val bn_mod_exp_st : t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0
[]
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_st
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0
{ "end_col": 36, "end_line": 114, "start_col": 4, "start_line": 104 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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 } ]
false
let bn_mod_exp_precompr2_st (t:limb_t) (len:BN.bn_len t) = n:lbignum t len -> r2:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 (2 * bits t * len) % bn_v n) (ensures fun res -> bn_mod_exp_post n a bBits b res)
let bn_mod_exp_precompr2_st (t: limb_t) (len: BN.bn_len t) =
false
null
false
n: lbignum t len -> r2: lbignum t len -> a: lbignum t len -> bBits: size_nat -> b: lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 ((2 * bits t) * len) % bn_v n) (ensures fun res -> bn_mod_exp_post n a bBits b res)
{ "checked_file": "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Exponentiation.fsti" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.l_and", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Modulus", "Prims.pow2", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post" ]
[]
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BN = Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_mod_exp_pre (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) = bn_v n % 2 = 1 /\ 1 < bn_v n /\ bn_v b < pow2 bBits /\ bn_v a < bn_v n let bn_mod_exp_post (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) (res:lbignum t len) = bn_mod_exp_pre n a bBits b /\ bn_v res == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b) val bn_check_mod_exp: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> res:limb t{ let b = bn_v n % 2 = 1 && 1 < bn_v n && bn_v b < pow2 bBits && bn_v a < bn_v n in v res == (if b then v (ones t SEC) else v (zeros t SEC))} let bn_mod_exp_precomp_st (t:limb_t) (len:BN.bn_len t) = n:lbignum t len -> mu:limb t -> r2:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 (2 * bits t * len) % bn_v n /\ (1 + bn_v n * v mu) % pow2 (bits t) == 0) (ensures fun res -> bn_mod_exp_post n a bBits b res) val bn_mod_exp_rl_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len val bn_mod_exp_mont_ladder_swap_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len val bn_mod_exp_fw_precomp: #t:limb_t -> len:BN.bn_len t -> l:size_pos{l < bits t /\ pow2 l * len <= max_size_t} -> bn_mod_exp_precomp_st t len //no need to distinguish between vartime and consttime in the spec val bn_mod_exp_vartime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len val bn_mod_exp_consttime_precomp: #t:limb_t -> len:BN.bn_len t -> bn_mod_exp_precomp_st t len
false
false
Hacl.Spec.Bignum.Exponentiation.fsti
{ "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" }
null
val bn_mod_exp_precompr2_st : t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0
[]
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precompr2_st
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0
{ "end_col": 36, "end_line": 96, "start_col": 4, "start_line": 86 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.AlmostMontExponentiation", "short_module": "AE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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 } ]
false
let bn_mod_exp_precomp_st (t:limb_t) (len:BN.bn_len t) = n:lbignum t len -> mu:limb t -> r2:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 (2 * bits t * len) % bn_v n /\ (1 + bn_v n * v mu) % pow2 (bits t) == 0) (ensures fun res -> bn_mod_exp_post n a bBits b res)
let bn_mod_exp_precomp_st (t: limb_t) (len: BN.bn_len t) =
false
null
false
n: lbignum t len -> mu: limb t -> r2: lbignum t len -> a: lbignum t len -> bBits: size_nat -> b: lbignum t (blocks0 bBits (bits t)) -> Pure (lbignum t len) (requires bn_mod_exp_pre n a bBits b /\ bn_v r2 == pow2 ((2 * bits t) * len) % bn_v n /\ (1 + bn_v n * v mu) % pow2 (bits t) == 0) (ensures fun res -> bn_mod_exp_post n a bBits b res)
{ "checked_file": "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Exponentiation.fsti" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.l_and", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Modulus", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post" ]
[]
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BN = Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_mod_exp_pre (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) = bn_v n % 2 = 1 /\ 1 < bn_v n /\ bn_v b < pow2 bBits /\ bn_v a < bn_v n let bn_mod_exp_post (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) (res:lbignum t len) = bn_mod_exp_pre n a bBits b /\ bn_v res == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b) val bn_check_mod_exp: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> a:lbignum t len -> bBits:size_nat -> b:lbignum t (blocks0 bBits (bits t)) -> res:limb t{ let b = bn_v n % 2 = 1 && 1 < bn_v n && bn_v b < pow2 bBits && bn_v a < bn_v n in v res == (if b then v (ones t SEC) else v (zeros t SEC))}
false
false
Hacl.Spec.Bignum.Exponentiation.fsti
{ "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" }
null
val bn_mod_exp_precomp_st : t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0
[]
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_precomp_st
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0
{ "end_col": 36, "end_line": 67, "start_col": 4, "start_line": 55 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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 } ]
false
let bn_mod_exp_post (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) (res:lbignum t len) = bn_mod_exp_pre n a bBits b /\ bn_v res == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)
let bn_mod_exp_post (#t: limb_t) (#len: BN.bn_len t) (n a: lbignum t len) (bBits: size_nat) (b: lbignum t (blocks0 bBits (bits t))) (res: lbignum t len) =
false
null
false
bn_mod_exp_pre n a bBits b /\ bn_v res == Lib.NatMod.pow_mod #(bn_v n) (bn_v a) (bn_v b)
{ "checked_file": "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Exponentiation.fsti" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.l_and", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre", "Prims.eq2", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.NatMod.pow_mod", "Prims.logical" ]
[]
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BN = Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_mod_exp_pre (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) = bn_v n % 2 = 1 /\ 1 < bn_v n /\ bn_v b < pow2 bBits /\ bn_v a < bn_v n let bn_mod_exp_post (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) (res:lbignum t len)
false
false
Hacl.Spec.Bignum.Exponentiation.fsti
{ "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" }
null
val bn_mod_exp_post : n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> bBits: Lib.IntTypes.size_nat -> b: Hacl.Spec.Bignum.Definitions.lbignum t (Hacl.Spec.Bignum.Definitions.blocks0 bBits (Lib.IntTypes.bits t)) -> res: Hacl.Spec.Bignum.Definitions.lbignum t len -> Prims.logical
[]
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> bBits: Lib.IntTypes.size_nat -> b: Hacl.Spec.Bignum.Definitions.lbignum t (Hacl.Spec.Bignum.Definitions.blocks0 bBits (Lib.IntTypes.bits t)) -> res: Hacl.Spec.Bignum.Definitions.lbignum t len -> Prims.logical
{ "end_col": 60, "end_line": 36, "start_col": 2, "start_line": 35 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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 } ]
false
let bn_mod_exp_pre (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t))) = bn_v n % 2 = 1 /\ 1 < bn_v n /\ bn_v b < pow2 bBits /\ bn_v a < bn_v n
let bn_mod_exp_pre (#t: limb_t) (#len: BN.bn_len t) (n a: lbignum t len) (bBits: size_nat) (b: lbignum t (blocks0 bBits (bits t))) =
false
null
false
bn_v n % 2 = 1 /\ 1 < bn_v n /\ bn_v b < pow2 bBits /\ bn_v a < bn_v n
{ "checked_file": "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Exponentiation.fsti" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_LessThan", "Prims.pow2", "Prims.logical" ]
[]
module Hacl.Spec.Bignum.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BN = Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_mod_exp_pre (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) (a:lbignum t len) (bBits:size_nat) (b:lbignum t (blocks0 bBits (bits t)))
false
false
Hacl.Spec.Bignum.Exponentiation.fsti
{ "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" }
null
val bn_mod_exp_pre : n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> bBits: Lib.IntTypes.size_nat -> b: Hacl.Spec.Bignum.Definitions.lbignum t (Hacl.Spec.Bignum.Definitions.blocks0 bBits (Lib.IntTypes.bits t)) -> Prims.logical
[]
Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Exponentiation.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> bBits: Lib.IntTypes.size_nat -> b: Hacl.Spec.Bignum.Definitions.lbignum t (Hacl.Spec.Bignum.Definitions.blocks0 bBits (Lib.IntTypes.bits t)) -> Prims.logical
{ "end_col": 41, "end_line": 23, "start_col": 3, "start_line": 22 }
Prims.GTot
val m (#sl: _) (#t: lattice_element sl) (#s: _) (x: secret_int t s) : GTot (int_t s)
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x)
val m (#sl: _) (#t: lattice_element sl) (#s: _) (x: secret_int t s) : GTot (int_t s) let m #sl (#t: lattice_element sl) #s (x: secret_int t s) : GTot (int_t s) =
false
null
false
u (reveal x)
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "sometrivial" ]
[ "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.ConstantTime.Integers.secret_int", "FStar.Integers.u", "FStar.ConstantTime.Integers.reveal", "FStar.Integers.int_t" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s)
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val m (#sl: _) (#t: lattice_element sl) (#s: _) (x: secret_int t s) : GTot (int_t s)
[]
FStar.ConstantTime.Integers.m
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.ConstantTime.Integers.secret_int t s -> Prims.GTot (FStar.Integers.int_t s)
{ "end_col": 16, "end_line": 51, "start_col": 4, "start_line": 51 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128}
let sw =
false
null
false
s: signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128}
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.Integers.signed_width", "Prims.l_and", "Prims.b2t", "Prims.op_disEquality", "FStar.Integers.width", "FStar.Integers.width_of_sw", "FStar.Integers.Winfinite", "FStar.Integers.W128" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time
false
true
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sw : Type0
[]
FStar.ConstantTime.Integers.sw
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Type0
{ "end_col": 31, "end_line": 33, "start_col": 9, "start_line": 32 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let t (q:qual) = match q with | Secret l s -> secret_int l s | Public s -> int_t s
let t (q: qual) =
false
null
false
match q with | Secret l s -> secret_int l s | Public s -> int_t s
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.ConstantTime.Integers.secret_int", "FStar.Integers.signed_width", "FStar.Integers.int_t" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l (** The type corresponding to a qualifier, either an integer or a secret integer *) [@@mark_for_norm] unfold
false
true
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t : q: FStar.ConstantTime.Integers.qual -> Type0
[]
FStar.ConstantTime.Integers.t
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
q: FStar.ConstantTime.Integers.qual -> Type0
{ "end_col": 23, "end_line": 147, "start_col": 2, "start_line": 145 }
Prims.Tot
val label_qual (q: qual{Secret? q}) : lattice_element (Secret?.sl q)
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l
val label_qual (q: qual{Secret? q}) : lattice_element (Secret?.sl q) let label_qual (q: qual{Secret? q}) : lattice_element (Secret?.sl q) =
false
null
false
match q with | Secret l _ -> l
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "Prims.b2t", "FStar.ConstantTime.Integers.uu___is_Secret", "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.ConstantTime.Integers.__proj__Secret__item__sl" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val label_qual (q: qual{Secret? q}) : lattice_element (Secret?.sl q)
[]
FStar.ConstantTime.Integers.label_qual
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
q: FStar.ConstantTime.Integers.qual{Secret? q} -> FStar.IFC.lattice_element (Secret?.sl q)
{ "end_col": 19, "end_line": 139, "start_col": 2, "start_line": 138 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sw_qual = function | Secret _ sw -> sw | Public sw -> sw
let sw_qual =
false
null
false
function | Secret _ sw -> sw | Public sw -> sw
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.Integers.signed_width" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm]
false
true
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sw_qual : _: FStar.ConstantTime.Integers.qual -> FStar.Integers.signed_width
[]
FStar.ConstantTime.Integers.sw_qual
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: FStar.ConstantTime.Integers.qual -> FStar.Integers.signed_width
{ "end_col": 19, "end_line": 132, "start_col": 14, "start_line": 130 }
Prims.Tot
val as_public (#q: qual{Public? q}) (x: t q) : int_t (sw_qual q)
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let as_public (#q:qual{Public? q}) (x:t q) : int_t (sw_qual q) = x
val as_public (#q: qual{Public? q}) (x: t q) : int_t (sw_qual q) let as_public (#q: qual{Public? q}) (x: t q) : int_t (sw_qual q) =
false
null
false
x
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "Prims.b2t", "FStar.ConstantTime.Integers.uu___is_Public", "FStar.ConstantTime.Integers.t", "FStar.Integers.int_t", "FStar.ConstantTime.Integers.sw_qual" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l (** The type corresponding to a qualifier, either an integer or a secret integer *) [@@mark_for_norm] unfold let t (q:qual) = match q with | Secret l s -> secret_int l s | Public s -> int_t s [@@mark_for_norm] unfold let i (#q:qual) (x:t q) : GTot (int_t (sw_qual q)) = match q with | Public s -> x | Secret l s -> m (x <: secret_int l s) [@@mark_for_norm] unfold let as_secret (#q:qual{Secret? q}) (x:t q) : secret_int (label_qual q) (sw_qual q) = x [@@mark_for_norm] unfold let as_public (#q:qual{Public? q}) (x:t q)
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val as_public (#q: qual{Public? q}) (x: t q) : int_t (sw_qual q)
[]
FStar.ConstantTime.Integers.as_public
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.ConstantTime.Integers.t q -> FStar.Integers.int_t (FStar.ConstantTime.Integers.sw_qual q)
{ "end_col": 5, "end_line": 166, "start_col": 4, "start_line": 166 }
Prims.GTot
val i (#q: qual) (x: t q) : GTot (int_t (sw_qual q))
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let i (#q:qual) (x:t q) : GTot (int_t (sw_qual q)) = match q with | Public s -> x | Secret l s -> m (x <: secret_int l s)
val i (#q: qual) (x: t q) : GTot (int_t (sw_qual q)) let i (#q: qual) (x: t q) : GTot (int_t (sw_qual q)) =
false
null
false
match q with | Public s -> x | Secret l s -> m (x <: secret_int l s)
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "sometrivial" ]
[ "FStar.ConstantTime.Integers.qual", "FStar.ConstantTime.Integers.t", "FStar.Integers.signed_width", "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.ConstantTime.Integers.m", "FStar.ConstantTime.Integers.secret_int", "FStar.Integers.int_t", "FStar.ConstantTime.Integers.sw_qual" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l (** The type corresponding to a qualifier, either an integer or a secret integer *) [@@mark_for_norm] unfold let t (q:qual) = match q with | Secret l s -> secret_int l s | Public s -> int_t s [@@mark_for_norm] unfold
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val i (#q: qual) (x: t q) : GTot (int_t (sw_qual q))
[]
FStar.ConstantTime.Integers.i
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.ConstantTime.Integers.t q -> Prims.GTot (FStar.Integers.int_t (FStar.ConstantTime.Integers.sw_qual q))
{ "end_col": 41, "end_line": 154, "start_col": 2, "start_line": 152 }
Prims.Tot
val op_Plus (#q: qual) (x: t q) (y: t q {ok ( + ) (i x) (i y)}) : Tot (t q)
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ( + ) (#q:qual) (x:t q) (y:t q{ok (+) (i x) (i y)}) : Tot (t q) = match q with | Public s -> as_public x + as_public y | Secret l s -> as_secret x `addition` as_secret y
val op_Plus (#q: qual) (x: t q) (y: t q {ok ( + ) (i x) (i y)}) : Tot (t q) let op_Plus (#q: qual) (x: t q) (y: t q {ok ( + ) (i x) (i y)}) : Tot (t q) =
false
null
false
match q with | Public s -> as_public x + as_public y | Secret l s -> (as_secret x) `addition` (as_secret y)
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "FStar.ConstantTime.Integers.t", "FStar.Integers.ok", "FStar.ConstantTime.Integers.sw_qual", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.ConstantTime.Integers.i", "FStar.Integers.signed_width", "FStar.ConstantTime.Integers.as_public", "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.ConstantTime.Integers.addition", "FStar.ConstantTime.Integers.__proj__Secret__item__sl", "FStar.ConstantTime.Integers.label_qual", "FStar.ConstantTime.Integers.as_secret" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l (** The type corresponding to a qualifier, either an integer or a secret integer *) [@@mark_for_norm] unfold let t (q:qual) = match q with | Secret l s -> secret_int l s | Public s -> int_t s [@@mark_for_norm] unfold let i (#q:qual) (x:t q) : GTot (int_t (sw_qual q)) = match q with | Public s -> x | Secret l s -> m (x <: secret_int l s) [@@mark_for_norm] unfold let as_secret (#q:qual{Secret? q}) (x:t q) : secret_int (label_qual q) (sw_qual q) = x [@@mark_for_norm] unfold let as_public (#q:qual{Public? q}) (x:t q) : int_t (sw_qual q) = x (** Lifting addition to work over both secret and public integers *) [@@mark_for_norm] unfold noextract inline_for_extraction let ( + ) (#q:qual) (x:t q) (y:t q{ok (+) (i x) (i y)})
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Plus (#q: qual) (x: t q) (y: t q {ok ( + ) (i x) (i y)}) : Tot (t q)
[]
FStar.ConstantTime.Integers.op_Plus
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.ConstantTime.Integers.t q -> y: FStar.ConstantTime.Integers.t q { FStar.Integers.ok FStar.Integers.op_Plus (FStar.ConstantTime.Integers.i x) (FStar.ConstantTime.Integers.i y) } -> FStar.ConstantTime.Integers.t q
{ "end_col": 56, "end_line": 177, "start_col": 6, "start_line": 175 }
Prims.Tot
val as_secret (#q: qual{Secret? q}) (x: t q) : secret_int (label_qual q) (sw_qual q)
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let as_secret (#q:qual{Secret? q}) (x:t q) : secret_int (label_qual q) (sw_qual q) = x
val as_secret (#q: qual{Secret? q}) (x: t q) : secret_int (label_qual q) (sw_qual q) let as_secret (#q: qual{Secret? q}) (x: t q) : secret_int (label_qual q) (sw_qual q) =
false
null
false
x
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "Prims.b2t", "FStar.ConstantTime.Integers.uu___is_Secret", "FStar.ConstantTime.Integers.t", "FStar.ConstantTime.Integers.secret_int", "FStar.ConstantTime.Integers.__proj__Secret__item__sl", "FStar.ConstantTime.Integers.label_qual", "FStar.ConstantTime.Integers.sw_qual" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l (** The type corresponding to a qualifier, either an integer or a secret integer *) [@@mark_for_norm] unfold let t (q:qual) = match q with | Secret l s -> secret_int l s | Public s -> int_t s [@@mark_for_norm] unfold let i (#q:qual) (x:t q) : GTot (int_t (sw_qual q)) = match q with | Public s -> x | Secret l s -> m (x <: secret_int l s) [@@mark_for_norm] unfold let as_secret (#q:qual{Secret? q}) (x:t q)
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val as_secret (#q: qual{Secret? q}) (x: t q) : secret_int (label_qual q) (sw_qual q)
[]
FStar.ConstantTime.Integers.as_secret
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.ConstantTime.Integers.t q -> FStar.ConstantTime.Integers.secret_int (FStar.ConstantTime.Integers.label_qual q) (FStar.ConstantTime.Integers.sw_qual q)
{ "end_col": 5, "end_line": 160, "start_col": 4, "start_line": 160 }
Prims.Tot
val op_Plus_Percent (#q: qual{norm (Unsigned? (sw_qual q) /\ width_of_sw (sw_qual q) <> W128)}) (x y: t q) : Tot (t q)
[ { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.IFC", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.ConstantTime", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ( +% ) (#q:qual{norm (Unsigned? (sw_qual q) /\ width_of_sw (sw_qual q) <> W128)}) (x:t q) (y:t q) : Tot (t q) = match q with | Public s -> as_public x +% as_public y | Secret l s -> as_secret x `addition_mod` as_secret y
val op_Plus_Percent (#q: qual{norm (Unsigned? (sw_qual q) /\ width_of_sw (sw_qual q) <> W128)}) (x y: t q) : Tot (t q) let op_Plus_Percent (#q: qual{norm (Unsigned? (sw_qual q) /\ width_of_sw (sw_qual q) <> W128)}) (x y: t q) : Tot (t q) =
false
null
false
match q with | Public s -> as_public x +% as_public y | Secret l s -> (as_secret x) `addition_mod` (as_secret y)
{ "checked_file": "FStar.ConstantTime.Integers.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.IFC.fsti.checked" ], "interface_file": false, "source_file": "FStar.ConstantTime.Integers.fsti" }
[ "total" ]
[ "FStar.ConstantTime.Integers.qual", "FStar.Integers.norm", "Prims.l_and", "Prims.b2t", "FStar.Integers.uu___is_Unsigned", "FStar.ConstantTime.Integers.sw_qual", "Prims.op_disEquality", "FStar.Integers.width", "FStar.Integers.width_of_sw", "FStar.Integers.W128", "FStar.ConstantTime.Integers.t", "FStar.Integers.signed_width", "FStar.Integers.op_Plus_Percent", "FStar.ConstantTime.Integers.as_public", "FStar.IFC.sl", "FStar.IFC.lattice_element", "FStar.ConstantTime.Integers.sw", "FStar.ConstantTime.Integers.addition_mod", "FStar.ConstantTime.Integers.__proj__Secret__item__sl", "FStar.ConstantTime.Integers.label_qual", "FStar.ConstantTime.Integers.as_secret" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.ConstantTime.Integers /// This module provides a refinement of FStar.IFC providing an /// interface restricted only to constant-time operations on integers. /// /// In contrast, FStar.IFC provides a general monadic information-flow /// control framework, which need not be restricted to constant-time /// operations. open FStar.IFC open FStar.Integers (** `sw`: signedness and width of machine integers excluding FStar.[U]Int128, which does not provide constant-time operations. *) let sw = s:signed_width{width_of_sw s <> Winfinite /\ width_of_sw s <> W128} (** A `secret_int l s` is a machine-integer at secrecy level `l` and signedness/width `s`. *) val secret_int (#sl:sl u#c) (l:lattice_element sl) (s:sw) : Type0 (** A `secret_int l s` can be seen as an int in spec *) val reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : GTot (y:int{within_bounds s y}) (** A `secret_int l s` can be also be seen as an machine integer in spec *) let m #sl (#t:lattice_element sl) #s (x:secret_int t s) : GTot (int_t s) = u (reveal x) (** `hide` is the inverse of `reveal`, proving that `secret_int` is injective *) val hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : GTot (secret_int l s) val reveal_hide (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:int{within_bounds s x}) : Lemma (reveal (hide #sl #l #s x) == x) val hide_reveal (#sl:sl) (#l:lattice_element sl) (#s:sw) (x:secret_int l s) : Lemma (hide (reveal x) == x) [SMTPat (reveal x)] (** `promote x l` allows increasing the confidentiality classification of `x` This can easily be programmed using the FStar.IFC interface *) val promote (#sl:sl) (#l0:lattice_element sl) (#s:sw) (x:secret_int l0 s) (l1:lattice_element sl) : Tot (y:secret_int (l1 `lub` l0) s{reveal y == reveal x}) /// The remainder of this module provides liftings of specific /// integers operations to work on secret integers, i.e., only those /// that respect the constant time guarantees and do not break /// confidentiality. /// /// Note, with our choice of representation, it is impossible to /// implement functions that break basic IFC guarantees, e.g., we /// cannot implement a boolean comparison function on secret_ints (** Bounds-respecting addition *) noextract inline_for_extraction val addition (#sl:sl) (#l:lattice_element sl) (#s:sw) (x : secret_int l s) (y : secret_int l s {ok ( + ) (m x) (m y)}) : Tot (z:secret_int l s{m z == m x + m y}) (** Addition modulo *) noextract inline_for_extraction val addition_mod (#sl:sl) (#l:lattice_element sl) (#sw: _ {Unsigned? sw /\ width_of_sw sw <> W128}) (x : secret_int l sw) (y : secret_int l sw) : Tot (z:secret_int l sw { m z == m x +% m y } ) /// If we like this style, I will proceed to implement a lifting of /// the rest of the constant-time integers over secret integers /// Now, a multiplexing layer to overload operators over int_t and secret_int (** A type of qualifiers, distinguishing secret and public integers *) noeq type qual = | Secret: #sl:sl -> l:lattice_element sl -> sw:sw -> qual | Public: sw:signed_width -> qual (** The signedness and width of a qualifier *) [@@mark_for_norm] unfold let sw_qual = function | Secret _ sw -> sw | Public sw -> sw (** The lattice element of a secret qualifier *) [@@mark_for_norm] unfold let label_qual (q:qual{Secret? q}) : lattice_element (Secret?.sl q) = match q with | Secret l _ -> l (** The type corresponding to a qualifier, either an integer or a secret integer *) [@@mark_for_norm] unfold let t (q:qual) = match q with | Secret l s -> secret_int l s | Public s -> int_t s [@@mark_for_norm] unfold let i (#q:qual) (x:t q) : GTot (int_t (sw_qual q)) = match q with | Public s -> x | Secret l s -> m (x <: secret_int l s) [@@mark_for_norm] unfold let as_secret (#q:qual{Secret? q}) (x:t q) : secret_int (label_qual q) (sw_qual q) = x [@@mark_for_norm] unfold let as_public (#q:qual{Public? q}) (x:t q) : int_t (sw_qual q) = x (** Lifting addition to work over both secret and public integers *) [@@mark_for_norm] unfold noextract inline_for_extraction let ( + ) (#q:qual) (x:t q) (y:t q{ok (+) (i x) (i y)}) : Tot (t q) = match q with | Public s -> as_public x + as_public y | Secret l s -> as_secret x `addition` as_secret y (** Lifting addition modulo to work over both secret and public integers *) [@@mark_for_norm] unfold noextract inline_for_extraction let ( +% ) (#q:qual{norm (Unsigned? (sw_qual q) /\ width_of_sw (sw_qual q) <> W128)}) (x:t q) (y:t q)
false
false
FStar.ConstantTime.Integers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Plus_Percent (#q: qual{norm (Unsigned? (sw_qual q) /\ width_of_sw (sw_qual q) <> W128)}) (x y: t q) : Tot (t q)
[]
FStar.ConstantTime.Integers.op_Plus_Percent
{ "file_name": "ulib/experimental/FStar.ConstantTime.Integers.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.ConstantTime.Integers.t q -> y: FStar.ConstantTime.Integers.t q -> FStar.ConstantTime.Integers.t q
{ "end_col": 60, "end_line": 190, "start_col": 6, "start_line": 188 }
Steel.ST.Effect.ST
val compare (#a: eqtype) (#p0 #p1: perm) (a0 a1: A.array a) (#s0 #s1: G.erased (Seq.seq a)) (n: US.t{US.v n == A.length a0 /\ A.length a0 == A.length a1}) : ST bool ((A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (fun _ -> (A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (requires True) (ensures fun b -> b <==> s0 == s1)
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": true, "full_module": "Steel.ST.Array", "short_module": "A" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "Steel.ST.Array", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Array", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let compare (#a:eqtype) (#p0 #p1:perm) (a0 a1:A.array a) (#s0 #s1:G.erased (Seq.seq a)) (n:US.t{US.v n == A.length a0 /\ A.length a0 == A.length a1}) : ST bool (A.pts_to a0 p0 s0 `star` A.pts_to a1 p1 s1) (fun _ -> A.pts_to a0 p0 s0 `star` A.pts_to a1 p1 s1) (requires True) (ensures fun b -> b <==> s0 == s1) = let b = for_all2 n a0 a1 (fun x y -> x = y) in A.pts_to_length a0 s0; A.pts_to_length a1 s1; assert (b <==> Seq.equal s0 s1); return b
val compare (#a: eqtype) (#p0 #p1: perm) (a0 a1: A.array a) (#s0 #s1: G.erased (Seq.seq a)) (n: US.t{US.v n == A.length a0 /\ A.length a0 == A.length a1}) : ST bool ((A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (fun _ -> (A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (requires True) (ensures fun b -> b <==> s0 == s1) let compare (#a: eqtype) (#p0 #p1: perm) (a0 a1: A.array a) (#s0 #s1: G.erased (Seq.seq a)) (n: US.t{US.v n == A.length a0 /\ A.length a0 == A.length a1}) : ST bool ((A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (fun _ -> (A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (requires True) (ensures fun b -> b <==> s0 == s1) =
true
null
false
let b = for_all2 n a0 a1 (fun x y -> x = y) in A.pts_to_length a0 s0; A.pts_to_length a1 s1; assert (b <==> Seq.equal s0 s1); return b
{ "checked_file": "Steel.ST.Array.Util.fsti.checked", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Effect.fsti.checked", "Steel.ST.Array.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Array.Util.fsti" }
[]
[ "Prims.eqtype", "Steel.FractionalPermission.perm", "Steel.ST.Array.array", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "FStar.SizeT.t", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.SizeT.v", "Steel.ST.Array.length", "Steel.ST.Util.return", "Prims.bool", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.VStar", "Steel.ST.Array.pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.vprop", "Prims.unit", "Prims._assert", "Prims.l_iff", "Prims.b2t", "FStar.Seq.Base.equal", "Steel.ST.Array.pts_to_length", "Steel.ST.Array.Util.for_all2", "Prims.op_Equality", "Steel.Effect.Common.star", "Prims.l_True" ]
[]
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array.Util module G = FStar.Ghost module US = FStar.SizeT module A = Steel.ST.Array open Steel.FractionalPermission open Steel.ST.Effect open Steel.ST.Util /// Some utilities for steel arrays /// Create an array whose elements are specified by the input function inline_for_extraction val array_literal (#a:Type0) (n:US.t) (f:(i:US.t{US.v i < US.v n} -> a)) : ST (A.array a) emp (fun arr -> A.pts_to arr full_perm (Seq.init (US.v n) (fun i -> f (US.uint_to_t i)))) (requires US.v n > 0) (ensures fun arr -> A.length arr == US.v n) /// Check if all the elements of an array satisfy a predicate inline_for_extraction val for_all (#a:Type0) (#perm:perm) (#s:G.erased (Seq.seq a)) (n:US.t) (arr:A.array a) (p:a -> bool) : ST bool (A.pts_to arr perm s) (fun _ -> A.pts_to arr perm s) (requires A.length arr == US.v n) (ensures fun b -> b <==> (forall (i:nat). i < Seq.length s ==> p (Seq.index s i))) /// for_all2, for predicates over elements of two arrays inline_for_extraction val for_all2 (#a #b:Type0) (#p0 #p1:perm) (#s0:G.erased (Seq.seq a)) (#s1:G.erased (Seq.seq b)) (n:US.t) (a0:A.array a) (a1:A.array b) (p:a -> b -> bool) : ST bool (A.pts_to a0 p0 s0 `star` A.pts_to a1 p1 s1) (fun _ -> A.pts_to a0 p0 s0 `star` A.pts_to a1 p1 s1) (requires A.length a0 == US.v n /\ A.length a0 == A.length a1) (ensures fun b -> b <==> (forall (i:nat). (i < Seq.length s0 /\ i < Seq.length s1) ==> p (Seq.index s0 i) (Seq.index s1 i))) /// An array compare function that uses for_all2 /// to loop over the two arrays and compre their elements let compare (#a:eqtype) (#p0 #p1:perm) (a0 a1:A.array a) (#s0 #s1:G.erased (Seq.seq a)) (n:US.t{US.v n == A.length a0 /\ A.length a0 == A.length a1}) : ST bool (A.pts_to a0 p0 s0 `star` A.pts_to a1 p1 s1) (fun _ -> A.pts_to a0 p0 s0 `star` A.pts_to a1 p1 s1) (requires True)
false
false
Steel.ST.Array.Util.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val compare (#a: eqtype) (#p0 #p1: perm) (a0 a1: A.array a) (#s0 #s1: G.erased (Seq.seq a)) (n: US.t{US.v n == A.length a0 /\ A.length a0 == A.length a1}) : ST bool ((A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (fun _ -> (A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) (requires True) (ensures fun b -> b <==> s0 == s1)
[]
Steel.ST.Array.Util.compare
{ "file_name": "lib/steel/Steel.ST.Array.Util.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
a0: Steel.ST.Array.array a -> a1: Steel.ST.Array.array a -> n: FStar.SizeT.t { FStar.SizeT.v n == Steel.ST.Array.length a0 /\ Steel.ST.Array.length a0 == Steel.ST.Array.length a1 } -> Steel.ST.Effect.ST Prims.bool
{ "end_col": 12, "end_line": 113, "start_col": 3, "start_line": 109 }
Prims.Tot
val atom:eqtype
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let atom : eqtype = int
val atom:eqtype let atom:eqtype =
false
null
false
int
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "Prims.int" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val atom:eqtype
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.atom
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Prims.eqtype
{ "end_col": 23, "end_line": 41, "start_col": 20, "start_line": 41 }
Prims.Tot
val sort:permute
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<))
val sort:permute let sort:permute =
false
null
false
List.Tot.Base.sortWith #int (compare_of_bool ( < ))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.List.Tot.Base.sortWith", "Prims.int", "FStar.List.Tot.Base.compare_of_bool", "Prims.op_LessThan" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sort:permute
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.sort
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
FStar.Tactics.CanonCommMonoidSimple.Equiv.permute
{ "end_col": 70, "end_line": 224, "start_col": 21, "start_line": 224 }
FStar.Tactics.Effect.Tac
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let where = where_aux 0
let where =
true
null
false
where_aux 0
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.where_aux" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val where : x: FStar.Tactics.NamedView.term -> xs: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Prims.nat)
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.where
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.Tactics.NamedView.term -> xs: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Prims.nat)
{ "end_col": 23, "end_line": 275, "start_col": 12, "start_line": 275 }
Prims.Tot
val update (#a: Type) (x: atom) (xa: a) (am: amap a) : amap a
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am
val update (#a: Type) (x: atom) (xa: a) (am: amap a) : amap a let update (#a: Type) (x: atom) (xa: a) (am: amap a) : amap a =
false
null
false
(x, xa) :: fst am, snd am
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.Cons", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update (#a: Type) (x: atom) (xa: a) (am: amap a) : amap a
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.update
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> xa: a -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a
{ "end_col": 25, "end_line": 68, "start_col": 2, "start_line": 68 }
FStar.Tactics.Effect.Tac
val repeat_cong_right_identity (eq m: term) : Tac unit
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec repeat_cong_right_identity (eq: term) (m: term) : Tac unit = or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m )
val repeat_cong_right_identity (eq m: term) : Tac unit let rec repeat_cong_right_identity (eq m: term) : Tac unit =
true
null
false
or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.or_else", "Prims.unit", "FStar.Tactics.V2.Derived.apply_lemma", "FStar.Tactics.CanonCommMonoidSimple.Equiv.repeat_cong_right_identity", "FStar.Tactics.V2.Logic.split" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_cong_right_identity (eq m: term) : Tac unit
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.repeat_cong_right_identity
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Tactics.NamedView.term -> m: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 21, "end_line": 314, "start_col": 2, "start_line": 309 }
FStar.Tactics.Effect.Tac
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let term_eq = FStar.Tactics.term_eq_old
let term_eq =
true
null
false
FStar.Tactics.term_eq_old
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.V1.Builtins.term_eq_old" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val term_eq : _: FStar.Reflection.Types.term -> _: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.term_eq
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: FStar.Reflection.Types.term -> _: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
{ "end_col": 39, "end_line": 24, "start_col": 14, "start_line": 24 }
FStar.Tactics.Effect.Tac
val reification (eq m: term) (ts: list term) (am: amap term) (t: term) : Tac (exp * list term * amap term)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t
val reification (eq m: term) (ts: list term) (am: amap term) (t: term) : Tac (exp * list term * amap term) let reification (eq m: term) (ts: list term) (am: amap term) (t: term) : Tac (exp * list term * amap term) =
true
null
false
let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.CanonCommMonoidSimple.Equiv.reification_aux", "FStar.Pervasives.Native.tuple3", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Tactics.V2.Derived.norm_term", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "Prims.Nil", "FStar.Pervasives.delta" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reification (eq m: term) (ts: list term) (am: amap term) (t: term) : Tac (exp * list term * amap term)
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.reification
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Tactics.NamedView.term -> m: FStar.Tactics.NamedView.term -> ts: Prims.list FStar.Tactics.NamedView.term -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac ((FStar.Tactics.CanonCommMonoidSimple.Equiv.exp * Prims.list FStar.Tactics.NamedView.term) * FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term)
{ "end_col": 35, "end_line": 306, "start_col": 39, "start_line": 302 }
Prims.Tot
val sort_correct:permute_correct sort
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a)
val sort_correct:permute_correct sort let sort_correct:permute_correct sort =
false
null
false
(fun #a -> sort_correct_aux #a)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort_correct_aux", "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sort_correct:permute_correct sort
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.sort_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
FStar.Tactics.CanonCommMonoidSimple.Equiv.permute_correct FStar.Tactics.CanonCommMonoidSimple.Equiv.sort
{ "end_col": 73, "end_line": 236, "start_col": 42, "start_line": 236 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let permute = list atom -> list atom
let permute =
false
null
false
list atom -> list atom
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *)
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val permute : Type0
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.permute
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Type0
{ "end_col": 36, "end_line": 134, "start_col": 14, "start_line": 134 }
Prims.Tot
val select (#a: Type) (x: atom) (am: amap a) : Tot a
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am
val select (#a: Type) (x: atom) (am: amap a) : Tot a let select (#a: Type) (x: atom) (am: amap a) : Tot a =
false
null
false
match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.List.Tot.Base.assoc", "FStar.Pervasives.Native.fst", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.snd" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val select (#a: Type) (x: atom) (am: amap a) : Tot a
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.select
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> a
{ "end_col": 15, "end_line": 66, "start_col": 2, "start_line": 64 }
Prims.Tot
val const (#a: Type) (xa: a) : amap a
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let const (#a:Type) (xa:a) : amap a = ([], xa)
val const (#a: Type) (xa: a) : amap a let const (#a: Type) (xa: a) : amap a =
false
null
false
([], xa)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Pervasives.Native.Mktuple2", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "Prims.Nil", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val const (#a: Type) (xa: a) : amap a
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.const
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
xa: a -> FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a
{ "end_col": 46, "end_line": 62, "start_col": 38, "start_line": 62 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs))
let permute_correct (p: permute) =
false
null
false
#a: Type -> eq: equiv a -> m: cm a eq -> am: amap a -> xs: list atom -> Lemma (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (p xs)))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.permute", "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val permute_correct : p: FStar.Tactics.CanonCommMonoidSimple.Equiv.permute -> Type
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.permute_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
p: FStar.Tactics.CanonCommMonoidSimple.Equiv.permute -> Type
{ "end_col": 67, "end_line": 139, "start_col": 2, "start_line": 138 }
FStar.Pervasives.Lemma
val sort_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (sort xs)))
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs
val sort_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (sort xs))) let sort_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (sort xs))) =
false
null
true
permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommMonoidSimple.Equiv.permute_via_swaps_correct", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort_via_swaps", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_Exists", "FStar.Tactics.CanonCommSwaps.swaps_for", "Prims.eq2", "FStar.Tactics.CanonCommSwaps.apply_swaps", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sort_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (sort xs)))
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.sort_correct_aux
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am xs) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.sort xs)))
{ "end_col": 76, "end_line": 234, "start_col": 2, "start_line": 234 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let canon (e:exp) = sort (flatten e)
let canon (e: exp) =
false
null
false
sort (flatten e)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *)
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val canon : e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.canon
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom
{ "end_col": 36, "end_line": 240, "start_col": 20, "start_line": 240 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)
let permute_via_swaps (p: permute) =
false
null
false
#a: Type -> am: amap a -> xs: list atom -> Lemma (exists (ss: swaps_for xs). p xs == apply_swaps xs ss)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.permute", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_Exists", "FStar.Tactics.CanonCommSwaps.swaps_for", "Prims.eq2", "FStar.Tactics.CanonCommSwaps.apply_swaps", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss'))
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val permute_via_swaps : p: FStar.Tactics.CanonCommMonoidSimple.Equiv.permute -> Type
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.permute_via_swaps
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
p: FStar.Tactics.CanonCommMonoidSimple.Equiv.permute -> Type
{ "end_col": 63, "end_line": 204, "start_col": 2, "start_line": 203 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let amap (a:Type) = list (atom * a) * a
let amap (a: Type) =
false
null
false
list (atom * a) * a
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Pervasives.Native.tuple2", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b)
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val amap : a: Type -> Type
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.amap
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type -> Type
{ "end_col": 39, "end_line": 61, "start_col": 20, "start_line": 61 }
Prims.Tot
val convert_am (am: amap term) : term
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let convert_am (am : amap term) : term = let (map, def) = am in (* let def = norm_term [delta] def in *) `( (`#(convert_map map), `#def) )
val convert_am (am: amap term) : term let convert_am (am: amap term) : term =
false
null
false
let map, def = am in `(((`#(convert_map map)), (`#def)))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Reflection.Types.term", "FStar.Tactics.CanonCommMonoidSimple.Equiv.convert_map" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t let rec repeat_cong_right_identity (eq: term) (m: term) : Tac unit = or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m ) let rec convert_map (m : list (atom * term)) : term = match m with | [] -> `[] | (a, t)::ps -> let a = pack (Tv_Const (C_Int a)) in (* let t = norm_term [delta] t in *) `((`#a, (`#t)) :: (`#(convert_map ps))) (* `am` is an amap (basically a list) of terms, each representing a value of type `a` (whichever we are canonicalizing). This functions converts
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val convert_am (am: amap term) : term
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.convert_am
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term -> FStar.Tactics.NamedView.term
{ "end_col": 35, "end_line": 330, "start_col": 40, "start_line": 327 }
FStar.Tactics.Effect.Tac
val canon_lhs_rhs (eq m lhs rhs: term) : Tac unit
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let canon_lhs_rhs (eq: term) (m: term) (lhs rhs:term) : Tac unit = let m_unit = norm_term [iota; zeta; delta](`CM?.unit (`#m)) in let am = const m_unit in (* empty map *) let (r1, ts, am) = reification eq m [] am lhs in let (r2, _, am) = reification eq m ts am rhs in //dump ("am = " ^ term_to_string (quote am)); //dump ("r1 = " ^ term_to_string (norm_term [delta;primops] (quote (mdenote eq m am r1)))); //dump ("r2 = " ^ term_to_string (norm_term [delta;primops] (quote (mdenote eq m am r2)))); //dump ("before = " ^ term_to_string (norm_term [hnf;delta;primops] // (quote (mdenote eq m am r1 `EQ?.eq eq` mdenote eq m am r2)))); //dump ("current goal -- " ^ term_to_string (cur_goal ())); let am = convert_am am in let r1 = quote_exp r1 in let r2 = quote_exp r2 in change_sq (`(mdenote (`#eq) (`#m) (`#am) (`#r1) `EQ?.eq (`#eq)` mdenote (`#eq) (`#m) (`#am) (`#r2))); (* dump ("expected after = " ^ term_to_string (norm_term [delta;primops] *) (* (quote (xsdenote eq m am (canon r1) `EQ?.eq eq` *) (* xsdenote eq m am (canon r2))))); *) apply (`monoid_reflect); //dump ("after apply monoid_reflect"); norm [iota; zeta; delta_only [`%canon; `%xsdenote; `%flatten; `%sort; `%select; `%assoc; `%fst; `%__proj__Mktuple2__item___1; `%(@); `%append; `%List.Tot.sortWith; `%List.Tot.partition; `%bool_of_compare; `%compare_of_bool; ]; primops]; //dump "before refl"; or_else (fun _ -> apply_lemma (`(EQ?.reflexivity (`#eq)))) (fun _ -> repeat_cong_right_identity eq m)
val canon_lhs_rhs (eq m lhs rhs: term) : Tac unit let canon_lhs_rhs (eq m lhs rhs: term) : Tac unit =
true
null
false
let m_unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let am = const m_unit in let r1, ts, am = reification eq m [] am lhs in let r2, _, am = reification eq m ts am rhs in let am = convert_am am in let r1 = quote_exp r1 in let r2 = quote_exp r2 in change_sq (`(EQ?.eq (`#eq) (mdenote (`#eq) (`#m) (`#am) (`#r1)) (mdenote (`#eq) (`#m) (`#am) (`#r2)) )); apply (`monoid_reflect); norm [ iota; zeta; delta_only [ `%canon; `%xsdenote; `%flatten; `%sort; `%select; `%assoc; `%fst; `%__proj__Mktuple2__item___1; `%( @ ); `%append; `%List.Tot.sortWith; `%List.Tot.partition; `%bool_of_compare; `%compare_of_bool ]; primops ]; or_else (fun _ -> apply_lemma (`(EQ?.reflexivity (`#eq)))) (fun _ -> repeat_cong_right_identity eq m)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.V2.Derived.or_else", "Prims.unit", "FStar.Tactics.V2.Derived.apply_lemma", "FStar.Tactics.CanonCommMonoidSimple.Equiv.repeat_cong_right_identity", "FStar.Tactics.V2.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "FStar.Pervasives.primops", "FStar.Tactics.V2.Derived.apply", "FStar.Tactics.V2.Derived.change_sq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.quote_exp", "FStar.Tactics.CanonCommMonoidSimple.Equiv.convert_am", "FStar.Pervasives.Native.tuple3", "FStar.Tactics.CanonCommMonoidSimple.Equiv.reification", "FStar.Tactics.CanonCommMonoidSimple.Equiv.const", "FStar.Tactics.V2.Derived.norm_term", "FStar.Pervasives.delta" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t let rec repeat_cong_right_identity (eq: term) (m: term) : Tac unit = or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m ) let rec convert_map (m : list (atom * term)) : term = match m with | [] -> `[] | (a, t)::ps -> let a = pack (Tv_Const (C_Int a)) in (* let t = norm_term [delta] t in *) `((`#a, (`#t)) :: (`#(convert_map ps))) (* `am` is an amap (basically a list) of terms, each representing a value of type `a` (whichever we are canonicalizing). This functions converts `am` into a single `term` of type `amap a`, suitable to call `mdenote` with *) let convert_am (am : amap term) : term = let (map, def) = am in (* let def = norm_term [delta] def in *) `( (`#(convert_map map), `#def) ) let rec quote_exp (e:exp) : term = match e with | Unit -> (`Unit) | Mult e1 e2 -> (`Mult (`#(quote_exp e1)) (`#(quote_exp e2))) | Atom n -> let nt = pack (Tv_Const (C_Int n)) in (`Atom (`#nt))
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val canon_lhs_rhs (eq m lhs rhs: term) : Tac unit
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.canon_lhs_rhs
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Tactics.NamedView.term -> m: FStar.Tactics.NamedView.term -> lhs: FStar.Tactics.NamedView.term -> rhs: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 52, "end_line": 369, "start_col": 66, "start_line": 339 }
FStar.Tactics.Effect.Tac
val reification_aux (ts: list term) (am: amap term) (mult unit t: term) : Tac (exp * list term * amap term)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am
val reification_aux (ts: list term) (am: amap term) (mult unit t: term) : Tac (exp * list term * amap term) let rec reification_aux (ts: list term) (am: amap term) (mult unit t: term) : Tac (exp * list term * amap term) =
true
null
false
let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [t1, Q_Explicit ; t2, Q_Explicit] -> if term_eq (pack (Tv_FVar fv)) mult then (let e1, ts, am = reification_aux ts am mult unit t1 in let e2, ts, am = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "Prims.list", "FStar.Tactics.NamedView.term", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Reflection.V2.Data.argv", "FStar.Reflection.Types.fv", "FStar.Reflection.Types.term", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Pervasives.Native.Mktuple3", "FStar.Tactics.CanonCommMonoidSimple.Equiv.Mult", "FStar.Pervasives.Native.tuple3", "FStar.Tactics.CanonCommMonoidSimple.Equiv.reification_aux", "Prims.bool", "FStar.Tactics.CanonCommMonoidSimple.Equiv.fatom", "FStar.Tactics.CanonCommMonoidSimple.Equiv.term_eq", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_FVar", "FStar.Tactics.NamedView.named_term_view", "FStar.Pervasives.Native.tuple2", "FStar.Reflection.V2.Data.aqualv", "FStar.Tactics.CanonCommMonoidSimple.Equiv.Unit", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.inspect", "FStar.Tactics.V2.SyntaxHelpers.collect_app" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reification_aux (ts: list term) (am: amap term) (mult unit t: term) : Tac (exp * list term * amap term)
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.reification_aux
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
ts: Prims.list FStar.Tactics.NamedView.term -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term -> mult: FStar.Tactics.NamedView.term -> unit: FStar.Tactics.NamedView.term -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac ((FStar.Tactics.CanonCommMonoidSimple.Equiv.exp * Prims.list FStar.Tactics.NamedView.term) * FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term)
{ "end_col": 22, "end_line": 299, "start_col": 82, "start_line": 287 }
Prims.Tot
val exp_to_string (e: exp) : string
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")"
val exp_to_string (e: exp) : string let rec exp_to_string (e: exp) : string =
false
null
false
match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")"
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "Prims.op_Hat", "Prims.string_of_int", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp_to_string", "Prims.string" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val exp_to_string (e: exp) : string
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.exp_to_string
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> Prims.string
{ "end_col": 51, "end_line": 53, "start_col": 2, "start_line": 49 }
FStar.Pervasives.Lemma
val canon_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (canon e)))
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e)))
val canon_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (canon e))) let canon_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (canon e))) =
false
null
true
flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e)))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__transitivity", "FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort", "Prims.unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort_correct", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten_correct", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.canon", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val canon_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (canon e)))
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.canon_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote eq m am e) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.canon e)))
{ "end_col": 59, "end_line": 248, "start_col": 2, "start_line": 244 }
Prims.Tot
val xsdenote (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : a
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs')
val xsdenote (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : a let rec xsdenote (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : a =
false
null
false
match xs with | [] -> CM?.unit m | [x] -> select x am | x :: xs' -> CM?.mult m (select x am) (xsdenote eq m am xs')
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.select", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val xsdenote (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) : a
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> a
{ "end_col": 61, "end_line": 80, "start_col": 2, "start_line": 77 }
Prims.Tot
val flatten (e: exp) : list atom
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2
val flatten (e: exp) : list atom let rec flatten (e: exp) : list atom =
false
null
false
match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "Prims.Nil", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "Prims.Cons", "FStar.List.Tot.Base.op_At", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten", "Prims.list" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *)
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val flatten (e: exp) : list atom
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom
{ "end_col": 41, "end_line": 88, "start_col": 2, "start_line": 85 }
FStar.Pervasives.Lemma
val sort_via_swaps (#a: Type) (am: amap a) (xs: list atom) : Lemma (exists (ss: swaps_for xs). sort xs == apply_swaps xs ss)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in ()
val sort_via_swaps (#a: Type) (am: amap a) (xs: list atom) : Lemma (exists (ss: swaps_for xs). sort xs == apply_swaps xs ss) let sort_via_swaps (#a: Type) (am: amap a) (xs: list atom) : Lemma (exists (ss: swaps_for xs). sort xs == apply_swaps xs ss) =
false
null
true
List.Tot.Properties.sortWith_permutation #int (compare_of_bool ( < )) xs; let ss = equal_counts_implies_swaps xs (sort xs) in ()
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommSwaps.swap", "FStar.List.Tot.Base.length", "FStar.Tactics.CanonCommSwaps.equal_counts_implies_swaps", "FStar.Tactics.CanonCommMonoidSimple.Equiv.sort", "Prims.unit", "FStar.List.Tot.Properties.sortWith_permutation", "Prims.int", "FStar.List.Tot.Base.compare_of_bool", "Prims.op_LessThan", "Prims.l_True", "Prims.squash", "Prims.l_Exists", "FStar.Tactics.CanonCommSwaps.swaps_for", "Prims.eq2", "FStar.Tactics.CanonCommSwaps.apply_swaps", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sort_via_swaps (#a: Type) (am: amap a) (xs: list atom) : Lemma (exists (ss: swaps_for xs). sort xs == apply_swaps xs ss)
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.sort_via_swaps
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> FStar.Pervasives.Lemma (ensures exists (ss: FStar.Tactics.CanonCommSwaps.swaps_for xs). FStar.Tactics.CanonCommMonoidSimple.Equiv.sort xs == FStar.Tactics.CanonCommSwaps.apply_swaps xs ss)
{ "end_col": 6, "end_line": 230, "start_col": 4, "start_line": 228 }
Prims.Tot
val quote_exp (e: exp) : term
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec quote_exp (e:exp) : term = match e with | Unit -> (`Unit) | Mult e1 e2 -> (`Mult (`#(quote_exp e1)) (`#(quote_exp e2))) | Atom n -> let nt = pack (Tv_Const (C_Int n)) in (`Atom (`#nt))
val quote_exp (e: exp) : term let rec quote_exp (e: exp) : term =
false
null
false
match e with | Unit -> (`Unit) | Mult e1 e2 -> (`Mult (`#(quote_exp e1)) (`#(quote_exp e2))) | Atom n -> let nt = pack (Tv_Const (C_Int n)) in (`Atom (`#nt))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Reflection.Types.term", "FStar.Tactics.CanonCommMonoidSimple.Equiv.quote_exp", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Const", "FStar.Reflection.V2.Data.C_Int" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t let rec repeat_cong_right_identity (eq: term) (m: term) : Tac unit = or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m ) let rec convert_map (m : list (atom * term)) : term = match m with | [] -> `[] | (a, t)::ps -> let a = pack (Tv_Const (C_Int a)) in (* let t = norm_term [delta] t in *) `((`#a, (`#t)) :: (`#(convert_map ps))) (* `am` is an amap (basically a list) of terms, each representing a value of type `a` (whichever we are canonicalizing). This functions converts `am` into a single `term` of type `amap a`, suitable to call `mdenote` with *) let convert_am (am : amap term) : term = let (map, def) = am in (* let def = norm_term [delta] def in *) `( (`#(convert_map map), `#def) )
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val quote_exp (e: exp) : term
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.quote_exp
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> FStar.Tactics.NamedView.term
{ "end_col": 30, "end_line": 337, "start_col": 4, "start_line": 333 }
FStar.Tactics.Effect.Tac
val where_aux (n: nat) (x: term) (xs: list term) : Tac (option nat)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs'
val where_aux (n: nat) (x: term) (xs: list term) : Tac (option nat) let rec where_aux (n: nat) (x: term) (xs: list term) : Tac (option nat) =
true
null
false
match xs with | [] -> None | x' :: xs' -> if term_eq x x' then Some n else where_aux (n + 1) x xs'
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "Prims.nat", "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "Prims.bool", "FStar.Tactics.CanonCommMonoidSimple.Equiv.where_aux", "Prims.op_Addition", "FStar.Tactics.CanonCommMonoidSimple.Equiv.term_eq" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) :
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val where_aux (n: nat) (x: term) (xs: list term) : Tac (option nat)
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.where_aux
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n: Prims.nat -> x: FStar.Tactics.NamedView.term -> xs: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Prims.nat)
{ "end_col": 69, "end_line": 274, "start_col": 2, "start_line": 272 }
FStar.Pervasives.Lemma
val monoid_reflect_orig (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e1 e2: exp) : Lemma (requires (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)))) (ensures (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2)))
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2)
val monoid_reflect_orig (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e1 e2: exp) : Lemma (requires (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)))) (ensures (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2))) let monoid_reflect_orig (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e1 e2: exp) : Lemma (requires (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)))) (ensures (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2))) =
false
null
true
canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__transitivity", "FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.canon", "Prims.unit", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__symmetry", "FStar.Tactics.CanonCommMonoidSimple.Equiv.canon_correct", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2)))
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val monoid_reflect_orig (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e1 e2: exp) : Lemma (requires (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)))) (ensures (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2)))
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.monoid_reflect_orig
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> e1: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> e2: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> FStar.Pervasives.Lemma (requires EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.canon e1)) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.canon e2))) (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote eq m am e1) (FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote eq m am e2))
{ "end_col": 42, "end_line": 261, "start_col": 2, "start_line": 253 }
FStar.Tactics.Effect.Tac
val fatom (t: term) (ts: list term) (am: amap term) : Tac (exp * list term * amap term)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am)
val fatom (t: term) (ts: list term) (am: amap term) : Tac (exp * list term * amap term) let fatom (t: term) (ts: list term) (am: amap term) : Tac (exp * list term * amap term) =
true
null
false
match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.nat", "FStar.Pervasives.Native.Mktuple3", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Tactics.CanonCommMonoidSimple.Equiv.Atom", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.op_At", "Prims.Cons", "Prims.Nil", "FStar.Tactics.CanonCommMonoidSimple.Equiv.update", "FStar.Tactics.V2.Derived.norm_term", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.option", "FStar.Tactics.CanonCommMonoidSimple.Equiv.where" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fatom (t: term) (ts: list term) (am: amap term) : Tac (exp * list term * amap term)
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.fatom
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Tactics.NamedView.term -> ts: Prims.list FStar.Tactics.NamedView.term -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac ((FStar.Tactics.CanonCommMonoidSimple.Equiv.exp * Prims.list FStar.Tactics.NamedView.term) * FStar.Tactics.CanonCommMonoidSimple.Equiv.amap FStar.Tactics.NamedView.term)
{ "end_col": 47, "end_line": 283, "start_col": 2, "start_line": 278 }
Prims.Tot
val monoid_reflect: #a: Type -> eq: equiv a -> m: cm a eq -> am: amap a -> e1: exp -> e2: exp -> squash (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2))) -> squash (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2))
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2
val monoid_reflect: #a: Type -> eq: equiv a -> m: cm a eq -> am: amap a -> e1: exp -> e2: exp -> squash (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2))) -> squash (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2)) let monoid_reflect (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e1: exp) (e2: exp) (_: squash (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)))) : squash (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2)) =
false
null
true
monoid_reflect_orig #a eq m am e1 e2
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.canon", "FStar.Tactics.CanonCommMonoidSimple.Equiv.monoid_reflect_orig", "FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2)))
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val monoid_reflect: #a: Type -> eq: equiv a -> m: cm a eq -> am: amap a -> e1: exp -> e2: exp -> squash (EQ?.eq eq (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2))) -> squash (EQ?.eq eq (mdenote eq m am e1) (mdenote eq m am e2))
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.monoid_reflect
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> e1: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> e2: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> _: Prims.squash (EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.canon e1)) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.canon e2))) -> Prims.squash (EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote eq m am e1) (FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote eq m am e2))
{ "end_col": 38, "end_line": 266, "start_col": 2, "start_line": 266 }
Prims.Tot
val convert_map (m: list (atom * term)) : term
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec convert_map (m : list (atom * term)) : term = match m with | [] -> `[] | (a, t)::ps -> let a = pack (Tv_Const (C_Int a)) in (* let t = norm_term [delta] t in *) `((`#a, (`#t)) :: (`#(convert_map ps)))
val convert_map (m: list (atom * term)) : term let rec convert_map (m: list (atom * term)) : term =
false
null
false
match m with | [] -> `[] | (a, t) :: ps -> let a = pack (Tv_Const (C_Int a)) in `(((`#a), (`#t)) :: (`#(convert_map ps)))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.NamedView.term", "FStar.Reflection.Types.term", "FStar.Tactics.CanonCommMonoidSimple.Equiv.convert_map", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Const", "FStar.Reflection.V2.Data.C_Int" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t let rec repeat_cong_right_identity (eq: term) (m: term) : Tac unit = or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m )
false
true
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val convert_map (m: list (atom * term)) : term
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.convert_map
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
m: Prims.list (FStar.Tactics.CanonCommMonoidSimple.Equiv.atom * FStar.Tactics.NamedView.term) -> FStar.Tactics.NamedView.term
{ "end_col": 45, "end_line": 322, "start_col": 2, "start_line": 317 }
FStar.Pervasives.Lemma
val apply_swaps_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (ss: list (swap (length xs))) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swaps xs ss)))) (decreases ss)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss'))
val apply_swaps_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (ss: list (swap (length xs))) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swaps xs ss)))) (decreases ss) let rec apply_swaps_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (ss: list (swap (length xs))) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swaps xs ss)))) (decreases ss) =
false
null
true
match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s :: ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss'))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma", "" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommSwaps.swap", "FStar.List.Tot.Base.length", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__reflexivity", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__transitivity", "FStar.Tactics.CanonCommSwaps.apply_swap", "FStar.Tactics.CanonCommSwaps.apply_swaps", "Prims.unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swaps_correct", "FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swap_correct", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss)))
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val apply_swaps_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (ss: list (swap (length xs))) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swaps xs ss)))) (decreases ss)
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swaps_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> ss: Prims.list (FStar.Tactics.CanonCommSwaps.swap (FStar.List.Tot.Base.length xs)) -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am xs) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommSwaps.apply_swaps xs ss))) (decreases ss)
{ "end_col": 80, "end_line": 200, "start_col": 2, "start_line": 193 }
FStar.Pervasives.Lemma
val flatten_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (flatten e)))
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2))
val flatten_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (flatten e))) let rec flatten_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (flatten e))) =
false
null
true
match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__reflexivity", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommMonoidSimple.Equiv.select", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__transitivity", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult", "FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten", "FStar.List.Tot.Base.op_At", "Prims.unit", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__congruence", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten_correct", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__symmetry", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten_correct_aux", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val flatten_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : Lemma (EQ?.eq eq (mdenote eq m am e) (xsdenote eq m am (flatten e)))
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote eq m am e) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten e)))
{ "end_col": 70, "end_line": 129, "start_col": 2, "start_line": 116 }
Prims.Tot
val mdenote (#a: Type u#aa) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : a
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)
val mdenote (#a: Type u#aa) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : a let rec mdenote (#a: Type u#aa) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : a =
false
null
false
match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "total" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "FStar.Tactics.CanonCommMonoidSimple.Equiv.exp", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommMonoidSimple.Equiv.select", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult", "FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mdenote (#a: Type u#aa) (eq: equiv a) (m: cm a eq) (am: amap a) (e: exp) : a
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.mdenote
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> e: FStar.Tactics.CanonCommMonoidSimple.Equiv.exp -> a
{ "end_col": 70, "end_line": 74, "start_col": 2, "start_line": 71 }
FStar.Pervasives.Lemma
val apply_swap_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs)) : Lemma (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)))) (decreases xs)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s
val apply_swap_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs)) : Lemma (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)))) (decreases xs) let apply_swap_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs)) : Lemma (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)))) (decreases xs) =
false
null
true
apply_swap_aux_correct 0 eq m am xs s
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma", "" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommSwaps.swap", "FStar.List.Tot.Base.length", "FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swap_aux_correct", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "FStar.Tactics.CanonCommSwaps.apply_swap", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s)))
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val apply_swap_correct (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs)) : Lemma (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)))) (decreases xs)
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swap_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> s: FStar.Tactics.CanonCommSwaps.swap (FStar.List.Tot.Base.length xs) -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am xs) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommSwaps.apply_swap xs s))) (decreases xs)
{ "end_col": 39, "end_line": 186, "start_col": 2, "start_line": 186 }
FStar.Pervasives.Lemma
val flatten_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs1 xs2: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am (xs1 @ xs2)) (CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)))
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2))
val flatten_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs1 xs2: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am (xs1 @ xs2)) (CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2))) let rec flatten_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs1 xs2: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am (xs1 @ xs2)) (CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2))) =
false
null
true
match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> (if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x :: xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma" ]
[ "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__symmetry", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "Prims.unit", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__identity", "Prims.uu___is_Nil", "FStar.Tactics.CanonCommMonoidSimple.Equiv.select", "FStar.Algebra.CommMonoid.Equiv.right_identity", "Prims.bool", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__reflexivity", "Prims.Cons", "Prims.Nil", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__transitivity", "FStar.List.Tot.Base.op_At", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__associativity", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__congruence", "FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten_correct_aux", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1)
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val flatten_correct_aux (#a: Type) (eq: equiv a) (m: cm a eq) (am: amap a) (xs1 xs2: list atom) : Lemma (EQ?.eq eq (xsdenote eq m am (xs1 @ xs2)) (CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)))
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.flatten_correct_aux
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs1: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> xs2: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (xs1 @ xs2)) (CM?.mult m (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am xs1) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am xs2)))
{ "end_col": 112, "end_line": 112, "start_col": 2, "start_line": 93 }
FStar.Tactics.Effect.Tac
val canon_monoid (eq m: term) : Tac unit
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let canon_monoid (eq: term) (m: term) : Tac unit = norm [iota; zeta]; let t = cur_goal () in // removing top-level squash application let sq, rel_xy = collect_app t in // unpacking the application of the equivalence relation (lhs `EQ?.eq eq` rhs) (match rel_xy with | [(rel_xy,_)] -> ( let rel, xy = collect_app rel_xy in if (length xy >= 2) then ( match FStar.List.Tot.Base.index xy (length xy - 2) , FStar.List.Tot.index xy (length xy - 1) with | (lhs, Q_Explicit) , (rhs, Q_Explicit) -> canon_lhs_rhs eq m lhs rhs | _ -> fail "Goal should have been an application of a binary relation to 2 explicit arguments" ) else ( fail "Goal should have been an application of a binary relation to n implicit and 2 explicit arguments" ) ) | _ -> fail "Goal should be squash applied to a binary relation")
val canon_monoid (eq m: term) : Tac unit let canon_monoid (eq m: term) : Tac unit =
true
null
false
norm [iota; zeta]; let t = cur_goal () in let sq, rel_xy = collect_app t in (match rel_xy with | [rel_xy, _] -> (let rel, xy = collect_app rel_xy in if (length xy >= 2) then (match FStar.List.Tot.Base.index xy (length xy - 2), FStar.List.Tot.index xy (length xy - 1) with | (lhs, Q_Explicit), (rhs, Q_Explicit) -> canon_lhs_rhs eq m lhs rhs | _ -> fail "Goal should have been an application of a binary relation to 2 explicit arguments" ) else (fail "Goal should have been an application of a binary relation to n implicit and 2 explicit arguments" )) | _ -> fail "Goal should be squash applied to a binary relation")
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[]
[ "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Reflection.V2.Data.argv", "FStar.Reflection.Types.term", "FStar.Reflection.V2.Data.aqualv", "Prims.op_GreaterThanOrEqual", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.index", "Prims.op_Subtraction", "FStar.Tactics.CanonCommMonoidSimple.Equiv.canon_lhs_rhs", "Prims.unit", "FStar.Tactics.V2.Derived.fail", "Prims.bool", "FStar.Tactics.V2.SyntaxHelpers.collect_app", "FStar.Reflection.Types.typ", "FStar.Tactics.V2.Derived.cur_goal", "FStar.Tactics.V2.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "Prims.Nil" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s))) let apply_swap_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs)) : Lemma (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap xs s))) (decreases xs) = apply_swap_aux_correct 0 eq m am xs s let rec apply_swaps_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (ss:list (swap (length xs))) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swaps xs ss))) (decreases ss) = match ss with | [] -> EQ?.reflexivity eq (xsdenote eq m am xs) | s::ss' -> apply_swap_correct eq m am xs s; apply_swaps_correct eq m am (apply_swap xs s) ss'; EQ?.transitivity eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap xs s)) (xsdenote eq m am (apply_swaps (apply_swap xs s) ss')) let permute_via_swaps (p:permute) = (#a:Type) -> (am:amap a) -> xs:list atom -> Lemma (exists (ss:swaps_for xs). p xs == apply_swaps xs ss) let permute_via_swaps_correct_aux (p:permute) (pvs:permute_via_swaps p) (#a:Type) (eq:equiv a)(m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) = pvs am xs; assert(exists (ss:swaps_for xs). p xs == apply_swaps xs ss); exists_elim (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) (() <: squash (exists (ss:swaps_for xs). p xs == apply_swaps xs ss)) (fun ss -> apply_swaps_correct eq m am xs ss) let permute_via_swaps_correct (p:permute) (pvs:permute_via_swaps p) : permute_correct p = fun #a -> permute_via_swaps_correct_aux p pvs #a (***** Sorting atoms is a correct permutation (since it can be done by swaps) *) // Here we sort the variable numbers let sort : permute = List.Tot.Base.sortWith #int (compare_of_bool (<)) let sort_via_swaps (#a:Type) (am:amap a) (xs:list atom) : Lemma (exists (ss:swaps_for xs). sort xs == apply_swaps xs ss) = List.Tot.Properties.sortWith_permutation #int (compare_of_bool (<)) xs; let ss = equal_counts_implies_swaps xs (sort xs) in () let sort_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (sort xs)) = permute_via_swaps_correct sort (fun #a am -> sort_via_swaps am) eq m am xs let sort_correct : permute_correct sort = (fun #a -> sort_correct_aux #a) (***** Canonicalization tactics *) let canon (e:exp) = sort (flatten e) let canon_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (canon e)) = flatten_correct eq m am e; sort_correct eq m am (flatten e); EQ?.transitivity eq (mdenote eq m am e) (xsdenote eq m am (flatten e)) (xsdenote eq m am (sort (flatten e))) let monoid_reflect_orig (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) : Lemma (requires (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) (ensures (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2)) = canon_correct eq m am e1; canon_correct eq m am e2; EQ?.symmetry eq (mdenote eq m am e2) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e1)) (xsdenote eq m am (canon e2)); EQ?.transitivity eq (mdenote eq m am e1) (xsdenote eq m am (canon e2)) (mdenote eq m am e2) let monoid_reflect (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e1 e2:exp) (_ : squash (xsdenote eq m am (canon e1) `EQ?.eq eq` xsdenote eq m am (canon e2))) : squash (mdenote eq m am e1 `EQ?.eq eq` mdenote eq m am e2) = monoid_reflect_orig #a eq m am e1 e2 (* Finds the position of first occurrence of x in xs. This is now specialized to terms and their funny term_eq. *) let rec where_aux (n:nat) (x:term) (xs:list term) : Tac (option nat) = match xs with | [] -> None | x'::xs' -> if term_eq x x' then Some n else where_aux (n+1) x xs' let where = where_aux 0 let fatom (t:term) (ts:list term) (am:amap term) : Tac (exp * list term * amap term) = match where t ts with | Some v -> (Atom v, ts, am) | None -> let vfresh = length ts in let t = norm_term [iota; zeta] t in (Atom vfresh, ts @ [t], update vfresh t am) // This expects that mult, unit, and t have already been normalized let rec reification_aux (ts:list term) (am:amap term) (mult unit t : term) : Tac (exp * list term * amap term) = let hd, tl = collect_app t in match inspect hd, tl with | Tv_FVar fv, [(t1, Q_Explicit) ; (t2, Q_Explicit)] -> if term_eq (pack (Tv_FVar fv)) mult then (let (e1, ts, am) = reification_aux ts am mult unit t1 in let (e2, ts, am) = reification_aux ts am mult unit t2 in (Mult e1 e2, ts, am)) else fatom t ts am | _, _ -> if term_eq t unit then (Unit, ts, am) else fatom t ts am let reification (eq: term) (m: term) (ts:list term) (am:amap term) (t:term) : Tac (exp * list term * amap term) = let mult = norm_term [iota; zeta; delta] (`CM?.mult (`#m)) in let unit = norm_term [iota; zeta; delta] (`CM?.unit (`#m)) in let t = norm_term [iota; zeta] t in reification_aux ts am mult unit t let rec repeat_cong_right_identity (eq: term) (m: term) : Tac unit = or_else (fun _ -> apply_lemma (`right_identity)) (fun _ -> apply_lemma (`CM?.congruence (`#m)); split (); apply_lemma (`EQ?.reflexivity (`#eq)); repeat_cong_right_identity eq m ) let rec convert_map (m : list (atom * term)) : term = match m with | [] -> `[] | (a, t)::ps -> let a = pack (Tv_Const (C_Int a)) in (* let t = norm_term [delta] t in *) `((`#a, (`#t)) :: (`#(convert_map ps))) (* `am` is an amap (basically a list) of terms, each representing a value of type `a` (whichever we are canonicalizing). This functions converts `am` into a single `term` of type `amap a`, suitable to call `mdenote` with *) let convert_am (am : amap term) : term = let (map, def) = am in (* let def = norm_term [delta] def in *) `( (`#(convert_map map), `#def) ) let rec quote_exp (e:exp) : term = match e with | Unit -> (`Unit) | Mult e1 e2 -> (`Mult (`#(quote_exp e1)) (`#(quote_exp e2))) | Atom n -> let nt = pack (Tv_Const (C_Int n)) in (`Atom (`#nt)) let canon_lhs_rhs (eq: term) (m: term) (lhs rhs:term) : Tac unit = let m_unit = norm_term [iota; zeta; delta](`CM?.unit (`#m)) in let am = const m_unit in (* empty map *) let (r1, ts, am) = reification eq m [] am lhs in let (r2, _, am) = reification eq m ts am rhs in //dump ("am = " ^ term_to_string (quote am)); //dump ("r1 = " ^ term_to_string (norm_term [delta;primops] (quote (mdenote eq m am r1)))); //dump ("r2 = " ^ term_to_string (norm_term [delta;primops] (quote (mdenote eq m am r2)))); //dump ("before = " ^ term_to_string (norm_term [hnf;delta;primops] // (quote (mdenote eq m am r1 `EQ?.eq eq` mdenote eq m am r2)))); //dump ("current goal -- " ^ term_to_string (cur_goal ())); let am = convert_am am in let r1 = quote_exp r1 in let r2 = quote_exp r2 in change_sq (`(mdenote (`#eq) (`#m) (`#am) (`#r1) `EQ?.eq (`#eq)` mdenote (`#eq) (`#m) (`#am) (`#r2))); (* dump ("expected after = " ^ term_to_string (norm_term [delta;primops] *) (* (quote (xsdenote eq m am (canon r1) `EQ?.eq eq` *) (* xsdenote eq m am (canon r2))))); *) apply (`monoid_reflect); //dump ("after apply monoid_reflect"); norm [iota; zeta; delta_only [`%canon; `%xsdenote; `%flatten; `%sort; `%select; `%assoc; `%fst; `%__proj__Mktuple2__item___1; `%(@); `%append; `%List.Tot.sortWith; `%List.Tot.partition; `%bool_of_compare; `%compare_of_bool; ]; primops]; //dump "before refl"; or_else (fun _ -> apply_lemma (`(EQ?.reflexivity (`#eq)))) (fun _ -> repeat_cong_right_identity eq m) [@@plugin]
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val canon_monoid (eq m: term) : Tac unit
[]
FStar.Tactics.CanonCommMonoidSimple.Equiv.canon_monoid
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
eq: FStar.Tactics.NamedView.term -> m: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 68, "end_line": 391, "start_col": 2, "start_line": 373 }
FStar.Pervasives.Lemma
val apply_swap_aux_correct (#a: Type) (n: nat) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs + n)) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap_aux n xs s)))) (decreases xs)
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSwaps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid.Equiv", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommMonoidSimple", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s))) (decreases xs) = match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1;x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1;x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then ( CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else ( apply_swap_aux_correct (n+1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n+1) (x2 :: xs') s)))
val apply_swap_aux_correct (#a: Type) (n: nat) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs + n)) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap_aux n xs s)))) (decreases xs) let rec apply_swap_aux_correct (#a: Type) (n: nat) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs + n)) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap_aux n xs s)))) (decreases xs) =
false
null
true
match xs with | [] -> EQ?.reflexivity eq (CM?.unit m) | [x] -> EQ?.reflexivity eq (select x am) | [x1 ; x2] -> if n = (s <: nat) then CM?.commutativity m (select x1 am) (select x2 am) else EQ?.reflexivity eq (xsdenote eq m am [x1; x2]) | x1 :: x2 :: xs' -> if n = (s <: nat) then (CM?.associativity m (select x1 am) (select x2 am) (xsdenote eq m am xs'); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))); CM?.commutativity m (select x1 am) (select x2 am); EQ?.reflexivity eq (xsdenote eq m am xs'); CM?.congruence m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs') (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs'); CM?.associativity m (select x2 am) (select x1 am) (xsdenote eq m am xs'); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x1 am) (select x2 am)) (xsdenote eq m am xs')) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')); EQ?.transitivity eq (CM?.mult m (select x1 am) (CM?.mult m (select x2 am) (xsdenote eq m am xs'))) (CM?.mult m (CM?.mult m (select x2 am) (select x1 am)) (xsdenote eq m am xs')) (CM?.mult m (select x2 am) (CM?.mult m (select x1 am) (xsdenote eq m am xs')))) else (apply_swap_aux_correct (n + 1) eq m am (x2 :: xs') s; EQ?.reflexivity eq (select x1 am); CM?.congruence m (select x1 am) (xsdenote eq m am (x2 :: xs')) (select x1 am) (xsdenote eq m am (apply_swap_aux (n + 1) (x2 :: xs') s)))
{ "checked_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.CanonCommSwaps.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Algebra.CommMonoid.Equiv.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.CanonCommMonoidSimple.Equiv.fst" }
[ "lemma", "" ]
[ "Prims.nat", "FStar.Algebra.CommMonoid.Equiv.equiv", "FStar.Algebra.CommMonoid.Equiv.cm", "FStar.Tactics.CanonCommMonoidSimple.Equiv.amap", "Prims.list", "FStar.Tactics.CanonCommMonoidSimple.Equiv.atom", "FStar.Tactics.CanonCommSwaps.swap", "Prims.op_Addition", "FStar.List.Tot.Base.length", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__reflexivity", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "FStar.Tactics.CanonCommMonoidSimple.Equiv.select", "Prims.op_Equality", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__commutativity", "Prims.bool", "FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote", "Prims.Cons", "Prims.Nil", "Prims.unit", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__transitivity", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__associativity", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__congruence", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__symmetry", "FStar.Tactics.CanonCommSwaps.apply_swap_aux", "FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swap_aux_correct", "Prims.l_True", "Prims.squash", "FStar.Algebra.CommMonoid.Equiv.__proj__EQ__item__eq", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.CanonCommMonoidSimple.Equiv open FStar.Algebra.CommMonoid.Equiv open FStar.List open FStar.Classical open FStar.Tactics.CanonCommSwaps open FStar.Tactics.V2 let term_eq = FStar.Tactics.term_eq_old (* A simple expression canonizer for commutative monoids (working up to some given equivalence relation as opposed to just propositional equality). For a canonizer with more features see FStar.Tactics.CanonCommMonoid.fst. Based on FStar.Tactics.CanonCommMonoidSimple.fst *) (* Only dump when debugging is on *) //let dump m = if debugging () then dump m (***** Expression syntax *) // GM: ugh, we had `nat`, but then we get bitten by lack // of subtyping over datatypes when we typecheck the amap term // we generate (see convert_am). let atom : eqtype = int type exp : Type = | Unit : exp | Mult : exp -> exp -> exp | Atom : atom -> exp let rec exp_to_string (e:exp) : string = match e with | Unit -> "Unit" | Atom x -> "Atom " ^ string_of_int (x <: atom) | Mult e1 e2 -> "Mult (" ^ exp_to_string e1 ^ ") (" ^ exp_to_string e2 ^ ")" (***** Expression denotation *) // Use a map that stores for each atom // (1) its denotation that should be treated abstractly (type a) and // (2) user-specified extra information depending on its term (type b) let amap (a:Type) = list (atom * a) * a let const (#a:Type) (xa:a) : amap a = ([], xa) let select (#a:Type) (x:atom) (am:amap a) : Tot a = match assoc #atom #a x (fst am) with | Some a -> a | _ -> snd am let update (#a:Type) (x:atom) (xa:a) (am:amap a) : amap a = (x, xa)::fst am, snd am let rec mdenote (#a:Type u#aa) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : a = match e with | Unit -> CM?.unit m | Atom x -> select x am | Mult e1 e2 -> CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2) let rec xsdenote (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) : a = match xs with | [] -> CM?.unit m | [x] -> select x am | x::xs' -> CM?.mult m (select x am) (xsdenote eq m am xs') (***** Flattening expressions to lists of atoms *) let rec flatten (e:exp) : list atom = match e with | Unit -> [] | Atom x -> [x] | Mult e1 e2 -> flatten e1 @ flatten e2 let rec flatten_correct_aux (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (xs1 xs2:list atom) : Lemma (xsdenote eq m am (xs1 @ xs2) `EQ?.eq eq` CM?.mult m (xsdenote eq m am xs1) (xsdenote eq m am xs2)) = match xs1 with | [] -> CM?.identity m (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.unit m) (xsdenote eq m am xs2)) (xsdenote eq m am xs2) | [x] -> ( if (Nil? xs2) then (right_identity eq m (select x am); EQ?.symmetry eq (CM?.mult m (select x am) (CM?.unit m)) (select x am)) else EQ?.reflexivity eq (CM?.mult m (xsdenote eq m am [x]) (xsdenote eq m am xs2))) | x::xs1' -> flatten_correct_aux eq m am xs1' xs2; EQ?.reflexivity eq (select x am); CM?.congruence m (select x am) (xsdenote eq m am (xs1' @ xs2)) (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2)); CM?.associativity m (select x am) (xsdenote eq m am xs1') (xsdenote eq m am xs2); EQ?.symmetry eq (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))); EQ?.transitivity eq (CM?.mult m (select x am) (xsdenote eq m am (xs1' @ xs2))) (CM?.mult m (select x am) (CM?.mult m (xsdenote eq m am xs1') (xsdenote eq m am xs2))) (CM?.mult m (CM?.mult m (select x am) (xsdenote eq m am xs1')) (xsdenote eq m am xs2)) let rec flatten_correct (#a:Type) (eq:equiv a) (m:cm a eq) (am:amap a) (e:exp) : Lemma (mdenote eq m am e `EQ?.eq eq` xsdenote eq m am (flatten e)) = match e with | Unit -> EQ?.reflexivity eq (CM?.unit m) | Atom x -> EQ?.reflexivity eq (select x am) | Mult e1 e2 -> flatten_correct_aux eq m am (flatten e1) (flatten e2); EQ?.symmetry eq (xsdenote eq m am (flatten e1 @ flatten e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))); flatten_correct eq m am e1; flatten_correct eq m am e2; CM?.congruence m (mdenote eq m am e1) (mdenote eq m am e2) (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2)); EQ?.transitivity eq (CM?.mult m (mdenote eq m am e1) (mdenote eq m am e2)) (CM?.mult m (xsdenote eq m am (flatten e1)) (xsdenote eq m am (flatten e2))) (xsdenote eq m am (flatten e1 @ flatten e2)) (***** Permuting the lists of atoms by swapping adjacent elements *) let permute = list atom -> list atom // high-level correctness criterion for permutations let permute_correct (p:permute) = #a:Type -> eq:equiv a -> m:cm a eq -> am:amap a -> xs:list atom -> Lemma (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (p xs)) // sufficient condition: // permutation has to be expressible as swaps of adjacent list elements // In the general case, an arbitrary permutation can be done via swaps. // (see FStar.Tactics.CanonCommSwaps for a proof) let rec apply_swap_aux_correct (#a:Type) (n:nat) (eq:equiv a) (m:cm a eq) (am:amap a) (xs:list atom) (s:swap (length xs + n)) : Lemma (requires True) (ensures (xsdenote eq m am xs `EQ?.eq eq` xsdenote eq m am (apply_swap_aux n xs s)))
false
false
FStar.Tactics.CanonCommMonoidSimple.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val apply_swap_aux_correct (#a: Type) (n: nat) (eq: equiv a) (m: cm a eq) (am: amap a) (xs: list atom) (s: swap (length xs + n)) : Lemma (requires True) (ensures (EQ?.eq eq (xsdenote eq m am xs) (xsdenote eq m am (apply_swap_aux n xs s)))) (decreases xs)
[ "recursion" ]
FStar.Tactics.CanonCommMonoidSimple.Equiv.apply_swap_aux_correct
{ "file_name": "ulib/FStar.Tactics.CanonCommMonoidSimple.Equiv.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n: Prims.nat -> eq: FStar.Algebra.CommMonoid.Equiv.equiv a -> m: FStar.Algebra.CommMonoid.Equiv.cm a eq -> am: FStar.Tactics.CanonCommMonoidSimple.Equiv.amap a -> xs: Prims.list FStar.Tactics.CanonCommMonoidSimple.Equiv.atom -> s: FStar.Tactics.CanonCommSwaps.swap (FStar.List.Tot.Base.length xs + n) -> FStar.Pervasives.Lemma (ensures EQ?.eq eq (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am xs) (FStar.Tactics.CanonCommMonoidSimple.Equiv.xsdenote eq m am (FStar.Tactics.CanonCommSwaps.apply_swap_aux n xs s))) (decreases xs)
{ "end_col": 96, "end_line": 180, "start_col": 2, "start_line": 152 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let t = input_stream_base
let t =
false
null
false
input_stream_base
{ "checked_file": "EverParse3d.InputStream.Extern.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Extern.Base.fsti" }
[ "total" ]
[ "EverParse3d.InputStream.Extern.Base.input_stream_base" ]
[]
module EverParse3d.InputStream.Extern.Base module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module U8 = FStar.UInt8 module LPE = EverParse3d.ErrorCode module U64 = FStar.UInt64 val input_stream_base : Type0 inline_for_extraction
false
true
EverParse3d.InputStream.Extern.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t : Type0
[]
EverParse3d.InputStream.Extern.Base.t
{ "file_name": "src/3d/prelude/extern/EverParse3d.InputStream.Extern.Base.fsti", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type0
{ "end_col": 25, "end_line": 15, "start_col": 8, "start_line": 15 }
Prims.Tot
val createEmpty (#a: Type) : Tot (s: (seq a){length s = 0})
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "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 } ]
false
let createEmpty (#a:Type) : Tot (s:(seq a){length s=0}) = empty #a
val createEmpty (#a: Type) : Tot (s: (seq a){length s = 0}) let createEmpty (#a: Type) : Tot (s: (seq a){length s = 0}) =
false
null
false
empty #a
{ "checked_file": "FStar.Seq.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Seq.Base.fsti" }
[ "total" ]
[ "FStar.Seq.Base.empty", "FStar.Seq.Base.seq", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length" ]
[]
(* Copyright 2008-2014 Nikhil Swamy and Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) (* A logical theory of sequences indexed by natural numbers in [0, n) *) module FStar.Seq.Base //#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1" module List = FStar.List.Tot new val seq ([@@@strictly_positive] a : Type u#a) : Type u#a (* Destructors *) val length: #a:Type -> seq a -> Tot nat val index: #a:Type -> s:seq a -> i:nat{i < length s} -> Tot a val create: #a:Type -> nat -> a -> Tot (seq a) private val init_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a)) :Tot (seq a) inline_for_extraction val init: #a:Type -> len:nat -> contents: (i:nat { i < len } -> Tot a) -> Tot (seq a) private val init_aux_ghost (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a)) : GTot (seq a) inline_for_extraction val init_ghost: #a:Type -> len:nat -> contents: (i:nat { i < len } -> GTot a) -> GTot (seq a) val empty (#a:Type) : Tot (s:(seq a){length s=0}) [@@(deprecated "Seq.empty")] unfold let createEmpty (#a:Type)
false
false
FStar.Seq.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val createEmpty (#a: Type) : Tot (s: (seq a){length s = 0})
[]
FStar.Seq.Base.createEmpty
{ "file_name": "ulib/FStar.Seq.Base.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s = 0}
{ "end_col": 14, "end_line": 48, "start_col": 6, "start_line": 48 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "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 } ]
false
let op_At_Bar (#a:Type) (s1:seq a) (s2:seq a) = append s1 s2
let op_At_Bar (#a: Type) (s1 s2: seq a) =
false
null
false
append s1 s2
{ "checked_file": "FStar.Seq.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Seq.Base.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "FStar.Seq.Base.append" ]
[]
(* Copyright 2008-2014 Nikhil Swamy and Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) (* A logical theory of sequences indexed by natural numbers in [0, n) *) module FStar.Seq.Base //#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1" module List = FStar.List.Tot new val seq ([@@@strictly_positive] a : Type u#a) : Type u#a (* Destructors *) val length: #a:Type -> seq a -> Tot nat val index: #a:Type -> s:seq a -> i:nat{i < length s} -> Tot a val create: #a:Type -> nat -> a -> Tot (seq a) private val init_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a)) :Tot (seq a) inline_for_extraction val init: #a:Type -> len:nat -> contents: (i:nat { i < len } -> Tot a) -> Tot (seq a) private val init_aux_ghost (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a)) : GTot (seq a) inline_for_extraction val init_ghost: #a:Type -> len:nat -> contents: (i:nat { i < len } -> GTot a) -> GTot (seq a) val empty (#a:Type) : Tot (s:(seq a){length s=0}) [@@(deprecated "Seq.empty")] unfold let createEmpty (#a:Type) : Tot (s:(seq a){length s=0}) = empty #a val lemma_empty (#a:Type) (s:seq a) : Lemma (length s = 0 ==> s == empty #a) val upd: #a:Type -> s:seq a -> n:nat{n < length s} -> a -> Tot (seq a) val append: #a:Type -> seq a -> seq a -> Tot (seq a)
false
false
FStar.Seq.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_At_Bar : s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> FStar.Seq.Base.seq a
[]
FStar.Seq.Base.op_At_Bar
{ "file_name": "ulib/FStar.Seq.Base.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> FStar.Seq.Base.seq a
{ "end_col": 60, "end_line": 56, "start_col": 48, "start_line": 56 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "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 } ]
false
let lbignum = Hacl.Bignum.Definitions.lbignum
let lbignum =
false
null
false
Hacl.Bignum.Definitions.lbignum
{ "checked_file": "Hacl.Bignum32.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Bignum.SafeAPI.fst.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum32.fsti" }
[ "total" ]
[ "Hacl.Bignum.Definitions.lbignum" ]
[]
module Hacl.Bignum32 open FStar.Mul module BN = Hacl.Bignum module BS = Hacl.Bignum.SafeAPI module MA = Hacl.Bignum.MontArithmetic #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let t_limbs: Hacl.Bignum.Definitions.limb_t = Lib.IntTypes.U32
false
true
Hacl.Bignum32.fsti
{ "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" }
null
val lbignum : t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t -> Type0
[]
Hacl.Bignum32.lbignum
{ "file_name": "code/bignum/Hacl.Bignum32.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t -> Type0
{ "end_col": 45, "end_line": 15, "start_col": 14, "start_line": 15 }
Prims.Tot
val t_limbs:Hacl.Bignum.Definitions.limb_t
[ { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "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 } ]
false
let t_limbs: Hacl.Bignum.Definitions.limb_t = Lib.IntTypes.U32
val t_limbs:Hacl.Bignum.Definitions.limb_t let t_limbs:Hacl.Bignum.Definitions.limb_t =
false
null
false
Lib.IntTypes.U32
{ "checked_file": "Hacl.Bignum32.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Bignum.SafeAPI.fst.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum32.fsti" }
[ "total" ]
[ "Lib.IntTypes.U32" ]
[]
module Hacl.Bignum32 open FStar.Mul module BN = Hacl.Bignum module BS = Hacl.Bignum.SafeAPI module MA = Hacl.Bignum.MontArithmetic #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Bignum32.fsti
{ "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" }
null
val t_limbs:Hacl.Bignum.Definitions.limb_t
[]
Hacl.Bignum32.t_limbs
{ "file_name": "code/bignum/Hacl.Bignum32.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Bignum.Definitions.limb_t
{ "end_col": 62, "end_line": 12, "start_col": 46, "start_line": 12 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "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 } ]
false
let pbn_mont_ctx_u32 = MA.pbn_mont_ctx_u32
let pbn_mont_ctx_u32 =
false
null
false
MA.pbn_mont_ctx_u32
{ "checked_file": "Hacl.Bignum32.fsti.checked", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Bignum.SafeAPI.fst.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum32.fsti" }
[ "total" ]
[ "Hacl.Bignum.MontArithmetic.pbn_mont_ctx_u32" ]
[]
module Hacl.Bignum32 open FStar.Mul module BN = Hacl.Bignum module BS = Hacl.Bignum.SafeAPI module MA = Hacl.Bignum.MontArithmetic #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let t_limbs: Hacl.Bignum.Definitions.limb_t = Lib.IntTypes.U32 inline_for_extraction noextract let lbignum = Hacl.Bignum.Definitions.lbignum
false
true
Hacl.Bignum32.fsti
{ "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" }
null
val pbn_mont_ctx_u32 : Type0
[]
Hacl.Bignum32.pbn_mont_ctx_u32
{ "file_name": "code/bignum/Hacl.Bignum32.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 42, "end_line": 17, "start_col": 23, "start_line": 17 }
Prims.GTot
val createL_pre (#a: Type0) (init: list a) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let createL_pre (#a: Type0) (init: list a) : GTot Type0 = alloca_of_list_pre init
val createL_pre (#a: Type0) (init: list a) : GTot Type0 let createL_pre (#a: Type0) (init: list a) : GTot Type0 =
false
null
false
alloca_of_list_pre init
{ "checked_file": "LowStar.BufferCompat.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.BufferCompat.fst" }
[ "sometrivial" ]
[ "Prims.list", "LowStar.Monotonic.Buffer.alloca_of_list_pre" ]
[]
(* 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 LowStar.BufferCompat include LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module G = FStar.Ghost module Seq = FStar.Seq unfold let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem) (s:Seq.seq a) = alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ length b == len inline_for_extraction let rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b) )) = free b inline_for_extraction let rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b )) = let b = gcmalloc r init len in b inline_for_extraction let rcreate_mm (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ freeable b )) = malloc r init len inline_for_extraction let create (#a: Type) (init: a) (len: U32.t) : HST.StackInline (buffer a) (requires (fun h -> U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common (HS.get_tip h) (U32.v len) b h h' (Seq.create (U32.v len) init) )) = alloca init len
false
false
LowStar.BufferCompat.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val createL_pre (#a: Type0) (init: list a) : GTot Type0
[]
LowStar.BufferCompat.createL_pre
{ "file_name": "ulib/legacy/LowStar.BufferCompat.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
init: Prims.list a -> Prims.GTot Type0
{ "end_col": 25, "end_line": 92, "start_col": 2, "start_line": 92 }
FStar.HyperStack.ST.ST
val rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ (Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b) )) = free b
val rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ (Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b))) let rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ (Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b))) =
true
null
false
free b
{ "checked_file": "LowStar.BufferCompat.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.BufferCompat.fst" }
[]
[ "LowStar.Buffer.buffer", "LowStar.Monotonic.Buffer.free", "LowStar.Buffer.trivial_preorder", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.freeable", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "FStar.Set.equal", "FStar.Monotonic.HyperHeap.rid", "FStar.Map.domain", "FStar.Monotonic.Heap.heap", "FStar.Monotonic.HyperStack.get_hmap", "Prims.eq2", "FStar.Monotonic.HyperStack.get_tip", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "FStar.Monotonic.HyperStack.live_region", "LowStar.Monotonic.Buffer.frameOf" ]
[]
(* 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 LowStar.BufferCompat include LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module G = FStar.Ghost module Seq = FStar.Seq unfold let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem) (s:Seq.seq a) = alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ length b == len inline_for_extraction let rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b)
false
false
LowStar.BufferCompat.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ (Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b)))
[]
LowStar.BufferCompat.rfree
{ "file_name": "ulib/legacy/LowStar.BufferCompat.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.Buffer.buffer a -> FStar.HyperStack.ST.ST Prims.unit
{ "end_col": 8, "end_line": 48, "start_col": 2, "start_line": 48 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem) (s:Seq.seq a) = alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ length b == len
let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem) (s: Seq.seq a) =
false
null
false
alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ length b == len
{ "checked_file": "LowStar.BufferCompat.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.BufferCompat.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperHeap.rid", "Prims.nat", "LowStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "FStar.Seq.Base.seq", "Prims.l_and", "LowStar.Monotonic.Buffer.alloc_post_mem_common", "LowStar.Buffer.trivial_preorder", "Prims.eq2", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.length", "Prims.logical" ]
[]
(* 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 LowStar.BufferCompat include LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module G = FStar.Ghost module Seq = FStar.Seq unfold let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem)
false
false
LowStar.BufferCompat.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rcreate_post_mem_common : r: FStar.Monotonic.HyperHeap.rid -> len: Prims.nat -> b: LowStar.Buffer.buffer a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> s: FStar.Seq.Base.seq a -> Prims.logical
[]
LowStar.BufferCompat.rcreate_post_mem_common
{ "file_name": "ulib/legacy/LowStar.BufferCompat.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> len: Prims.nat -> b: LowStar.Buffer.buffer a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> s: FStar.Seq.Base.seq a -> Prims.logical
{ "end_col": 70, "end_line": 33, "start_col": 2, "start_line": 33 }
FStar.HyperStack.ST.StackInline
val createL (#a: Type0) (init: list a) : HST.StackInline (buffer a) (requires (fun h -> createL_pre #a init)) (ensures (fun h b h' -> let len = FStar.List.Tot.length init in rcreate_post_mem_common (HS.get_tip h) len b h h' (Seq.seq_of_list init) /\ length b == normalize_term (List.Tot.length init)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let createL (#a: Type0) (init: list a) : HST.StackInline (buffer a) (requires (fun h -> createL_pre #a init)) (ensures (fun h b h' -> let len = FStar.List.Tot.length init in rcreate_post_mem_common (HS.get_tip h) len b h h' (Seq.seq_of_list init) /\ length b == normalize_term (List.Tot.length init) )) = alloca_of_list init
val createL (#a: Type0) (init: list a) : HST.StackInline (buffer a) (requires (fun h -> createL_pre #a init)) (ensures (fun h b h' -> let len = FStar.List.Tot.length init in rcreate_post_mem_common (HS.get_tip h) len b h h' (Seq.seq_of_list init) /\ length b == normalize_term (List.Tot.length init))) let createL (#a: Type0) (init: list a) : HST.StackInline (buffer a) (requires (fun h -> createL_pre #a init)) (ensures (fun h b h' -> let len = FStar.List.Tot.length init in rcreate_post_mem_common (HS.get_tip h) len b h h' (Seq.seq_of_list init) /\ length b == normalize_term (List.Tot.length init))) =
true
null
false
alloca_of_list init
{ "checked_file": "LowStar.BufferCompat.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.BufferCompat.fst" }
[]
[ "Prims.list", "LowStar.Buffer.alloca_of_list", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.length", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "LowStar.BufferCompat.createL_pre", "LowStar.BufferCompat.rcreate_post_mem_common", "FStar.Monotonic.HyperStack.get_tip", "FStar.Seq.Properties.seq_of_list" ]
[]
(* 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 LowStar.BufferCompat include LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module G = FStar.Ghost module Seq = FStar.Seq unfold let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem) (s:Seq.seq a) = alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ length b == len inline_for_extraction let rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b) )) = free b inline_for_extraction let rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b )) = let b = gcmalloc r init len in b inline_for_extraction let rcreate_mm (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ freeable b )) = malloc r init len inline_for_extraction let create (#a: Type) (init: a) (len: U32.t) : HST.StackInline (buffer a) (requires (fun h -> U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common (HS.get_tip h) (U32.v len) b h h' (Seq.create (U32.v len) init) )) = alloca init len unfold let createL_pre (#a: Type0) (init: list a) : GTot Type0 = alloca_of_list_pre init let createL (#a: Type0) (init: list a) : HST.StackInline (buffer a) (requires (fun h -> createL_pre #a init)) (ensures (fun h b h' -> let len = FStar.List.Tot.length init in rcreate_post_mem_common (HS.get_tip h) len b h h' (Seq.seq_of_list init) /\ length b == normalize_term (List.Tot.length init)
false
false
LowStar.BufferCompat.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val createL (#a: Type0) (init: list a) : HST.StackInline (buffer a) (requires (fun h -> createL_pre #a init)) (ensures (fun h b h' -> let len = FStar.List.Tot.length init in rcreate_post_mem_common (HS.get_tip h) len b h h' (Seq.seq_of_list init) /\ length b == normalize_term (List.Tot.length init)))
[]
LowStar.BufferCompat.createL
{ "file_name": "ulib/legacy/LowStar.BufferCompat.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
init: Prims.list a -> FStar.HyperStack.ST.StackInline (LowStar.Buffer.buffer a)
{ "end_col": 21, "end_line": 104, "start_col": 2, "start_line": 104 }
FStar.HyperStack.ST.ST
val rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b )) = let b = gcmalloc r init len in b
val rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b)) let rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b)) =
true
null
false
let b = gcmalloc r init len in b
{ "checked_file": "LowStar.BufferCompat.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.BufferCompat.fst" }
[]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.UInt32.t", "LowStar.Buffer.buffer", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.recallable", "LowStar.Buffer.gcmalloc", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.is_eternal_region", "Prims.op_GreaterThan", "LowStar.BufferCompat.rcreate_post_mem_common", "FStar.Seq.Base.create" ]
[]
(* 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 LowStar.BufferCompat include LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module G = FStar.Ghost module Seq = FStar.Seq unfold let rcreate_post_mem_common (#a: Type) (r: HS.rid) (len: nat) (b: buffer a) (h0 h1: HS.mem) (s:Seq.seq a) = alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ length b == len inline_for_extraction let rfree (#a: Type) (b: buffer a) : HST.ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> (not (g_is_null b)) /\ Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\ (HS.get_tip h1) == (HS.get_tip h0) /\ modifies (loc_addr_of_buffer b) h0 h1 /\ HS.live_region h1 (frameOf b) )) = free b inline_for_extraction let rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b
false
false
LowStar.BufferCompat.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rcreate (#a: Type) (r: HS.rid) (init: a) (len: U32.t) : HST.ST (buffer a) (requires (fun h -> HST.is_eternal_region r /\ U32.v len > 0)) (ensures (fun h b h' -> rcreate_post_mem_common r (U32.v len) b h h' (Seq.create (U32.v len) init) /\ recallable b))
[]
LowStar.BufferCompat.rcreate
{ "file_name": "ulib/legacy/LowStar.BufferCompat.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t -> FStar.HyperStack.ST.ST (LowStar.Buffer.buffer a)
{ "end_col": 3, "end_line": 63, "start_col": 1, "start_line": 62 }