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
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let well_founded_relation (a:Type) = rel:binrel a{is_well_founded rel}
let well_founded_relation (a: Type) =
false
null
false
rel: binrel a {is_well_founded rel}
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "total" ]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.is_well_founded" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h)) let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) : p x = fix_F f x (rwf x) let is_well_founded (#a:Type) (rel:binrel a) = forall (x:a). squash (acc rel x)
false
true
FStar.WellFounded.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 well_founded_relation : a: Type -> Type
[]
FStar.WellFounded.well_founded_relation
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type -> Type
{ "end_col": 70, "end_line": 64, "start_col": 37, "start_line": 64 }
Prims.Tot
val fix (#aa: Type) (#r: binrel aa) (rwf: well_founded r) (p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) : p x
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) : p x = fix_F f x (rwf x)
val fix (#aa: Type) (#r: binrel aa) (rwf: well_founded r) (p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) : p x let fix (#aa: Type) (#r: binrel aa) (rwf: well_founded r) (p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) : p x =
false
null
false
fix_F f x (rwf x)
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "total" ]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.fix_F" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h)) let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa)
false
false
FStar.WellFounded.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 fix (#aa: Type) (#r: binrel aa) (rwf: well_founded r) (p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) : p x
[]
FStar.WellFounded.fix
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
rwf: FStar.WellFounded.well_founded r -> p: (_: aa -> Type) -> f: (x: aa -> _: (y: aa -> _: r y x -> p y) -> p x) -> x: aa -> p x
{ "end_col": 21, "end_line": 59, "start_col": 4, "start_line": 59 }
Prims.Tot
val inverse_image (#a: Type u#a) (#b: Type u#b) (r_b: binrel u#b u#r b) (f: (a -> b)) : binrel u#a u#r a
[ { "abbrev": false, "full_module": "FStar.IndefiniteDescription", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let inverse_image (#a:Type u#a) (#b:Type u#b) (r_b:binrel u#b u#r b) (f:a -> b) : binrel u#a u#r a = fun x y -> r_b (f x) (f y)
val inverse_image (#a: Type u#a) (#b: Type u#b) (r_b: binrel u#b u#r b) (f: (a -> b)) : binrel u#a u#r a let inverse_image (#a: Type u#a) (#b: Type u#b) (r_b: binrel u#b u#r b) (f: (a -> b)) : binrel u#a u#r a =
false
null
false
fun x y -> r_b (f x) (f y)
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "total" ]
[ "FStar.WellFounded.binrel" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h)) let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) : p x = fix_F f x (rwf x) let is_well_founded (#a:Type) (rel:binrel a) = forall (x:a). squash (acc rel x) let well_founded_relation (a:Type) = rel:binrel a{is_well_founded rel} unfold let as_well_founded (#a:Type u#a) (#rel:binrel u#a u#r a) (f:well_founded rel) : well_founded_relation a = introduce forall (x:a). squash (acc rel x) with FStar.Squash.return_squash (FStar.Squash.return_squash (f x)); rel open FStar.IndefiniteDescription (* * Proofs that subrelation and inverse image commute with well-foundedness * * Reference: Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 *) let subrelation_wf (#a:Type) (#r #sub_r:binrel a) (sub_w:(x:a -> y:a -> sub_r x y -> r x y)) (r_wf:well_founded r) : well_founded sub_r = let rec aux (x:a) (acc_r:acc r x) : Tot (acc sub_r x) (decreases acc_r) = AccIntro (fun y sub_r_y_x -> aux y (match acc_r with | AccIntro f -> f y (sub_w y x sub_r_y_x))) in fun x -> aux x (r_wf x) let subrelation_squash_wf (#a:Type u#a) (#r:binrel u#a u#r a) (#sub_r:binrel u#a u#sr a) (sub_w:(x:a -> y:a -> sub_r x y -> squash (r x y))) (r_wf:well_founded r) : Lemma (is_well_founded sub_r) = introduce forall (x:a). squash (acc sub_r x) with ( let rec acc_y (x:a) (acc_r:acc r x) (y:a) (p:sub_r y x) : Tot (acc sub_r y) (decreases acc_r) = AccIntro (acc_y y (acc_r.access_smaller y (elim_squash (sub_w y x p)))) in FStar.Squash.return_squash (FStar.Squash.return_squash (AccIntro (acc_y x (r_wf x)))) ) unfold let subrelation_as_wf (#a:Type u#a) (#r #sub_r:binrel u#a u#r a) (sub_w:(x:a -> y:a -> sub_r x y -> squash (r x y))) (r_wf:well_founded r) : well_founded_relation a = subrelation_squash_wf sub_w r_wf; sub_r
false
false
FStar.WellFounded.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 inverse_image (#a: Type u#a) (#b: Type u#b) (r_b: binrel u#b u#r b) (f: (a -> b)) : binrel u#a u#r a
[]
FStar.WellFounded.inverse_image
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r_b: FStar.WellFounded.binrel b -> f: (_: a -> b) -> FStar.WellFounded.binrel a
{ "end_col": 28, "end_line": 120, "start_col": 2, "start_line": 120 }
Prims.Tot
val fix_F (#aa: Type) (#r: binrel aa) (#p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) (a: acc r x) : Tot (p x) (decreases a)
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h))
val fix_F (#aa: Type) (#r: binrel aa) (#p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) (a: acc r x) : Tot (p x) (decreases a) let rec fix_F (#aa: Type) (#r: binrel aa) (#p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) (a: acc r x) : Tot (p x) (decreases a) =
false
null
false
f x (fun y h -> fix_F f y (a.access_smaller y h))
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "total", "" ]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.acc", "FStar.WellFounded.fix_F", "FStar.WellFounded.__proj__AccIntro__item__access_smaller" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x)
false
false
FStar.WellFounded.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 fix_F (#aa: Type) (#r: binrel aa) (#p: (aa -> Type)) (f: (x: aa -> (y: aa -> r y x -> p y) -> p x)) (x: aa) (a: acc r x) : Tot (p x) (decreases a)
[ "recursion" ]
FStar.WellFounded.fix_F
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
f: (x: aa -> _: (y: aa -> _: r y x -> p y) -> p x) -> x: aa -> a: FStar.WellFounded.acc r x -> Prims.Tot (p x)
{ "end_col": 53, "end_line": 53, "start_col": 4, "start_line": 53 }
Prims.Tot
val subrelation_wf (#a: Type) (#r #sub_r: binrel a) (sub_w: (x: a -> y: a -> sub_r x y -> r x y)) (r_wf: well_founded r) : well_founded sub_r
[ { "abbrev": false, "full_module": "FStar.IndefiniteDescription", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let subrelation_wf (#a:Type) (#r #sub_r:binrel a) (sub_w:(x:a -> y:a -> sub_r x y -> r x y)) (r_wf:well_founded r) : well_founded sub_r = let rec aux (x:a) (acc_r:acc r x) : Tot (acc sub_r x) (decreases acc_r) = AccIntro (fun y sub_r_y_x -> aux y (match acc_r with | AccIntro f -> f y (sub_w y x sub_r_y_x))) in fun x -> aux x (r_wf x)
val subrelation_wf (#a: Type) (#r #sub_r: binrel a) (sub_w: (x: a -> y: a -> sub_r x y -> r x y)) (r_wf: well_founded r) : well_founded sub_r let subrelation_wf (#a: Type) (#r #sub_r: binrel a) (sub_w: (x: a -> y: a -> sub_r x y -> r x y)) (r_wf: well_founded r) : well_founded sub_r =
false
null
false
let rec aux (x: a) (acc_r: acc r x) : Tot (acc sub_r x) (decreases acc_r) = AccIntro (fun y sub_r_y_x -> aux y (match acc_r with | AccIntro f -> f y (sub_w y x sub_r_y_x))) in fun x -> aux x (r_wf x)
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "total" ]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.acc", "FStar.WellFounded.AccIntro", "Prims.precedes" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h)) let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) : p x = fix_F f x (rwf x) let is_well_founded (#a:Type) (rel:binrel a) = forall (x:a). squash (acc rel x) let well_founded_relation (a:Type) = rel:binrel a{is_well_founded rel} unfold let as_well_founded (#a:Type u#a) (#rel:binrel u#a u#r a) (f:well_founded rel) : well_founded_relation a = introduce forall (x:a). squash (acc rel x) with FStar.Squash.return_squash (FStar.Squash.return_squash (f x)); rel open FStar.IndefiniteDescription (* * Proofs that subrelation and inverse image commute with well-foundedness * * Reference: Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 *) let subrelation_wf (#a:Type) (#r #sub_r:binrel a) (sub_w:(x:a -> y:a -> sub_r x y -> r x y)) (r_wf:well_founded r)
false
false
FStar.WellFounded.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 subrelation_wf (#a: Type) (#r #sub_r: binrel a) (sub_w: (x: a -> y: a -> sub_r x y -> r x y)) (r_wf: well_founded r) : well_founded sub_r
[]
FStar.WellFounded.subrelation_wf
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
sub_w: (x: a -> y: a -> _: sub_r x y -> r x y) -> r_wf: FStar.WellFounded.well_founded r -> FStar.WellFounded.well_founded sub_r
{ "end_col": 27, "end_line": 91, "start_col": 3, "start_line": 86 }
Prims.Tot
val inverse_image_wf (#a: Type u#a) (#b: Type u#b) (#r_b: binrel u#b u#r b) (f: (a -> b)) (r_b_wf: well_founded r_b) : well_founded (inverse_image r_b f)
[ { "abbrev": false, "full_module": "FStar.IndefiniteDescription", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let inverse_image_wf (#a:Type u#a) (#b:Type u#b) (#r_b:binrel u#b u#r b) (f:a -> b) (r_b_wf:well_founded r_b) : well_founded (inverse_image r_b f) = let rec aux (x:a) (acc_r_b:acc r_b (f x)) : Tot (acc (inverse_image r_b f) x) (decreases acc_r_b) = AccIntro (fun y p -> aux y (acc_r_b.access_smaller (f y) p)) in fun x -> aux x (r_b_wf (f x))
val inverse_image_wf (#a: Type u#a) (#b: Type u#b) (#r_b: binrel u#b u#r b) (f: (a -> b)) (r_b_wf: well_founded r_b) : well_founded (inverse_image r_b f) let inverse_image_wf (#a: Type u#a) (#b: Type u#b) (#r_b: binrel u#b u#r b) (f: (a -> b)) (r_b_wf: well_founded r_b) : well_founded (inverse_image r_b f) =
false
null
false
let rec aux (x: a) (acc_r_b: acc r_b (f x)) : Tot (acc (inverse_image r_b f) x) (decreases acc_r_b) = AccIntro (fun y p -> aux y (acc_r_b.access_smaller (f y) p)) in fun x -> aux x (r_b_wf (f x))
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "total" ]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.acc", "FStar.WellFounded.inverse_image", "FStar.WellFounded.AccIntro", "FStar.WellFounded.__proj__AccIntro__item__access_smaller" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h)) let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) : p x = fix_F f x (rwf x) let is_well_founded (#a:Type) (rel:binrel a) = forall (x:a). squash (acc rel x) let well_founded_relation (a:Type) = rel:binrel a{is_well_founded rel} unfold let as_well_founded (#a:Type u#a) (#rel:binrel u#a u#r a) (f:well_founded rel) : well_founded_relation a = introduce forall (x:a). squash (acc rel x) with FStar.Squash.return_squash (FStar.Squash.return_squash (f x)); rel open FStar.IndefiniteDescription (* * Proofs that subrelation and inverse image commute with well-foundedness * * Reference: Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 *) let subrelation_wf (#a:Type) (#r #sub_r:binrel a) (sub_w:(x:a -> y:a -> sub_r x y -> r x y)) (r_wf:well_founded r) : well_founded sub_r = let rec aux (x:a) (acc_r:acc r x) : Tot (acc sub_r x) (decreases acc_r) = AccIntro (fun y sub_r_y_x -> aux y (match acc_r with | AccIntro f -> f y (sub_w y x sub_r_y_x))) in fun x -> aux x (r_wf x) let subrelation_squash_wf (#a:Type u#a) (#r:binrel u#a u#r a) (#sub_r:binrel u#a u#sr a) (sub_w:(x:a -> y:a -> sub_r x y -> squash (r x y))) (r_wf:well_founded r) : Lemma (is_well_founded sub_r) = introduce forall (x:a). squash (acc sub_r x) with ( let rec acc_y (x:a) (acc_r:acc r x) (y:a) (p:sub_r y x) : Tot (acc sub_r y) (decreases acc_r) = AccIntro (acc_y y (acc_r.access_smaller y (elim_squash (sub_w y x p)))) in FStar.Squash.return_squash (FStar.Squash.return_squash (AccIntro (acc_y x (r_wf x)))) ) unfold let subrelation_as_wf (#a:Type u#a) (#r #sub_r:binrel u#a u#r a) (sub_w:(x:a -> y:a -> sub_r x y -> squash (r x y))) (r_wf:well_founded r) : well_founded_relation a = subrelation_squash_wf sub_w r_wf; sub_r let inverse_image (#a:Type u#a) (#b:Type u#b) (r_b:binrel u#b u#r b) (f:a -> b) : binrel u#a u#r a = fun x y -> r_b (f x) (f y) let inverse_image_wf (#a:Type u#a) (#b:Type u#b) (#r_b:binrel u#b u#r b) (f:a -> b) (r_b_wf:well_founded r_b)
false
false
FStar.WellFounded.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 inverse_image_wf (#a: Type u#a) (#b: Type u#b) (#r_b: binrel u#b u#r b) (f: (a -> b)) (r_b_wf: well_founded r_b) : well_founded (inverse_image r_b f)
[]
FStar.WellFounded.inverse_image_wf
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
f: (_: a -> b) -> r_b_wf: FStar.WellFounded.well_founded r_b -> FStar.WellFounded.well_founded (FStar.WellFounded.inverse_image r_b f)
{ "end_col": 33, "end_line": 131, "start_col": 3, "start_line": 126 }
FStar.Pervasives.Lemma
val subrelation_squash_wf (#a: Type u#a) (#r: binrel u#a u#r a) (#sub_r: binrel u#a u#sr a) (sub_w: (x: a -> y: a -> sub_r x y -> squash (r x y))) (r_wf: well_founded r) : Lemma (is_well_founded sub_r)
[ { "abbrev": false, "full_module": "FStar.IndefiniteDescription", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let subrelation_squash_wf (#a:Type u#a) (#r:binrel u#a u#r a) (#sub_r:binrel u#a u#sr a) (sub_w:(x:a -> y:a -> sub_r x y -> squash (r x y))) (r_wf:well_founded r) : Lemma (is_well_founded sub_r) = introduce forall (x:a). squash (acc sub_r x) with ( let rec acc_y (x:a) (acc_r:acc r x) (y:a) (p:sub_r y x) : Tot (acc sub_r y) (decreases acc_r) = AccIntro (acc_y y (acc_r.access_smaller y (elim_squash (sub_w y x p)))) in FStar.Squash.return_squash (FStar.Squash.return_squash (AccIntro (acc_y x (r_wf x)))) )
val subrelation_squash_wf (#a: Type u#a) (#r: binrel u#a u#r a) (#sub_r: binrel u#a u#sr a) (sub_w: (x: a -> y: a -> sub_r x y -> squash (r x y))) (r_wf: well_founded r) : Lemma (is_well_founded sub_r) let subrelation_squash_wf (#a: Type u#a) (#r: binrel u#a u#r a) (#sub_r: binrel u#a u#sr a) (sub_w: (x: a -> y: a -> sub_r x y -> squash (r x y))) (r_wf: well_founded r) : Lemma (is_well_founded sub_r) =
false
null
true
introduce forall (x: a) . squash (acc sub_r x) with (let rec acc_y (x: a) (acc_r: acc r x) (y: a) (p: sub_r y x) : Tot (acc sub_r y) (decreases acc_r) = AccIntro (acc_y y (acc_r.access_smaller y (elim_squash (sub_w y x p)))) in FStar.Squash.return_squash (FStar.Squash.return_squash (AccIntro (acc_y x (r_wf x)))))
{ "checked_file": "FStar.WellFounded.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": false, "source_file": "FStar.WellFounded.fst" }
[ "lemma" ]
[ "FStar.WellFounded.binrel", "Prims.squash", "FStar.WellFounded.well_founded", "FStar.Classical.Sugar.forall_intro", "FStar.WellFounded.acc", "FStar.Squash.return_squash", "FStar.WellFounded.AccIntro", "FStar.WellFounded.__proj__AccIntro__item__access_smaller", "FStar.IndefiniteDescription.elim_squash", "Prims.unit", "Prims.l_True", "FStar.WellFounded.is_well_founded", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria 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. Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy *) (* Defining accessibility predicates and well-founded recursion like in Coq https://coq.inria.fr/library/Coq.Init.Wf.html *) module FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let binrel (a:Type) = a -> a -> Type (* * The accessibility relation * -- Marked erasable, since this is a singleton type anyway * -- Erasability also simplifies proofs that use accessibility in * with axioms like indefinitedescription *) [@@ erasable] noeq type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) = | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x (* * A binrel r is well-founded if every element is accessible *) let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x (* * Accessibility predicates can be used for implementing * total fix points *) let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type)) (f: (x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) (a:acc r x) : Tot (p x) (decreases a) = f x (fun y h -> fix_F f y (a.access_smaller y h)) let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r) (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x)) (x:aa) : p x = fix_F f x (rwf x) let is_well_founded (#a:Type) (rel:binrel a) = forall (x:a). squash (acc rel x) let well_founded_relation (a:Type) = rel:binrel a{is_well_founded rel} unfold let as_well_founded (#a:Type u#a) (#rel:binrel u#a u#r a) (f:well_founded rel) : well_founded_relation a = introduce forall (x:a). squash (acc rel x) with FStar.Squash.return_squash (FStar.Squash.return_squash (f x)); rel open FStar.IndefiniteDescription (* * Proofs that subrelation and inverse image commute with well-foundedness * * Reference: Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 *) let subrelation_wf (#a:Type) (#r #sub_r:binrel a) (sub_w:(x:a -> y:a -> sub_r x y -> r x y)) (r_wf:well_founded r) : well_founded sub_r = let rec aux (x:a) (acc_r:acc r x) : Tot (acc sub_r x) (decreases acc_r) = AccIntro (fun y sub_r_y_x -> aux y (match acc_r with | AccIntro f -> f y (sub_w y x sub_r_y_x))) in fun x -> aux x (r_wf x) let subrelation_squash_wf (#a:Type u#a) (#r:binrel u#a u#r a) (#sub_r:binrel u#a u#sr a) (sub_w:(x:a -> y:a -> sub_r x y -> squash (r x y))) (r_wf:well_founded r)
false
false
FStar.WellFounded.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 subrelation_squash_wf (#a: Type u#a) (#r: binrel u#a u#r a) (#sub_r: binrel u#a u#sr a) (sub_w: (x: a -> y: a -> sub_r x y -> squash (r x y))) (r_wf: well_founded r) : Lemma (is_well_founded sub_r)
[]
FStar.WellFounded.subrelation_squash_wf
{ "file_name": "ulib/FStar.WellFounded.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
sub_w: (x: a -> y: a -> _: sub_r x y -> Prims.squash (r x y)) -> r_wf: FStar.WellFounded.well_founded r -> FStar.Pervasives.Lemma (ensures FStar.WellFounded.is_well_founded sub_r)
{ "end_col": 5, "end_line": 109, "start_col": 4, "start_line": 99 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_mul_threshold = 32
let bn_mul_threshold =
false
null
false
32
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_mul_threshold : Prims.int
[]
Hacl.Spec.Bignum.Karatsuba.bn_mul_threshold
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.int
{ "end_col": 25, "end_line": 23, "start_col": 23, "start_line": 23 }
Prims.Tot
val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45
val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 =
false
null
false
let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Pervasives.Native.Mktuple2", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.mask_select", "Lib.Sequence.lseq", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Lib.Sequence.index", "Lib.Sequence.map2", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint", "Lib.IntTypes.op_Plus_Dot", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "Hacl.Spec.Bignum.Addition.bn_sub", "Lib.IntTypes.op_Hat_Dot" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c0: Hacl.Spec.Bignum.Base.carry t -> c1: Hacl.Spec.Bignum.Base.carry t -> c2: Hacl.Spec.Bignum.Base.carry t -> t01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> t23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.limb t * Hacl.Spec.Bignum.Definitions.lbignum t aLen
{ "end_col": 9, "end_line": 99, "start_col": 51, "start_line": 92 }
Prims.Tot
val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res
val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b =
false
null
false
let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.carry", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Lib.Sequence.index", "Hacl.Spec.Bignum.Base.mask_select", "Lib.IntTypes.sub_mod", "Lib.IntTypes.SEC", "Lib.IntTypes.mk_int", "Lib.Sequence.map2", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_sub" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen)
[]
Hacl.Spec.Bignum.Karatsuba.bn_sign_abs
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen
{ "end_col": 9, "end_line": 37, "start_col": 30, "start_line": 33 }
Prims.Tot
val bn_karatsuba_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_sqr #t #aLen a = bn_karatsuba_sqr_ aLen a
val bn_karatsuba_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_sqr #t #aLen a =
false
null
false
bn_karatsuba_sqr_ aLen a
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) let bn_karatsuba_mul_lemma #t #aLen a b = let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b) val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba_sqr #t #aLen c2 t01 t23 = let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in c3, t45 val bn_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23) let bn_middle_karatsuba_sqr_lemma #t #aLen c0 c2 t01 t23 = let (c, res) = bn_middle_karatsuba c0 c0 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in bn_middle_karatsuba_lemma c0 c0 c2 t01 t23; assert (v c == v c3' /\ bn_v res == bn_v t45); bn_eval_inj aLen t45 res val bn_karatsuba_sqr_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v a}) (decreases aLen) let rec bn_karatsuba_sqr_ #t aLen a = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_sqr_lemma a; bn_sqr a end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; (**) bn_eval_bound a aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let t23 = bn_karatsuba_sqr_ aLen2 t0 in let r01 = bn_karatsuba_sqr_ aLen2 a0 in let r23 = bn_karatsuba_sqr_ aLen2 a1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba_sqr c2 t01 t23 in (**) bn_middle_karatsuba_sqr_lemma c0 c2 t01 t23; (**) bn_middle_karatsuba_eval a0 a1 a0 a1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 a0 a1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v a0) (bn_v a1); (**) bn_karatsuba_no_last_carry a a c res; assert (v c = 0); res end val bn_karatsuba_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
{ "end_col": 26, "end_line": 618, "start_col": 2, "start_line": 618 }
Prims.Tot
val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b
val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b =
false
null
false
bn_karatsuba_mul_ aLen a b
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen)
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
{ "end_col": 28, "end_line": 522, "start_col": 2, "start_line": 522 }
Prims.Tot
val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba_sqr #t #aLen c2 t01 t23 = let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in c3, t45
val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba_sqr #t #aLen c2 t01 t23 =
false
null
false
let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in c3, t45
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Pervasives.Native.Mktuple2", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_sub" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) let bn_karatsuba_mul_lemma #t #aLen a b = let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b) val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c2: Hacl.Spec.Bignum.Base.carry t -> t01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> t23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.limb t * Hacl.Spec.Bignum.Definitions.lbignum t aLen
{ "end_col": 9, "end_line": 553, "start_col": 49, "start_line": 551 }
FStar.Pervasives.Lemma
val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1))
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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 sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL)
val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 =
false
null
true
logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL)
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.Base.carry", "FStar.Pervasives.assert_norm", "Prims.eq2", "FStar.UInt32.t", "FStar.UInt32.logxor", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.UInt64.t", "FStar.UInt64.logxor", "FStar.UInt64.__uint_to_t", "Lib.IntTypes.logxor_spec", "Lib.IntTypes.SEC" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1))
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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 sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1))
[]
Hacl.Spec.Bignum.Karatsuba.sign_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c0: Hacl.Spec.Bignum.Base.carry t -> c1: Hacl.Spec.Bignum.Base.carry t -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v (c0 ^. c1) == (match Lib.IntTypes.v c0 = Lib.IntTypes.v c1 with | true -> 0 | _ -> 1))
{ "end_col": 46, "end_line": 116, "start_col": 2, "start_line": 105 }
FStar.Pervasives.Lemma
val bn_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba_sqr_lemma #t #aLen c0 c2 t01 t23 = let (c, res) = bn_middle_karatsuba c0 c0 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in bn_middle_karatsuba_lemma c0 c0 c2 t01 t23; assert (v c == v c3' /\ bn_v res == bn_v t45); bn_eval_inj aLen t45 res
val bn_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23) let bn_middle_karatsuba_sqr_lemma #t #aLen c0 c2 t01 t23 =
false
null
true
let c, res = bn_middle_karatsuba c0 c0 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in bn_middle_karatsuba_lemma c0 c0 c2 t01 t23; assert (v c == v c3' /\ bn_v res == bn_v t45); bn_eval_inj aLen t45 res
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Prims.unit", "Prims._assert", "Prims.l_and", "Prims.eq2", "Lib.IntTypes.range_t", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_lemma", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Subtraction_Dot", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_sub", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) let bn_karatsuba_mul_lemma #t #aLen a b = let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b) val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba_sqr #t #aLen c2 t01 t23 = let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in c3, t45 val bn_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23)
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c0: Hacl.Spec.Bignum.Base.carry t -> c2: Hacl.Spec.Bignum.Base.carry t -> t01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> t23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr c2 t01 t23 == Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba c0 c0 c2 t01 t23)
{ "end_col": 26, "end_line": 570, "start_col": 58, "start_line": 565 }
Prims.Tot
val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a'
val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i =
false
null
false
let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a'
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Hacl.Spec.Bignum.Base.carry", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Prims.eq2", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen)
[]
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> i: Prims.nat{i + bLen <= aLen} -> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen
{ "end_col": 7, "end_line": 304, "start_col": 51, "start_line": 300 }
Prims.Tot
val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a'
val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i =
false
null
false
let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a'
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Hacl.Spec.Bignum.Base.carry", "Prims.op_Subtraction", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add1", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen)
[]
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i + 1 <= aLen} -> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen
{ "end_col": 7, "end_line": 256, "start_col": 35, "start_line": 252 }
FStar.Pervasives.Lemma
val bn_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_karatsuba_sqr a == bn_mul a a /\ bn_v (bn_karatsuba_sqr a) == bn_v a * bn_v a)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_sqr_lemma #t #aLen a = let res = bn_karatsuba_sqr_ aLen a in assert (bn_v res == bn_v a * bn_v a); let res' = bn_mul a a in bn_mul_lemma a a; assert (bn_v res' == bn_v a * bn_v a); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_sqr_ aLen a == bn_mul a a)
val bn_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_karatsuba_sqr a == bn_mul a a /\ bn_v (bn_karatsuba_sqr a) == bn_v a * bn_v a) let bn_karatsuba_sqr_lemma #t #aLen a =
false
null
true
let res = bn_karatsuba_sqr_ aLen a in assert (bn_v res == bn_v a * bn_v a); let res' = bn_mul a a in bn_mul_lemma a a; assert (bn_v res' == bn_v a * bn_v a); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_sqr_ aLen a == bn_mul a a)
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims._assert", "Prims.eq2", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_", "Hacl.Spec.Bignum.Multiplication.bn_mul", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Multiplication.bn_mul_lemma", "Prims.op_Multiply" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) let bn_karatsuba_mul_lemma #t #aLen a b = let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b) val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba_sqr #t #aLen c2 t01 t23 = let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in c3, t45 val bn_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23) let bn_middle_karatsuba_sqr_lemma #t #aLen c0 c2 t01 t23 = let (c, res) = bn_middle_karatsuba c0 c0 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in bn_middle_karatsuba_lemma c0 c0 c2 t01 t23; assert (v c == v c3' /\ bn_v res == bn_v t45); bn_eval_inj aLen t45 res val bn_karatsuba_sqr_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v a}) (decreases aLen) let rec bn_karatsuba_sqr_ #t aLen a = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_sqr_lemma a; bn_sqr a end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; (**) bn_eval_bound a aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let t23 = bn_karatsuba_sqr_ aLen2 t0 in let r01 = bn_karatsuba_sqr_ aLen2 a0 in let r23 = bn_karatsuba_sqr_ aLen2 a1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba_sqr c2 t01 t23 in (**) bn_middle_karatsuba_sqr_lemma c0 c2 t01 t23; (**) bn_middle_karatsuba_eval a0 a1 a0 a1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 a0 a1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v a0) (bn_v a1); (**) bn_karatsuba_no_last_carry a a c res; assert (v c = 0); res end val bn_karatsuba_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_sqr #t #aLen a = bn_karatsuba_sqr_ aLen a val bn_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_karatsuba_sqr a == bn_mul a a /\ bn_v (bn_karatsuba_sqr a) == bn_v a * bn_v a)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_karatsuba_sqr a == bn_mul a a /\ bn_v (bn_karatsuba_sqr a) == bn_v a * bn_v a)
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a == Hacl.Spec.Bignum.Multiplication.bn_mul a a /\ Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v a)
{ "end_col": 49, "end_line": 635, "start_col": 39, "start_line": 628 }
FStar.Pervasives.Lemma
val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_mul_lemma #t #aLen a b = let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b)
val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) let bn_karatsuba_mul_lemma #t #aLen a b =
false
null
true
let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b)
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims._assert", "Prims.eq2", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_", "Hacl.Spec.Bignum.Multiplication.bn_mul", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Multiplication.bn_mul_lemma", "Prims.op_Multiply" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b)
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b == Hacl.Spec.Bignum.Multiplication.bn_mul a b /\ Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b)
{ "end_col": 51, "end_line": 540, "start_col": 41, "start_line": 533 }
FStar.Pervasives.Lemma
val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0))
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen
val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b =
false
null
true
let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Karatsuba.Lemmas.sign", "Prims.nat", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.unit", "Prims._assert", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.bool", "Hacl.Spec.Bignum.Base.lseq_mask_select_lemma", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.index", "Hacl.Spec.Bignum.Base.mask_select", "Lib.Sequence.map2", "Lib.IntTypes.ones", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Addition.bn_sub_lemma", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_sub", "Hacl.Spec.Karatsuba.Lemmas.sign_abs" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0))
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0))
[]
Hacl.Spec.Bignum.Karatsuba.bn_sign_abs_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Karatsuba.bn_sign_abs a b in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Karatsuba.Lemmas.abs (Hacl.Spec.Bignum.Definitions.bn_v a) (Hacl.Spec.Bignum.Definitions.bn_v b) /\ Lib.IntTypes.v c == (match Hacl.Spec.Bignum.Definitions.bn_v a < Hacl.Spec.Bignum.Definitions.bn_v b with | true -> 1 | _ -> 0)) <: Type0))
{ "end_col": 23, "end_line": 69, "start_col": 36, "start_line": 49 }
Prims.Tot
val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen))
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res
val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 =
false
null
false
let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in c8, res
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.carry", "Prims.op_Addition", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Karatsuba.bn_lshift_add", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Dot", "Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop", "Lib.Sequence.lseq", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Prims.int", "Prims.op_Division" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen))
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen))
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> r23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c5: Hacl.Spec.Bignum.Definitions.limb t -> t45: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
{ "end_col": 9, "end_line": 363, "start_col": 46, "start_line": 349 }
FStar.Pervasives.Lemma
val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen
val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 =
false
null
true
bn_eval_bound res aLen
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_Division", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.unit" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1)
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval_aux
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a0: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> a1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> b0: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> b1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> res: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c2: Hacl.Spec.Bignum.Base.carry t -> c3: Hacl.Spec.Bignum.Base.carry t -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v res + (Lib.IntTypes.v c2 - Lib.IntTypes.v c3) * Prims.pow2 (Lib.IntTypes.bits t * aLen) == Hacl.Spec.Bignum.Definitions.bn_v a0 * Hacl.Spec.Bignum.Definitions.bn_v b1 + Hacl.Spec.Bignum.Definitions.bn_v a1 * Hacl.Spec.Bignum.Definitions.bn_v b0) (ensures 0 <= Lib.IntTypes.v c2 - Lib.IntTypes.v c3 /\ Lib.IntTypes.v c2 - Lib.IntTypes.v c3 <= 1)
{ "end_col": 24, "end_line": 172, "start_col": 2, "start_line": 172 }
FStar.Pervasives.Lemma
val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen)
val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res =
false
null
true
bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen)
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.unit", "FStar.Math.Lemmas.pow2_plus", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "FStar.Math.Lemmas.lemma_mult_lt_sqr", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0)
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_no_last_carry
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c: Hacl.Spec.Bignum.Base.carry t -> res: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v res + Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * (aLen + aLen)) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b) (ensures Lib.IntTypes.v c == 0)
{ "end_col": 33, "end_line": 461, "start_col": 2, "start_line": 457 }
FStar.Pervasives.Lemma
val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3'
val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 =
false
null
true
let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3'
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.mask_select_lemma", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.mask_select", "Prims.unit", "Hacl.Spec.Bignum.Base.lseq_mask_select_lemma", "Lib.Sequence.lseq", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Lib.Sequence.index", "Lib.Sequence.map2", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint", "Lib.IntTypes.op_Plus_Dot", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "Hacl.Spec.Bignum.Addition.bn_sub", "Prims._assert", "Prims.int", "Lib.IntTypes.v", "Prims.op_Equality", "Lib.IntTypes.range_t", "Prims.bool", "Hacl.Spec.Bignum.Karatsuba.sign_lemma", "Lib.IntTypes.op_Hat_Dot", "Prims.op_Addition", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.bits", "Prims.op_Subtraction" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67)
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c0: Hacl.Spec.Bignum.Base.carry t -> c1: Hacl.Spec.Bignum.Base.carry t -> c2: Hacl.Spec.Bignum.Base.carry t -> t01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> t23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba c0 c1 c2 t01 t23 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in let _ = Hacl.Spec.Bignum.Addition.bn_sub t01 t23 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c3 t45 = _ in let c3' = c2 -. c3 in let _ = Hacl.Spec.Bignum.Addition.bn_add t01 t23 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c4 t67 = _ in let c4' = c2 +. c4 in (match Lib.IntTypes.v c0 = Lib.IntTypes.v c1 with | true -> Lib.IntTypes.v c == Lib.IntTypes.v c3' /\ Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.bn_v t45 | _ -> Lib.IntTypes.v c == Lib.IntTypes.v c4' /\ Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.bn_v t67) <: Type0) <: Type0) <: Type0) <: Type0))
{ "end_col": 32, "end_line": 152, "start_col": 57, "start_line": 136 }
Prims.Tot
val bn_karatsuba_sqr_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v a}) (decreases aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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 rec bn_karatsuba_sqr_ #t aLen a = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_sqr_lemma a; bn_sqr a end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; (**) bn_eval_bound a aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let t23 = bn_karatsuba_sqr_ aLen2 t0 in let r01 = bn_karatsuba_sqr_ aLen2 a0 in let r23 = bn_karatsuba_sqr_ aLen2 a1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba_sqr c2 t01 t23 in (**) bn_middle_karatsuba_sqr_lemma c0 c2 t01 t23; (**) bn_middle_karatsuba_eval a0 a1 a0 a1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 a0 a1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v a0) (bn_v a1); (**) bn_karatsuba_no_last_carry a a c res; assert (v c = 0); res end
val bn_karatsuba_sqr_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v a}) (decreases aLen) let rec bn_karatsuba_sqr_ #t aLen a =
false
null
false
if aLen < bn_mul_threshold || aLen % 2 = 1 then (bn_sqr_lemma a; bn_sqr a) else let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in bn_div_pow2_lemma a aLen2; bn_eval_bound a aLen; K.lemma_bn_halves (bits t) aLen (bn_v a); let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; let t23 = bn_karatsuba_sqr_ aLen2 t0 in let r01 = bn_karatsuba_sqr_ aLen2 a0 in let r23 = bn_karatsuba_sqr_ aLen2 a1 in let c2, t01 = bn_add r01 r23 in bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba_sqr c2 t01 t23 in bn_middle_karatsuba_sqr_lemma c0 c2 t01 t23; bn_middle_karatsuba_eval a0 a1 a0 a1 c2 t01 t23; bn_middle_karatsuba_carry_bound aLen a0 a1 a0 a1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_karatsuba_res_lemma r01 r23 c5 t45; K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v a0) (bn_v a1); bn_karatsuba_no_last_carry a a c res; assert (v c = 0); res
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total", "" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_BarBar", "Prims.op_LessThan", "Hacl.Spec.Bignum.Karatsuba.bn_mul_threshold", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Bignum.Squaring.bn_sqr", "Prims.unit", "Hacl.Spec.Bignum.Squaring.bn_sqr_lemma", "Prims.bool", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.limb", "Prims._assert", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_no_last_carry", "Hacl.Spec.Karatsuba.Lemmas.lemma_karatsuba", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Subtraction", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res_lemma", "Prims.eq2", "FStar.Mul.op_Star", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_carry_bound", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr_lemma", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr", "Hacl.Spec.Bignum.Addition.bn_add_lemma", "Hacl.Spec.Bignum.Addition.bn_add", "Prims.op_Multiply", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_", "Hacl.Spec.Bignum.Karatsuba.bn_sign_abs_lemma", "Hacl.Spec.Bignum.Karatsuba.bn_sign_abs", "Hacl.Spec.Karatsuba.Lemmas.lemma_bn_halves", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma", "Hacl.Spec.Bignum.Lib.bn_div_pow2", "Hacl.Spec.Bignum.Lib.bn_mod_pow2_lemma", "Hacl.Spec.Bignum.Lib.bn_mod_pow2", "Prims.op_Division" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end val bn_karatsuba_mul: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> lbignum t (aLen + aLen) let bn_karatsuba_mul #t #aLen a b = bn_karatsuba_mul_ aLen a b val bn_karatsuba_mul_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (bn_karatsuba_mul a b == bn_mul a b /\ bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) let bn_karatsuba_mul_lemma #t #aLen a b = let res = bn_karatsuba_mul_ aLen a b in assert (bn_v res == bn_v a * bn_v b); let res' = bn_mul a b in bn_mul_lemma a b; assert (bn_v res' == bn_v a * bn_v b); bn_eval_inj (aLen + aLen) res res'; assert (bn_karatsuba_mul_ aLen a b == bn_mul a b) val bn_middle_karatsuba_sqr: #t:limb_t -> #aLen:size_nat -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba_sqr #t #aLen c2 t01 t23 = let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in c3, t45 val bn_middle_karatsuba_sqr_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (bn_middle_karatsuba_sqr c2 t01 t23 == bn_middle_karatsuba c0 c0 c2 t01 t23) let bn_middle_karatsuba_sqr_lemma #t #aLen c0 c2 t01 t23 = let (c, res) = bn_middle_karatsuba c0 c0 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in bn_middle_karatsuba_lemma c0 c0 c2 t01 t23; assert (v c == v c3' /\ bn_v res == bn_v t45); bn_eval_inj aLen t45 res val bn_karatsuba_sqr_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v a}) (decreases aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_sqr_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v a}) (decreases aLen)
[ "recursion" ]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
aLen: Lib.IntTypes.size_nat{aLen + aLen <= Lib.IntTypes.max_size_t} -> a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Prims.Tot (res: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) { Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v a })
{ "end_col": 11, "end_line": 608, "start_col": 2, "start_line": 577 }
FStar.Pervasives.Lemma
val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i))
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); }
val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i =
false
null
true
let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc ( == ) { bn_v a' + v c * p; ( == ) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; ( == ) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; ( == ) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; ( == ) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; ( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i); }
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Hacl.Spec.Bignum.Base.carry", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_update_sub_eval", "Prims.squash", "Hacl.Spec.Bignum.Addition.bn_add_lemma", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Prims.pos", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i))
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i))
[]
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> i: Prims.nat{i + bLen <= aLen} -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop a b i in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Hacl.Spec.Bignum.Definitions.bn_v res + Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * (i + bLen)) == Hacl.Spec.Bignum.Definitions.bn_v a + Hacl.Spec.Bignum.Definitions.bn_v b * Prims.pow2 (Lib.IntTypes.bits t * i)) <: Type0))
{ "end_col": 5, "end_line": 337, "start_col": 57, "start_line": 317 }
FStar.Pervasives.Lemma
val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i))
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); }
val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i =
false
null
true
let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc ( == ) { bn_v a' + v c * p; ( == ) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; ( == ) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; ( == ) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; ( == ) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; ( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i); }
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Hacl.Spec.Bignum.Base.carry", "Prims.op_Subtraction", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_update_sub_eval", "Prims.squash", "Hacl.Spec.Bignum.Addition.bn_add1_lemma", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Prims.pos", "Lib.Sequence.lseq", "Prims.l_and", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add1", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i))
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i))
[]
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i + 1 <= aLen} -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Karatsuba.bn_lshift_add a b1 i in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Hacl.Spec.Bignum.Definitions.bn_v res + Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) == Hacl.Spec.Bignum.Definitions.bn_v a + Lib.IntTypes.v b1 * Prims.pow2 (Lib.IntTypes.bits t * i)) <: Type0))
{ "end_col": 5, "end_line": 288, "start_col": 41, "start_line": 268 }
FStar.Pervasives.Lemma
val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1)
val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c =
false
null
true
let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc ( < ) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; ( < ) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; ( < ) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; ( == ) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1)
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_Division", "Hacl.Spec.Bignum.Definitions.limb", "Prims._assert", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.unit", "Prims.op_LessThan", "Prims.op_Addition", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Prims.pow2", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.eq2", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mult_lt_sqr", "Prims.squash", "Hacl.Spec.Karatsuba.Lemmas.lemma_double_p", "Lib.IntTypes.bits", "Prims.pos" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1)
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_carry_bound
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
aLen: Lib.IntTypes.size_nat{aLen % 2 = 0} -> a0: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> a1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> b0: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> b1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> res: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c: Hacl.Spec.Bignum.Definitions.limb t -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v res + Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) == Hacl.Spec.Bignum.Definitions.bn_v a0 * Hacl.Spec.Bignum.Definitions.bn_v b1 + Hacl.Spec.Bignum.Definitions.bn_v a1 * Hacl.Spec.Bignum.Definitions.bn_v b0) (ensures Lib.IntTypes.v c <= 1)
{ "end_col": 19, "end_line": 443, "start_col": 63, "start_line": 422 }
FStar.Pervasives.Lemma
val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0))
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end
val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 =
false
null
true
let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then (assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 ); ()) else (assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 ); ())
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_Division", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Equality", "Lib.IntTypes.range_t", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Addition", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Subtraction", "FStar.Math.Lemmas.small_mod", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval_aux", "FStar.Math.Lemmas.distributivity_sub_left", "Hacl.Spec.Bignum.Addition.bn_sub_lemma", "Prims.l_and", "Prims.nat", "Prims.bool", "FStar.Math.Lemmas.distributivity_add_left", "Hacl.Spec.Bignum.Addition.bn_add_lemma", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Dot", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "Lib.IntTypes.op_Subtraction_Dot", "Hacl.Spec.Bignum.Addition.bn_sub", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_lemma", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba", "Prims.op_LessThan", "Hacl.Spec.Karatsuba.Lemmas.abs", "Hacl.Spec.Bignum.Karatsuba.bn_sign_abs_lemma", "Hacl.Spec.Bignum.Karatsuba.bn_sign_abs", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0))
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0))
[]
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a0: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> a1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> b0: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> b1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen / 2) -> c2: Hacl.Spec.Bignum.Base.carry t -> t01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> t23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (requires (let t0 = Hacl.Spec.Karatsuba.Lemmas.abs (Hacl.Spec.Bignum.Definitions.bn_v a0) (Hacl.Spec.Bignum.Definitions.bn_v a1) in let t1 = Hacl.Spec.Karatsuba.Lemmas.abs (Hacl.Spec.Bignum.Definitions.bn_v b0) (Hacl.Spec.Bignum.Definitions.bn_v b1) in Hacl.Spec.Bignum.Definitions.bn_v t01 + Lib.IntTypes.v c2 * Prims.pow2 (Lib.IntTypes.bits t * aLen) == Hacl.Spec.Bignum.Definitions.bn_v a0 * Hacl.Spec.Bignum.Definitions.bn_v b0 + Hacl.Spec.Bignum.Definitions.bn_v a1 * Hacl.Spec.Bignum.Definitions.bn_v b1 /\ Hacl.Spec.Bignum.Definitions.bn_v t23 == t0 * t1)) (ensures (let _ = Hacl.Spec.Bignum.Karatsuba.bn_sign_abs a0 a1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c0 _ = _ in let _ = Hacl.Spec.Bignum.Karatsuba.bn_sign_abs b0 b1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 _ = _ in let _ = Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba c0 c1 c2 t01 t23 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Hacl.Spec.Bignum.Definitions.bn_v res + Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) == Hacl.Spec.Bignum.Definitions.bn_v a0 * Hacl.Spec.Bignum.Definitions.bn_v b1 + Hacl.Spec.Bignum.Definitions.bn_v a1 * Hacl.Spec.Bignum.Definitions.bn_v b0) <: Type0) <: Type0) <: Type0))
{ "end_col": 10, "end_line": 241, "start_col": 62, "start_line": 198 }
Prims.Tot
val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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 rec bn_karatsuba_mul_ #t aLen a b = if aLen < bn_mul_threshold || aLen % 2 = 1 then begin bn_mul_lemma a b; bn_mul a b end else begin let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in (**) bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in (**) bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in (**) bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in (**) bn_div_pow2_lemma b aLen2; (**) bn_eval_bound a aLen; (**) bn_eval_bound b aLen; (**) K.lemma_bn_halves (bits t) aLen (bn_v a); (**) K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in (**) bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in (**) bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in (**) bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in (**) bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; (**) bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in (**) bn_karatsuba_res_lemma r01 r23 c5 t45; (**) K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); (**) bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res end
val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen) let rec bn_karatsuba_mul_ #t aLen a b =
false
null
false
if aLen < bn_mul_threshold || aLen % 2 = 1 then (bn_mul_lemma a b; bn_mul a b) else let aLen2 = aLen / 2 in let a0 = bn_mod_pow2 a aLen2 in bn_mod_pow2_lemma a aLen2; let a1 = bn_div_pow2 a aLen2 in bn_div_pow2_lemma a aLen2; let b0 = bn_mod_pow2 b aLen2 in bn_mod_pow2_lemma b aLen2; let b1 = bn_div_pow2 b aLen2 in bn_div_pow2_lemma b aLen2; bn_eval_bound a aLen; bn_eval_bound b aLen; K.lemma_bn_halves (bits t) aLen (bn_v a); K.lemma_bn_halves (bits t) aLen (bn_v b); let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; let t23 = bn_karatsuba_mul_ aLen2 t0 t1 in let r01 = bn_karatsuba_mul_ aLen2 a0 b0 in let r23 = bn_karatsuba_mul_ aLen2 a1 b1 in let c2, t01 = bn_add r01 r23 in bn_add_lemma r01 r23; let c5, t45 = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_eval a0 a1 b0 b1 c2 t01 t23; bn_middle_karatsuba_carry_bound aLen a0 a1 b0 b1 t45 c5; let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_karatsuba_res_lemma r01 r23 c5 t45; K.lemma_karatsuba (bits t) aLen (bn_v a0) (bn_v a1) (bn_v b0) (bn_v b1); bn_karatsuba_no_last_carry a b c res; assert (v c = 0); res
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "total", "" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_BarBar", "Prims.op_LessThan", "Hacl.Spec.Bignum.Karatsuba.bn_mul_threshold", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Bignum.Multiplication.bn_mul", "Prims.unit", "Hacl.Spec.Bignum.Multiplication.bn_mul_lemma", "Prims.bool", "Hacl.Spec.Bignum.Base.carry", "Hacl.Spec.Bignum.Definitions.limb", "Prims._assert", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_no_last_carry", "Hacl.Spec.Karatsuba.Lemmas.lemma_karatsuba", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Subtraction", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res_lemma", "Prims.eq2", "FStar.Mul.op_Star", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_carry_bound", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval", "Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba", "Hacl.Spec.Bignum.Addition.bn_add_lemma", "Hacl.Spec.Bignum.Addition.bn_add", "Prims.op_Multiply", "Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_", "Hacl.Spec.Bignum.Karatsuba.bn_sign_abs_lemma", "Hacl.Spec.Bignum.Karatsuba.bn_sign_abs", "Hacl.Spec.Karatsuba.Lemmas.lemma_bn_halves", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma", "Hacl.Spec.Bignum.Lib.bn_div_pow2", "Hacl.Spec.Bignum.Lib.bn_mod_pow2_lemma", "Hacl.Spec.Bignum.Lib.bn_mod_pow2", "Prims.op_Division" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; } val bn_middle_karatsuba_carry_bound: #t:limb_t -> aLen:size_nat{aLen % 2 = 0} -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c:limb t -> Lemma (requires bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures v c <= 1) let bn_middle_karatsuba_carry_bound #t aLen a0 a1 b0 b1 res c = let pbits = bits t in let aLen2 = aLen / 2 in let p = pow2 (pbits * aLen2) in bn_eval_bound a0 aLen2; bn_eval_bound a1 aLen2; bn_eval_bound b0 aLen2; bn_eval_bound b1 aLen2; calc (<) { bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a0) (bn_v b1) p } p * p + bn_v a1 * bn_v b0; (<) { Math.Lemmas.lemma_mult_lt_sqr (bn_v a1) (bn_v b0) p } p * p + p * p; (==) { K.lemma_double_p (bits t) aLen } pow2 (pbits * aLen) + pow2 (pbits * aLen); }; bn_eval_bound res aLen; assert (bn_v res + v c * pow2 (pbits * aLen) < pow2 (pbits * aLen) + pow2 (pbits * aLen)); assert (v c <= 1) val bn_karatsuba_no_last_carry: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> c:carry t -> res:lbignum t (aLen + aLen) -> Lemma (requires bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v a * bn_v b) (ensures v c == 0) let bn_karatsuba_no_last_carry #t #aLen a b c res = bn_eval_bound a aLen; bn_eval_bound b aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v b) (pow2 (bits t * aLen)); Math.Lemmas.pow2_plus (bits t * aLen) (bits t * aLen); bn_eval_bound res (aLen + aLen) val bn_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_mul_: #t:limb_t -> aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t aLen -> Tot (res:lbignum t (aLen + aLen){bn_v res == bn_v a * bn_v b}) (decreases aLen)
[ "recursion" ]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
aLen: Lib.IntTypes.size_nat{aLen + aLen <= Lib.IntTypes.max_size_t} -> a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Prims.Tot (res: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) { Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b })
{ "end_col": 11, "end_line": 511, "start_col": 2, "start_line": 472 }
FStar.Pervasives.Lemma
val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01)
[ { "abbrev": true, "full_module": "Hacl.Spec.Karatsuba.Lemmas", "short_module": "K" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Squaring", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.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_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 = let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc (==) { bn_v res2 + v c8 * pow2 (pbits * aLen4); (==) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); (==) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); (==) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); (==) { Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2)) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); (==) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; }
val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01) let bn_karatsuba_res_lemma #t #aLen r01 r23 c5 t45 =
false
null
true
let pbits = bits t in let aLen2 = aLen / 2 in let aLen3 = aLen + aLen2 in let aLen4 = aLen + aLen in let res0 = concat r01 r23 in let c6, res1 = bn_lshift_add_early_stop res0 t45 aLen2 in let c7 = c5 +. c6 in let c8, res2 = bn_lshift_add res1 c7 aLen3 in calc ( == ) { bn_v res2 + v c8 * pow2 (pbits * aLen4); ( == ) { bn_lshift_add_lemma res1 c7 aLen3 } bn_v res1 + v c7 * pow2 (pbits * aLen3); ( == ) { Math.Lemmas.small_mod (v c5 + v c6) (pow2 pbits) } bn_v res1 + (v c5 + v c6) * pow2 (pbits * aLen3); ( == ) { bn_lshift_add_early_stop_lemma res0 t45 aLen2 } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) - v c6 * pow2 (pbits * aLen3) + (v c5 + v c6) * pow2 (pbits * aLen3); ( == ) { Math.Lemmas.distributivity_add_left (v c5) (v c6) (pow2 (pbits * aLen3)) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * pow2 (pbits * aLen3); ( == ) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen2) } bn_v res0 + bn_v t45 * pow2 (pbits * aLen2) + v c5 * (pow2 (pbits * aLen) * pow2 (pbits * aLen2)); ( == ) { (Math.Lemmas.paren_mul_right (v c5) (pow2 (pbits * aLen)) (pow2 (pbits * aLen2)); Math.Lemmas.distributivity_add_left (bn_v t45) (v c5 * pow2 (pbits * aLen)) (pow2 (pbits * aLen2))) } bn_v res0 + (bn_v t45 + v c5 * pow2 (pbits * aLen)) * pow2 (pbits * aLen2); ( == ) { bn_concat_lemma r01 r23 } bn_v r23 * pow2 (pbits * aLen) + (v c5 * pow2 (pbits * aLen) + bn_v t45) * pow2 (pbits * aLen2) + bn_v r01; }
{ "checked_file": "Hacl.Spec.Bignum.Karatsuba.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Karatsuba.Lemmas.fst.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Karatsuba.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Base.carry", "Prims.op_Addition", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_lemma", "Prims.squash", "FStar.Math.Lemmas.small_mod", "Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop_lemma", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Spec.Bignum.Definitions.bn_concat_lemma", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Karatsuba.bn_lshift_add", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Dot", "Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Prims.op_Division", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Karatsuba open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Bignum.Lib open Hacl.Spec.Lib open Hacl.Spec.Bignum.Addition open Hacl.Spec.Bignum.Multiplication open Hacl.Spec.Bignum.Squaring module K = Hacl.Spec.Karatsuba.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_mul_threshold = 32 (* this carry means nothing but the sign of the result *) val bn_sign_abs: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> tuple2 (carry t) (lbignum t aLen) let bn_sign_abs #t #aLen a b = let c0, t0 = bn_sub a b in let c1, t1 = bn_sub b a in let res = map2 (mask_select (uint #t 0 -. c0)) t1 t0 in c0, res val bn_sign_abs_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> Lemma (let c, res = bn_sign_abs a b in bn_v res == K.abs (bn_v a) (bn_v b) /\ v c == (if bn_v a < bn_v b then 1 else 0)) let bn_sign_abs_lemma #t #aLen a b = let s, r = K.sign_abs (bn_v a) (bn_v b) in let c0, t0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v t0 - v c0 * pow2 (bits t * aLen) == bn_v a - bn_v b); let c1, t1 = bn_sub b a in bn_sub_lemma b a; assert (bn_v t1 - v c1 * pow2 (bits t * aLen) == bn_v b - bn_v a); let mask = uint #t 0 -. c0 in assert (v mask == (if v c0 = 0 then 0 else v (ones t SEC))); let res = map2 (mask_select mask) t1 t0 in lseq_mask_select_lemma t1 t0 mask; assert (bn_v res == (if v mask = 0 then bn_v t0 else bn_v t1)); bn_eval_bound a aLen; bn_eval_bound b aLen; bn_eval_bound t0 aLen; bn_eval_bound t1 aLen // if bn_v a < bn_v b then begin // assert (v mask = v (ones U64 SEC)); // assert (bn_v res == bn_v b - bn_v a); // assert (bn_v res == r /\ v c0 = 1) end // else begin // assert (v mask = 0); // assert (bn_v res == bn_v a - bn_v b); // assert (bn_v res == r /\ v c0 = 0) end; // assert (bn_v res == r /\ v c0 == (if bn_v a < bn_v b then 1 else 0)) val bn_middle_karatsuba: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> limb t & lbignum t aLen let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 = let c_sign = c0 ^. c1 in let c3, t45 = bn_sub t01 t23 in let c3 = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4 = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45 = map2 (mask_select mask) t67 t45 in let c5 = mask_select mask c4 c3 in c5, t45 val sign_lemma: #t:limb_t -> c0:carry t -> c1:carry t -> Lemma (v (c0 ^. c1) == (if v c0 = v c1 then 0 else 1)) let sign_lemma #t c0 c1 = logxor_spec c0 c1; match t with | U32 -> assert_norm (UInt32.logxor 0ul 0ul == 0ul); assert_norm (UInt32.logxor 0ul 1ul == 1ul); assert_norm (UInt32.logxor 1ul 0ul == 1ul); assert_norm (UInt32.logxor 1ul 1ul == 0ul) | U64 -> assert_norm (UInt64.logxor 0uL 0uL == 0uL); assert_norm (UInt64.logxor 0uL 1uL == 1uL); assert_norm (UInt64.logxor 1uL 0uL == 1uL); assert_norm (UInt64.logxor 1uL 1uL == 0uL) val bn_middle_karatsuba_lemma: #t:limb_t -> #aLen:size_nat -> c0:carry t -> c1:carry t -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (let (c, res) = bn_middle_karatsuba c0 c1 c2 t01 t23 in let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then v c == v c3' /\ bn_v res == bn_v t45 else v c == v c4' /\ bn_v res == bn_v t67) let bn_middle_karatsuba_lemma #t #aLen c0 c1 c2 t01 t23 = let lp = bn_v t01 + v c2 * pow2 (bits t * aLen) - bn_v t23 in let rp = bn_v t01 + v c2 * pow2 (bits t * aLen) + bn_v t23 in let c_sign = c0 ^. c1 in sign_lemma c0 c1; assert (v c_sign == (if v c0 = v c1 then 0 else 1)); let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in let mask = uint #t 0 -. c_sign in let t45' = map2 (mask_select mask) t67 t45 in lseq_mask_select_lemma t67 t45 mask; //assert (bn_v t45' == (if v mask = 0 then bn_v t45 else bn_v t67)); let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3' //assert (v c5 == (if v mask = 0 then v c3' else v c4')); val bn_middle_karatsuba_eval_aux: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> res:lbignum t aLen -> c2:carry t -> c3:carry t -> Lemma (requires bn_v res + (v c2 - v c3) * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0) (ensures 0 <= v c2 - v c3 /\ v c2 - v c3 <= 1) let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 = bn_eval_bound res aLen val bn_middle_karatsuba_eval: #t:limb_t -> #aLen:size_nat -> a0:lbignum t (aLen / 2) -> a1:lbignum t (aLen / 2) -> b0:lbignum t (aLen / 2) -> b1:lbignum t (aLen / 2) -> c2:carry t -> t01:lbignum t aLen -> t23:lbignum t aLen -> Lemma (requires (let t0 = K.abs (bn_v a0) (bn_v a1) in let t1 = K.abs (bn_v b0) (bn_v b1) in bn_v t01 + v c2 * pow2 (bits t * aLen) == bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 /\ bn_v t23 == t0 * t1)) (ensures (let c0, t0 = bn_sign_abs a0 a1 in let c1, t1 = bn_sign_abs b0 b1 in let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_v res + v c * pow2 (bits t * aLen) == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0)) let bn_middle_karatsuba_eval #t #aLen a0 a1 b0 b1 c2 t01 t23 = let pbits = bits t in let c0, t0 = bn_sign_abs a0 a1 in bn_sign_abs_lemma a0 a1; assert (bn_v t0 == K.abs (bn_v a0) (bn_v a1)); assert (v c0 == (if bn_v a0 < bn_v a1 then 1 else 0)); let c1, t1 = bn_sign_abs b0 b1 in bn_sign_abs_lemma b0 b1; assert (bn_v t1 == K.abs (bn_v b0) (bn_v b1)); assert (v c1 == (if bn_v b0 < bn_v b1 then 1 else 0)); let c, res = bn_middle_karatsuba c0 c1 c2 t01 t23 in bn_middle_karatsuba_lemma c0 c1 c2 t01 t23; let c3, t45 = bn_sub t01 t23 in let c3' = c2 -. c3 in let c4, t67 = bn_add t01 t23 in let c4' = c2 +. c4 in if v c0 = v c1 then begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 - bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c3' /\ bn_v res == bn_v t45); //assert (v c = (v c2 - v c3) % pow2 pb); bn_sub_lemma t01 t23; assert (bn_v res - v c3 * pow2 (pbits * aLen) == bn_v t01 - bn_v t23); Math.Lemmas.distributivity_sub_left (v c2) (v c3) (pow2 (pbits * aLen)); assert (bn_v res + (v c2 - v c3) * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); bn_middle_karatsuba_eval_aux a0 a1 b0 b1 res c2 c3; Math.Lemmas.small_mod (v c2 - v c3) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 - bn_v t23); () end else begin assert (bn_v a0 * bn_v b0 + bn_v a1 * bn_v b1 + bn_v t0 * bn_v t1 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23 == bn_v a0 * bn_v b1 + bn_v a1 * bn_v b0); assert (v c == v c4' /\ bn_v res == bn_v t67); //assert (v c = v c2 + v c4); bn_add_lemma t01 t23; assert (bn_v res + v c4 * pow2 (pbits * aLen) == bn_v t01 + bn_v t23); Math.Lemmas.distributivity_add_left (v c2) (v c4) (pow2 (pbits * aLen)); Math.Lemmas.small_mod (v c2 + v c4) (pow2 pbits); assert (bn_v res + v c * pow2 (pbits * aLen) == v c2 * pow2 (pbits * aLen) + bn_v t01 + bn_v t23); () end val bn_lshift_add: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add #t #aLen a b1 i = let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in c, a' val bn_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b1:limb t -> i:nat{i + 1 <= aLen} -> Lemma (let c, res = bn_lshift_add a b1 i in bn_v res + v c * pow2 (bits t * aLen) == bn_v a + v b1 * pow2 (bits t * i)) let bn_lshift_add_lemma #t #aLen a b1 i = let pbits = bits t in let r = sub a i (aLen - i) in let c, r' = bn_add1 r b1 in let a' = update_sub a i (aLen - i) r' in let p = pow2 (pbits * aLen) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add1_lemma r b1 } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (v b1 - v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + (v b1 - v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (v b1) (v c * pow2 (pbits * (aLen - i))) (pow2 (pbits * i)) } bn_v a + v b1 * pow2 (pbits * i) - (v c * pow2 (pbits * (aLen - i))) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * (aLen - i))) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * (aLen - i)) (pbits * i) } bn_v a + v b1 * pow2 (pbits * i); } val bn_lshift_add_early_stop: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> tuple2 (carry t) (lbignum t aLen) let bn_lshift_add_early_stop #t #aLen #bLen a b i = let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in c, a' val bn_lshift_add_early_stop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i + bLen <= aLen} -> Lemma (let c, res = bn_lshift_add_early_stop a b i in bn_v res + v c * pow2 (bits t * (i + bLen)) == bn_v a + bn_v b * pow2 (bits t * i)) let bn_lshift_add_early_stop_lemma #t #aLen #bLen a b i = let pbits = bits t in let r = sub a i bLen in let c, r' = bn_add r b in let a' = update_sub a i bLen r' in let p = pow2 (pbits * (i + bLen)) in calc (==) { bn_v a' + v c * p; (==) { bn_update_sub_eval a r' i } bn_v a - bn_v r * pow2 (pbits * i) + bn_v r' * pow2 (pbits * i) + v c * p; (==) { bn_add_lemma r b } bn_v a - bn_v r * pow2 (pbits * i) + (bn_v r + bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_add_left (bn_v r) (bn_v b - v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + (bn_v b - v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.distributivity_sub_left (bn_v b) (v c * pow2 (pbits * bLen)) (pow2 (pbits * i)) } bn_v a + bn_v b * pow2 (pbits * i) - (v c * pow2 (pbits * bLen)) * pow2 (pbits * i) + v c * p; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * bLen)) (pow2 (pbits * i)); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * i) } bn_v a + bn_v b * pow2 (pbits * i); } val bn_karatsuba_res: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t -> t45:lbignum t aLen -> tuple2 (carry t) (lbignum t (aLen + aLen)) let bn_karatsuba_res #t #aLen r01 r23 c5 t45 = let aLen2 = aLen / 2 in let res = concat r01 r23 in let c6, res = bn_lshift_add_early_stop res t45 aLen2 in // let r12 = sub res aLen2 aLen in // let c6, r12 = bn_add r12 t45 in // let res = update_sub res aLen2 aLen r12 in let c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in // let r3 = sub res (aLen + aLen2) aLen2 in // let _, r3 = bn_add r3 (create 1 c7) in // let res = update_sub res (aLen + aLen2) aLen2 r3 in c8, res val bn_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01)
false
false
Hacl.Spec.Bignum.Karatsuba.fst
{ "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_karatsuba_res_lemma: #t:limb_t -> #aLen:size_pos{2 * aLen <= max_size_t} -> r01:lbignum t aLen -> r23:lbignum t aLen -> c5:limb t{v c5 <= 1} -> t45:lbignum t aLen -> Lemma (let c, res = bn_karatsuba_res r01 r23 c5 t45 in bn_v res + v c * pow2 (bits t * (aLen + aLen)) == bn_v r23 * pow2 (bits t * aLen) + (v c5 * pow2 (bits t * aLen) + bn_v t45) * pow2 (aLen / 2 * bits t) + bn_v r01)
[]
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r01: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> r23: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c5: Hacl.Spec.Bignum.Definitions.limb t {Lib.IntTypes.v c5 <= 1} -> t45: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_res r01 r23 c5 t45 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Hacl.Spec.Bignum.Definitions.bn_v res + Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * (aLen + aLen)) == Hacl.Spec.Bignum.Definitions.bn_v r23 * Prims.pow2 (Lib.IntTypes.bits t * aLen) + (Lib.IntTypes.v c5 * Prims.pow2 (Lib.IntTypes.bits t * aLen) + Hacl.Spec.Bignum.Definitions.bn_v t45) * Prims.pow2 ((aLen / 2) * Lib.IntTypes.bits t) + Hacl.Spec.Bignum.Definitions.bn_v r01) <: Type0))
{ "end_col": 5, "end_line": 407, "start_col": 52, "start_line": 378 }
FStar.Tactics.Effect.Tac
val tmatch (t1 t2: term) : Tac bool
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2
val tmatch (t1 t2: term) : Tac bool let tmatch (t1 t2: term) : Tac bool =
true
null
false
let e = cur_env () in match_env e t1 t2
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.match_env", "Prims.bool", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2
false
false
FStar.Tactics.V1.Derived.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 tmatch (t1 t2: term) : Tac bool
[]
FStar.Tactics.V1.Derived.tmatch
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t1: FStar.Reflection.Types.term -> t2: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
{ "end_col": 21, "end_line": 288, "start_col": 38, "start_line": 286 }
FStar.Tactics.Effect.Tac
val binder_to_string (b: binder) : Tac string
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b)
val binder_to_string (b: binder) : Tac string let binder_to_string (b: binder) : Tac string =
true
null
false
bv_to_string (bv_of_binder b)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.binder", "FStar.Tactics.V1.Derived.bv_to_string", "FStar.Reflection.V1.Derived.bv_of_binder", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b)
false
false
FStar.Tactics.V1.Derived.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 binder_to_string (b: binder) : Tac string
[]
FStar.Tactics.V1.Derived.binder_to_string
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac Prims.string
{ "end_col": 33, "end_line": 43, "start_col": 4, "start_line": 43 }
FStar.Tactics.Effect.Tac
val cur_binders: Prims.unit -> Tac binders
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 cur_binders () : Tac binders = binders_of_env (cur_env ())
val cur_binders: Prims.unit -> Tac binders let cur_binders () : Tac binders =
true
null
false
binders_of_env (cur_env ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Reflection.V1.Builtins.binders_of_env", "FStar.Reflection.Types.binders", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *)
false
false
FStar.Tactics.V1.Derived.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 cur_binders: Prims.unit -> Tac binders
[]
FStar.Tactics.V1.Derived.cur_binders
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.binders
{ "end_col": 31, "end_line": 84, "start_col": 4, "start_line": 84 }
FStar.Tactics.Effect.Tac
val intro_as (s: string) : Tac binder
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s
val intro_as (s: string) : Tac binder let intro_as (s: string) : Tac binder =
true
null
false
let b = intro () in rename_to b s
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.string", "FStar.Tactics.V1.Builtins.rename_to", "FStar.Reflection.Types.binder", "FStar.Tactics.V1.Builtins.intro" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro ()
false
false
FStar.Tactics.V1.Derived.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 intro_as (s: string) : Tac binder
[]
FStar.Tactics.V1.Derived.intro_as
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.binder
{ "end_col": 17, "end_line": 520, "start_col": 38, "start_line": 518 }
FStar.Tactics.Effect.Tac
val is_guard: Prims.unit -> Tac bool
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ())
val is_guard: Prims.unit -> Tac bool let is_guard () : Tac bool =
true
null
false
Tactics.Types.is_guard (_cur_goal ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.is_guard", "Prims.bool", "FStar.Tactics.Types.goal", "FStar.Tactics.V1.Derived._cur_goal" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *)
false
false
FStar.Tactics.V1.Derived.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 is_guard: Prims.unit -> Tac bool
[]
FStar.Tactics.V1.Derived.is_guard
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.bool
{ "end_col": 41, "end_line": 482, "start_col": 4, "start_line": 482 }
FStar.Tactics.Effect.Tac
val fresh_uvar (o: option typ) : Tac term
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o
val fresh_uvar (o: option typ) : Tac term let fresh_uvar (o: option typ) : Tac term =
true
null
false
let e = cur_env () in uvar_env e o
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Pervasives.Native.option", "FStar.Reflection.Types.typ", "FStar.Tactics.V1.Builtins.uvar_env", "FStar.Reflection.Types.term", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ())
false
false
FStar.Tactics.V1.Derived.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 fresh_uvar (o: option typ) : Tac term
[]
FStar.Tactics.V1.Derived.fresh_uvar
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
o: FStar.Pervasives.Native.option FStar.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
{ "end_col": 16, "end_line": 276, "start_col": 44, "start_line": 274 }
FStar.Tactics.Effect.Tac
val mapply (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 mapply (t : term) : Tac unit = apply_squash_or_lem 10 t
val mapply (t: term) : Tac unit let mapply (t: term) : Tac unit =
true
null
false
apply_squash_or_lem 10 t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.apply_squash_or_lem", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : term = let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack_ln (Tv_Var (bv_of_binder e)) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect_ln lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binder) : Tac unit = match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> begin match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b))] | _ -> fail "grewrite_eq: binder type is not an equality" end private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end (* `m` is for `magic` *)
false
false
FStar.Tactics.V1.Derived.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 mapply (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.mapply
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 28, "end_line": 756, "start_col": 4, "start_line": 756 }
FStar.Tactics.Effect.Tac
val cur_env: Prims.unit -> Tac env
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 cur_env () : Tac env = goal_env (_cur_goal ())
val cur_env: Prims.unit -> Tac env let cur_env () : Tac env =
true
null
false
goal_env (_cur_goal ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.goal_env", "FStar.Reflection.Types.env", "FStar.Tactics.Types.goal", "FStar.Tactics.V1.Derived._cur_goal" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g
false
false
FStar.Tactics.V1.Derived.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 cur_env: Prims.unit -> Tac env
[]
FStar.Tactics.V1.Derived.cur_env
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.env
{ "end_col": 50, "end_line": 66, "start_col": 27, "start_line": 66 }
FStar.Tactics.Effect.Tac
val unify_guard (t1 t2: term) : Tac bool
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2
val unify_guard (t1 t2: term) : Tac bool let unify_guard (t1 t2: term) : Tac bool =
true
null
false
let e = cur_env () in unify_guard_env e t1 t2
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.unify_guard_env", "Prims.bool", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2
false
false
FStar.Tactics.V1.Derived.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 unify_guard (t1 t2: term) : Tac bool
[]
FStar.Tactics.V1.Derived.unify_guard
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t1: FStar.Reflection.Types.term -> t2: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
{ "end_col": 27, "end_line": 284, "start_col": 43, "start_line": 282 }
FStar.Tactics.Effect.Tac
val cur_witness: Prims.unit -> Tac term
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 cur_witness () : Tac term = goal_witness (_cur_goal ())
val cur_witness: Prims.unit -> Tac term let cur_witness () : Tac term =
true
null
false
goal_witness (_cur_goal ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.goal_witness", "FStar.Reflection.Types.term", "FStar.Tactics.Types.goal", "FStar.Tactics.V1.Derived._cur_goal" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ())
false
false
FStar.Tactics.V1.Derived.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 cur_witness: Prims.unit -> Tac term
[]
FStar.Tactics.V1.Derived.cur_witness
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
{ "end_col": 59, "end_line": 72, "start_col": 32, "start_line": 72 }
FStar.Tactics.Effect.Tac
val bv_to_string (bv: bv) : Tac string
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv
val bv_to_string (bv: bv) : Tac string let bv_to_string (bv: bv) : Tac string =
true
null
false
name_of_bv bv
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.bv", "FStar.Tactics.V1.Derived.name_of_bv", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string =
false
false
FStar.Tactics.V1.Derived.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 bv_to_string (bv: bv) : Tac string
[]
FStar.Tactics.V1.Derived.bv_to_string
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
bv: FStar.Reflection.Types.bv -> FStar.Tactics.Effect.Tac Prims.string
{ "end_col": 17, "end_line": 37, "start_col": 4, "start_line": 37 }
FStar.Tactics.Effect.Tac
val guards_to_smt: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 guards_to_smt () : Tac unit = let _ = repeat skip_guard in ()
val guards_to_smt: Prims.unit -> Tac unit let guards_to_smt () : Tac unit =
true
null
false
let _ = repeat skip_guard in ()
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.V1.Derived.repeat", "FStar.Tactics.V1.Derived.skip_guard" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail ""
false
false
FStar.Tactics.V1.Derived.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 guards_to_smt: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.guards_to_smt
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 6, "end_line": 491, "start_col": 33, "start_line": 489 }
FStar.Tactics.Effect.Tac
val pointwise (tau: (unit -> Tac unit)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau
val pointwise (tau: (unit -> Tac unit)) : Tac unit let pointwise (tau: (unit -> Tac unit)) : Tac unit =
true
null
false
t_pointwise BottomUp tau
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.t_pointwise", "FStar.Tactics.Types.BottomUp" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw
false
false
FStar.Tactics.V1.Derived.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 pointwise (tau: (unit -> Tac unit)) : Tac unit
[]
FStar.Tactics.V1.Derived.pointwise
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 77, "end_line": 265, "start_col": 53, "start_line": 265 }
FStar.Tactics.Effect.Tac
val simpl: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 simpl () : Tac unit = norm [simplify; primops]
val simpl: Prims.unit -> Tac unit let simpl () : Tac unit =
true
null
false
norm [simplify; primops]
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.simplify", "FStar.Pervasives.primops", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in ()
false
false
FStar.Tactics.V1.Derived.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 simpl: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.simpl
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 52, "end_line": 493, "start_col": 28, "start_line": 493 }
FStar.Tactics.Effect.Tac
val ngoals_smt: Prims.unit -> Tac int
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ())
val ngoals_smt: Prims.unit -> Tac int let ngoals_smt () : Tac int =
true
null
false
List.Tot.Base.length (smt_goals ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.List.Tot.Base.length", "FStar.Tactics.Types.goal", "Prims.int", "Prims.list", "FStar.Tactics.V1.Derived.smt_goals" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ())
false
false
FStar.Tactics.V1.Derived.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 ngoals_smt: Prims.unit -> Tac int
[]
FStar.Tactics.V1.Derived.ngoals_smt
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int
{ "end_col": 65, "end_line": 374, "start_col": 30, "start_line": 374 }
FStar.Tactics.Effect.Tac
val trivial: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial
val trivial: Prims.unit -> Tac unit let trivial () : Tac unit =
true
null
false
norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.exact", "FStar.Reflection.V1.Formula.formula", "FStar.Tactics.Effect.raise", "FStar.Tactics.V1.Derived.Goal_not_trivial", "FStar.Reflection.V1.Formula.term_as_formula", "FStar.Reflection.Types.typ", "FStar.Tactics.V1.Derived.cur_goal", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.reify_", "FStar.Pervasives.delta", "FStar.Pervasives.primops", "FStar.Pervasives.simplify", "FStar.Pervasives.unmeta", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t)
false
false
FStar.Tactics.V1.Derived.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 trivial: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.trivial
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 31, "end_line": 110, "start_col": 2, "start_line": 106 }
FStar.Tactics.Effect.Tac
val apply_lemma (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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_lemma (t : term) : Tac unit = t_apply_lemma false false t
val apply_lemma (t: term) : Tac unit let apply_lemma (t: term) : Tac unit =
true
null
false
t_apply_lemma false false t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.t_apply_lemma", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *)
false
false
FStar.Tactics.V1.Derived.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_lemma (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.apply_lemma
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 31, "end_line": 181, "start_col": 4, "start_line": 181 }
FStar.Tactics.Effect.Tac
val for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a)
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ())
val for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a) let for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a) =
true
null
false
map f (cur_binders ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.binder", "FStar.Tactics.Util.map", "Prims.list", "FStar.Tactics.V1.Derived.cur_binders", "FStar.Reflection.Types.binders" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s
false
false
FStar.Tactics.V1.Derived.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 for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a)
[]
FStar.Tactics.V1.Derived.for_each_binder
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
f: (_: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (Prims.list 'a)
{ "end_col": 26, "end_line": 527, "start_col": 4, "start_line": 527 }
FStar.Tactics.Effect.Tac
val admit1: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 admit1 () : Tac unit = tadmit ()
val admit1: Prims.unit -> Tac unit let admit1 () : Tac unit =
true
null
false
tadmit ()
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.tadmit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`())
false
false
FStar.Tactics.V1.Derived.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 admit1: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.admit1
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 13, "end_line": 474, "start_col": 4, "start_line": 474 }
FStar.Tactics.Effect.Tac
val trans: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 trans () : Tac unit = apply_lemma (`lem_trans)
val trans: Prims.unit -> Tac unit let trans () : Tac unit =
true
null
false
apply_lemma (`lem_trans)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.apply_lemma" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : term = let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack_ln (Tv_Var (bv_of_binder e)) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect_ln lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binder) : Tac unit = match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> begin match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b))] | _ -> fail "grewrite_eq: binder type is not an equality" end private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end (* `m` is for `magic` *) let mapply (t : term) : Tac unit = apply_squash_or_lem 10 t private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect_ln head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_binder] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_binder (-1)] will return the last binder, [nth_binder (-2)] the second to last, and so on. *) let nth_binder (i:int) : Tac binder = let bs = cur_binders () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect_ln t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | _ -> t in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') (** [string_to_term_with_lb [(id1, t1); ...; (idn, tn)] e s] parses [s] as a term in environment [e] augmented with bindings [id1, t1], ..., [idn, tn]. *) let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string): Tac term = let unk = pack_ln Tv_Unknown in let e, lb_bvs = fold_left (fun (e, lb_bvs) (i, v) -> let e, bv = push_bv_dsenv e i in e, (v,bv)::lb_bvs ) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, bv) -> pack (Tv_Let false [] bv unk i t)) t lb_bvs private val lem_trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) -> squash (x == y) -> squash (y == z) -> Lemma (x == z) private let lem_trans #a #x #z #y e1 e2 = ()
false
false
FStar.Tactics.V1.Derived.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 trans: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.trans
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 50, "end_line": 960, "start_col": 26, "start_line": 960 }
FStar.Tactics.Effect.Tac
val cur_goal: Prims.unit -> Tac typ
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 cur_goal () : Tac typ = goal_type (_cur_goal ())
val cur_goal: Prims.unit -> Tac typ let cur_goal () : Tac typ =
true
null
false
goal_type (_cur_goal ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.goal_type", "FStar.Reflection.Types.typ", "FStar.Tactics.Types.goal", "FStar.Tactics.V1.Derived._cur_goal" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ())
false
false
FStar.Tactics.V1.Derived.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 cur_goal: Prims.unit -> Tac typ
[]
FStar.Tactics.V1.Derived.cur_goal
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.typ
{ "end_col": 52, "end_line": 69, "start_col": 28, "start_line": 69 }
FStar.Tactics.Effect.Tac
val compute: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 compute () : Tac unit = norm [primops; iota; delta; zeta]
val compute: Prims.unit -> Tac unit let compute () : Tac unit =
true
null
false
norm [primops; iota; delta; zeta]
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.primops", "FStar.Pervasives.iota", "FStar.Pervasives.delta", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops]
false
false
FStar.Tactics.V1.Derived.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 compute: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.compute
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 61, "end_line": 495, "start_col": 28, "start_line": 495 }
Prims.Tot
val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 __cut a b f x = f x
val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b let __cut a b f x =
false
null
false
f x
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[ "total" ]
[]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros'
false
false
FStar.Tactics.V1.Derived.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 __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b
[]
FStar.Tactics.V1.Derived.__cut
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type -> b: Type -> f: (_: a -> b) -> x: a -> b
{ "end_col": 31, "end_line": 504, "start_col": 28, "start_line": 504 }
FStar.Tactics.Effect.Tac
val binder_sort (b: binder) : Tac typ
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort
val binder_sort (b: binder) : Tac typ let binder_sort (b: binder) : Tac typ =
true
null
false
(inspect_binder b).binder_sort
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.binder", "FStar.Reflection.V1.Data.__proj__Mkbinder_view__item__binder_sort", "FStar.Reflection.V1.Builtins.inspect_binder", "FStar.Reflection.Types.typ" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv
false
false
FStar.Tactics.V1.Derived.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 binder_sort (b: binder) : Tac typ
[]
FStar.Tactics.V1.Derived.binder_sort
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.typ
{ "end_col": 32, "end_line": 544, "start_col": 2, "start_line": 544 }
FStar.Tactics.Effect.Tac
val exact_args (qs: list aqualv) (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) )
val exact_args (qs: list aqualv) (t: term) : Tac unit let exact_args (qs: list aqualv) (t: term) : Tac unit =
true
null
false
focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv) (L.rev uvs))
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.list", "FStar.Reflection.V1.Data.aqualv", "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.focus", "Prims.unit", "FStar.Tactics.Util.iter", "FStar.Reflection.V1.Derived.is_uvar", "FStar.Tactics.V1.Builtins.unshelve", "Prims.bool", "FStar.List.Tot.Base.rev", "FStar.Tactics.V1.Derived.exact", "FStar.Reflection.V1.Derived.mk_app", "FStar.Reflection.V1.Data.argv", "FStar.Tactics.Util.zip", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.Util.repeatn", "FStar.Tactics.V1.Derived.fresh_uvar", "FStar.Pervasives.Native.None", "FStar.Reflection.Types.typ", "Prims.nat", "FStar.List.Tot.Base.length" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g)
false
false
FStar.Tactics.V1.Derived.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 exact_args (qs: list aqualv) (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.exact_args
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
qs: Prims.list FStar.Reflection.V1.Data.aqualv -> t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 5, "end_line": 365, "start_col": 4, "start_line": 357 }
FStar.Tactics.Effect.Tac
val pointwise' (tau: (unit -> Tac unit)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau
val pointwise' (tau: (unit -> Tac unit)) : Tac unit let pointwise' (tau: (unit -> Tac unit)) : Tac unit =
true
null
false
t_pointwise TopDown tau
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.t_pointwise", "FStar.Tactics.Types.TopDown" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw
false
false
FStar.Tactics.V1.Derived.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 pointwise' (tau: (unit -> Tac unit)) : Tac unit
[]
FStar.Tactics.V1.Derived.pointwise'
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 77, "end_line": 266, "start_col": 53, "start_line": 266 }
FStar.Tactics.Effect.Tac
val tcut (t: term) : Tac binder
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
val tcut (t: term) : Tac binder let tcut (t: term) : Tac binder =
true
null
false
let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.intro", "FStar.Reflection.Types.binder", "Prims.unit", "FStar.Tactics.V1.Derived.apply", "FStar.Reflection.V1.Derived.mk_e_app", "Prims.Cons", "Prims.Nil", "FStar.Reflection.Types.typ", "FStar.Tactics.V1.Derived.cur_goal" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x
false
false
FStar.Tactics.V1.Derived.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 tcut (t: term) : Tac binder
[]
FStar.Tactics.V1.Derived.tcut
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.binder
{ "end_col": 12, "end_line": 510, "start_col": 32, "start_line": 506 }
FStar.Tactics.Effect.Tac
val whnf: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 whnf () : Tac unit = norm [weak; hnf; primops; delta]
val whnf: Prims.unit -> Tac unit let whnf () : Tac unit =
true
null
false
norm [weak; hnf; primops; delta]
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.weak", "FStar.Pervasives.hnf", "FStar.Pervasives.primops", "FStar.Pervasives.delta", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in ()
false
false
FStar.Tactics.V1.Derived.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 whnf: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.whnf
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 60, "end_line": 494, "start_col": 28, "start_line": 494 }
FStar.Tactics.Effect.Tac
val unfold_def (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv"
val unfold_def (t: term) : Tac unit let unfold_def (t: term) : Tac unit =
true
null
false
match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv"
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Reflection.Types.fv", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_fully", "Prims.string", "Prims.Nil", "Prims.unit", "FStar.Reflection.V1.Builtins.implode_qn", "FStar.Reflection.V1.Builtins.inspect_fv", "FStar.Reflection.V1.Data.term_view", "FStar.Tactics.V1.Derived.fail", "FStar.Tactics.V1.Builtins.inspect" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ())
false
false
FStar.Tactics.V1.Derived.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 unfold_def (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.unfold_def
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 46, "end_line": 617, "start_col": 4, "start_line": 613 }
FStar.Tactics.Effect.Tac
val repeat' (f: (unit -> Tac 'a)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in ()
val repeat' (f: (unit -> Tac 'a)) : Tac unit let repeat' (f: (unit -> Tac 'a)) : Tac unit =
true
null
false
let _ = repeat f in ()
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.V1.Derived.repeat" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t
false
false
FStar.Tactics.V1.Derived.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' (f: (unit -> Tac 'a)) : Tac unit
[]
FStar.Tactics.V1.Derived.repeat'
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 26, "end_line": 442, "start_col": 45, "start_line": 441 }
FStar.Tactics.Effect.Tac
val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a)
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 (<|>) t1 t2 = fun () -> or_else t1 t2
val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let op_Less_Bar_Greater t1 t2 =
true
null
false
fun () -> or_else t1 t2
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.or_else" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) ->
false
false
FStar.Tactics.V1.Derived.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 (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a)
[]
FStar.Tactics.V1.Derived.op_Less_Bar_Greater
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t1: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> t2: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> _: Prims.unit -> FStar.Tactics.Effect.Tac 'a
{ "end_col": 41, "end_line": 428, "start_col": 18, "start_line": 428 }
FStar.Tactics.Effect.Tac
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 tadmit () = tadmit_t (`())
let tadmit () =
true
null
false
tadmit_t (`())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.tadmit_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.Tactics.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in ()
false
false
FStar.Tactics.V1.Derived.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 tadmit : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
[]
FStar.Tactics.V1.Derived.tadmit
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 30, "end_line": 471, "start_col": 16, "start_line": 471 }
Prims.Tot
val mk_squash (t: term) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
val mk_squash (t: term) : term let mk_squash (t: term) : term =
false
null
false
let sq:term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[ "total" ]
[ "FStar.Reflection.Types.term", "FStar.Reflection.V1.Derived.mk_e_app", "Prims.Cons", "Prims.Nil", "FStar.Reflection.V1.Builtins.pack_ln", "FStar.Reflection.V1.Data.Tv_FVar", "FStar.Reflection.V1.Builtins.pack_fv", "FStar.Reflection.Const.squash_qn" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl
false
true
FStar.Tactics.V1.Derived.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 mk_squash (t: term) : term
[]
FStar.Tactics.V1.Derived.mk_squash
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Reflection.Types.term
{ "end_col": 19, "end_line": 632, "start_col": 33, "start_line": 630 }
FStar.Tactics.Effect.Tac
val destruct_equality_implication (t: term) : Tac (option (formula * term))
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None
val destruct_equality_implication (t: term) : Tac (option (formula * term)) let destruct_equality_implication (t: term) : Tac (option (formula * term)) =
true
null
false
match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in (match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None) | _ -> None
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Pervasives.Native.option", "FStar.Reflection.Types.typ", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Reflection.V1.Formula.formula", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.None", "FStar.Reflection.V1.Formula.term_as_formula'", "FStar.Reflection.V1.Formula.term_as_formula" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ())
false
false
FStar.Tactics.V1.Derived.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 destruct_equality_implication (t: term) : Tac (option (formula * term))
[]
FStar.Tactics.V1.Derived.destruct_equality_implication
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.Reflection.V1.Formula.formula * FStar.Reflection.Types.term))
{ "end_col": 15, "end_line": 570, "start_col": 4, "start_line": 563 }
FStar.Tactics.Effect.Tac
val skip_guard: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 skip_guard () : Tac unit = if is_guard () then smt () else fail ""
val skip_guard: Prims.unit -> Tac unit let skip_guard () : Tac unit =
true
null
false
if is_guard () then smt () else fail ""
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.smt", "Prims.bool", "FStar.Tactics.V1.Derived.fail", "FStar.Tactics.V1.Derived.is_guard" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ())
false
false
FStar.Tactics.V1.Derived.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 skip_guard: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.skip_guard
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 16, "end_line": 487, "start_col": 4, "start_line": 485 }
FStar.Tactics.Effect.Tac
val add_elem (t: (unit -> Tac 'a)) : Tac 'a
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) )
val add_elem (t: (unit -> Tac 'a)) : Tac 'a let add_elem (t: (unit -> Tac 'a)) : Tac 'a =
true
null
false
focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x))
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.focus", "FStar.Tactics.V1.Derived.qed", "FStar.Tactics.V1.Derived.apply" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : term = let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack_ln (Tv_Var (bv_of_binder e)) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect_ln lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binder) : Tac unit = match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> begin match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b))] | _ -> fail "grewrite_eq: binder type is not an equality" end private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end (* `m` is for `magic` *) let mapply (t : term) : Tac unit = apply_squash_or_lem 10 t private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y
false
false
FStar.Tactics.V1.Derived.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 add_elem (t: (unit -> Tac 'a)) : Tac 'a
[]
FStar.Tactics.V1.Derived.add_elem
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
{ "end_col": 3, "end_line": 805, "start_col": 45, "start_line": 798 }
FStar.Tactics.Effect.Tac
val string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string): Tac term = let unk = pack_ln Tv_Unknown in let e, lb_bvs = fold_left (fun (e, lb_bvs) (i, v) -> let e, bv = push_bv_dsenv e i in e, (v,bv)::lb_bvs ) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, bv) -> pack (Tv_Let false [] bv unk i t)) t lb_bvs
val string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term =
true
null
false
let unk = pack_ln Tv_Unknown in let e, lb_bvs = fold_left (fun (e, lb_bvs) (i, v) -> let e, bv = push_bv_dsenv e i in e, (v, bv) :: lb_bvs) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, bv) -> pack (Tv_Let false [] bv unk i t)) t lb_bvs
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.string", "FStar.Reflection.Types.term", "FStar.Reflection.Types.env", "FStar.Reflection.Types.bv", "FStar.Tactics.Util.fold_left", "FStar.Tactics.V1.Builtins.pack", "FStar.Reflection.V1.Data.Tv_Let", "Prims.Nil", "FStar.Tactics.V1.Builtins.string_to_term", "FStar.Pervasives.Native.Mktuple2", "Prims.Cons", "FStar.Tactics.V1.Builtins.push_bv_dsenv", "FStar.Reflection.V1.Builtins.pack_ln", "FStar.Reflection.V1.Data.Tv_Unknown" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : term = let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack_ln (Tv_Var (bv_of_binder e)) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect_ln lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binder) : Tac unit = match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> begin match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b))] | _ -> fail "grewrite_eq: binder type is not an equality" end private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end (* `m` is for `magic` *) let mapply (t : term) : Tac unit = apply_squash_or_lem 10 t private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect_ln head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_binder] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_binder (-1)] will return the last binder, [nth_binder (-2)] the second to last, and so on. *) let nth_binder (i:int) : Tac binder = let bs = cur_binders () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect_ln t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | _ -> t in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') (** [string_to_term_with_lb [(id1, t1); ...; (idn, tn)] e s] parses [s] as a term in environment [e] augmented with bindings [id1, t1], ..., [idn, tn]. *) let string_to_term_with_lb (letbindings: list (string * term))
false
false
FStar.Tactics.V1.Derived.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 string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term
[]
FStar.Tactics.V1.Derived.string_to_term_with_lb
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
letbindings: Prims.list (Prims.string * FStar.Reflection.Types.term) -> e: FStar.Reflection.Types.env -> t: Prims.string -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
{ "end_col": 75, "end_line": 951, "start_col": 3, "start_line": 945 }
FStar.Tactics.Effect.Tac
val branch_on_match: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) )
val branch_on_match: Prims.unit -> Tac unit let branch_on_match () : Tac unit =
true
null
false
focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in grewrite_eq b; norm [iota]))
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.focus", "FStar.Tactics.V1.Derived.iterAll", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "Prims.Nil", "FStar.Tactics.V1.Derived.grewrite_eq", "FStar.Reflection.Types.binder", "FStar.Tactics.V1.Derived.last", "Prims.list", "FStar.Tactics.V1.Derived.repeat", "FStar.Tactics.V1.Builtins.intro", "FStar.Pervasives.Native.tuple2", "FStar.Reflection.Types.fv", "Prims.nat", "FStar.Tactics.V1.Builtins.t_destruct", "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.get_match_body" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : term = let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack_ln (Tv_Var (bv_of_binder e)) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect_ln lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binder) : Tac unit = match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> begin match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b))] | _ -> fail "grewrite_eq: binder type is not an equality" end private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end (* `m` is for `magic` *) let mapply (t : term) : Tac unit = apply_squash_or_lem 10 t private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect_ln head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *)
false
false
FStar.Tactics.V1.Derived.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 branch_on_match: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.branch_on_match
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 5, "end_line": 899, "start_col": 4, "start_line": 891 }
FStar.Tactics.Effect.Tac
val grewrite_eq (b: binder) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 grewrite_eq (b:binder) : Tac unit = match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> begin match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b))] | _ -> fail "grewrite_eq: binder type is not an equality" end
val grewrite_eq (b: binder) : Tac unit let grewrite_eq (b: binder) : Tac unit =
true
null
false
match term_as_formula (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact (binder_to_term b))] | _ -> match term_as_formula' (type_of_binder b) with | Comp (Eq _) l r -> grewrite l r; iseq [ idtac; (fun () -> apply_lemma (`__un_sq_eq); exact (binder_to_term b)) ] | _ -> fail "grewrite_eq: binder type is not an equality"
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.binder", "FStar.Pervasives.Native.option", "FStar.Reflection.Types.typ", "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.iseq", "Prims.Cons", "Prims.unit", "FStar.Tactics.V1.Derived.idtac", "FStar.Tactics.V1.Derived.exact", "FStar.Tactics.V1.Derived.binder_to_term", "Prims.Nil", "FStar.Tactics.V1.Derived.grewrite", "FStar.Reflection.V1.Formula.formula", "FStar.Tactics.V1.Derived.apply_lemma", "FStar.Tactics.V1.Derived.fail", "FStar.Reflection.V1.Formula.term_as_formula'", "FStar.Reflection.V1.Derived.type_of_binder", "FStar.Reflection.V1.Formula.term_as_formula" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ()) let rec revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl (* Some syntax utility functions *) let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv) [@@coercion] let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (bs : binders) : Tac unit = match bs with | [] -> fail "no assumption matches goal" | b::bs -> let t = binder_to_term b in try exact t with | _ -> try (apply (`FStar.Squash.return_squash); exact t) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_binders ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binder x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:binders) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_binders ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : term = let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack_ln (Tv_Var (bv_of_binder e)) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect_ln lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *)
false
false
FStar.Tactics.V1.Derived.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 grewrite_eq (b: binder) : Tac unit
[]
FStar.Tactics.V1.Derived.grewrite_eq
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 7, "end_line": 674, "start_col": 2, "start_line": 662 }
FStar.Tactics.Effect.Tac
val name_of_binder (b: binder) : Tac string
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b)
val name_of_binder (b: binder) : Tac string let name_of_binder (b: binder) : Tac string =
true
null
false
name_of_bv (bv_of_binder b)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.binder", "FStar.Tactics.V1.Derived.name_of_bv", "FStar.Reflection.V1.Derived.bv_of_binder", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv
false
false
FStar.Tactics.V1.Derived.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 name_of_binder (b: binder) : Tac string
[]
FStar.Tactics.V1.Derived.name_of_binder
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac Prims.string
{ "end_col": 31, "end_line": 40, "start_col": 4, "start_line": 40 }
FStar.Tactics.Effect.Tac
val apply (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 (t : term) : Tac unit = t_apply true false false t
val apply (t: term) : Tac unit let apply (t: term) : Tac unit =
true
null
false
t_apply true false false t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.t_apply", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *)
false
false
FStar.Tactics.V1.Derived.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 (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.apply
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 30, "end_line": 171, "start_col": 4, "start_line": 171 }
FStar.Tactics.Effect.Tac
val trefl_guard: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 trefl_guard () : Tac unit = t_trefl true
val trefl_guard: Prims.unit -> Tac unit let trefl_guard () : Tac unit =
true
null
false
t_trefl true
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.t_trefl" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *)
false
false
FStar.Tactics.V1.Derived.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 trefl_guard: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.trefl_guard
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 14, "end_line": 189, "start_col": 2, "start_line": 189 }
FStar.Tactics.Effect.Tac
val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw
val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit let t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit =
true
null
false
let ctrl (t: term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Tactics.Types.direction", "Prims.unit", "FStar.Tactics.V1.Builtins.ctrl_rewrite", "FStar.Reflection.Types.term", "FStar.Pervasives.Native.tuple2", "Prims.bool", "FStar.Tactics.Types.ctrl_flag", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.Types.Continue" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide
false
false
FStar.Tactics.V1.Derived.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 t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit
[]
FStar.Tactics.V1.Derived.t_pointwise
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
d: FStar.Tactics.Types.direction -> tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 24, "end_line": 228, "start_col": 67, "start_line": 221 }
FStar.Tactics.Effect.Tac
val exact (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t)
val exact (t: term) : Tac unit let exact (t: term) : Tac unit =
true
null
false
with_policy SMT (fun () -> t_exact true false t)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.with_policy", "Prims.unit", "FStar.Tactics.Types.SMT", "FStar.Tactics.V1.Builtins.t_exact" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *)
false
false
FStar.Tactics.V1.Derived.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 exact (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.exact
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 52, "end_line": 97, "start_col": 4, "start_line": 97 }
FStar.Tactics.Effect.Tac
val apply_raw (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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_raw (t : term) : Tac unit = t_apply false false false t
val apply_raw (t: term) : Tac unit let apply_raw (t: term) : Tac unit =
true
null
false
t_apply false false false t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.t_apply", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *)
false
false
FStar.Tactics.V1.Derived.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_raw (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.apply_raw
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 31, "end_line": 207, "start_col": 4, "start_line": 207 }
FStar.Tactics.Effect.Tac
val apply_lemma_noinst (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t
val apply_lemma_noinst (t: term) : Tac unit let apply_lemma_noinst (t: term) : Tac unit =
true
null
false
t_apply_lemma true false t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.t_apply_lemma", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *)
false
false
FStar.Tactics.V1.Derived.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_lemma_noinst (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.apply_lemma_noinst
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 30, "end_line": 198, "start_col": 4, "start_line": 198 }
FStar.Tactics.Effect.Tac
val apply_noinst (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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_noinst (t : term) : Tac unit = t_apply true true false t
val apply_noinst (t: term) : Tac unit let apply_noinst (t: term) : Tac unit =
true
null
false
t_apply true true false t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.t_apply", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t
false
false
FStar.Tactics.V1.Derived.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_noinst (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.apply_noinst
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 29, "end_line": 174, "start_col": 4, "start_line": 174 }
FStar.Tactics.Effect.Tac
val exact_with_ref (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t)
val exact_with_ref (t: term) : Tac unit let exact_with_ref (t: term) : Tac unit =
true
null
false
with_policy SMT (fun () -> t_exact true true t)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.with_policy", "Prims.unit", "FStar.Tactics.Types.SMT", "FStar.Tactics.V1.Builtins.t_exact" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *)
false
false
FStar.Tactics.V1.Derived.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 exact_with_ref (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.exact_with_ref
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 51, "end_line": 103, "start_col": 4, "start_line": 103 }
FStar.Tactics.Effect.Tac
val commute_applied_match: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 commute_applied_match () : Tac unit = t_commute_applied_match ()
val commute_applied_match: Prims.unit -> Tac unit let commute_applied_match () : Tac unit =
true
null
false
t_commute_applied_match ()
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.t_commute_applied_match" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *)
false
false
FStar.Tactics.V1.Derived.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 commute_applied_match: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.commute_applied_match
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 28, "end_line": 193, "start_col": 2, "start_line": 193 }
FStar.Tactics.Effect.Tac
val topdown_rewrite (ctrl: (term -> Tac (bool * int))) (rw: (unit -> Tac unit)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw
val topdown_rewrite (ctrl: (term -> Tac (bool * int))) (rw: (unit -> Tac unit)) : Tac unit let topdown_rewrite (ctrl: (term -> Tac (bool * int))) (rw: (unit -> Tac unit)) : Tac unit =
true
null
false
let ctrl' (t: term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Pervasives.Native.tuple2", "Prims.bool", "Prims.int", "Prims.unit", "FStar.Tactics.V1.Builtins.ctrl_rewrite", "FStar.Tactics.Types.TopDown", "FStar.Tactics.Types.ctrl_flag", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.Types.Continue", "FStar.Tactics.Types.Skip", "FStar.Tactics.Types.Abort", "FStar.Tactics.V1.Derived.fail" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int))
false
false
FStar.Tactics.V1.Derived.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 topdown_rewrite (ctrl: (term -> Tac (bool * int))) (rw: (unit -> Tac unit)) : Tac unit
[]
FStar.Tactics.V1.Derived.topdown_rewrite
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
ctrl: (_: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac (Prims.bool * Prims.int)) -> rw: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 33, "end_line": 263, "start_col": 3, "start_line": 252 }
FStar.Tactics.Effect.Tac
val later: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals"
val later: Prims.unit -> Tac unit let later () : Tac unit =
true
null
false
match goals () with | g :: gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals"
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.goal", "Prims.list", "FStar.Tactics.V1.Builtins.set_goals", "FStar.Tactics.V1.Derived.op_At", "Prims.Cons", "Prims.Nil", "FStar.Tactics.V1.Derived.fail", "FStar.Tactics.V1.Derived.goals" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *)
false
false
FStar.Tactics.V1.Derived.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 later: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.later
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 33, "end_line": 164, "start_col": 4, "start_line": 162 }
FStar.Tactics.Effect.Tac
val unify (t1 t2: term) : Tac bool
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2
val unify (t1 t2: term) : Tac bool let unify (t1 t2: term) : Tac bool =
true
null
false
let e = cur_env () in unify_env e t1 t2
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.unify_env", "Prims.bool", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o
false
false
FStar.Tactics.V1.Derived.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 unify (t1 t2: term) : Tac bool
[]
FStar.Tactics.V1.Derived.unify
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t1: FStar.Reflection.Types.term -> t2: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
{ "end_col": 21, "end_line": 280, "start_col": 37, "start_line": 278 }
FStar.Tactics.Effect.Tac
val seq (f g: (unit -> Tac unit)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g)
val seq (f g: (unit -> Tac unit)) : Tac unit let seq (f g: (unit -> Tac unit)) : Tac unit =
true
null
false
focus (fun () -> f (); iterAll g)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.focus", "FStar.Tactics.V1.Derived.iterAll" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *)
false
false
FStar.Tactics.V1.Derived.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 seq (f g: (unit -> Tac unit)) : Tac unit
[]
FStar.Tactics.V1.Derived.seq
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> g: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 37, "end_line": 354, "start_col": 4, "start_line": 354 }
FStar.Tactics.Effect.Tac
val open_modules: Prims.unit -> Tac (list name)
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 open_modules () : Tac (list name) = env_open_modules (top_env ())
val open_modules: Prims.unit -> Tac (list name) let open_modules () : Tac (list name) =
true
null
false
env_open_modules (top_env ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Reflection.V1.Builtins.env_open_modules", "Prims.list", "FStar.Reflection.Types.name", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Builtins.top_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ())
false
false
FStar.Tactics.V1.Derived.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 open_modules: Prims.unit -> Tac (list name)
[]
FStar.Tactics.V1.Derived.open_modules
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Reflection.Types.name)
{ "end_col": 33, "end_line": 272, "start_col": 4, "start_line": 272 }
FStar.Tactics.Effect.Tac
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 dump1 (m : string) = focus (fun () -> dump m)
let dump1 (m: string) =
true
null
false
focus (fun () -> dump m)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.string", "FStar.Tactics.V1.Derived.focus", "Prims.unit", "FStar.Tactics.V1.Builtins.dump" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x
false
false
FStar.Tactics.V1.Derived.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 dump1 : m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
[]
FStar.Tactics.V1.Derived.dump1
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 49, "end_line": 328, "start_col": 25, "start_line": 328 }
FStar.Tactics.Effect.Tac
val ngoals: Prims.unit -> Tac int
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 ngoals () : Tac int = List.Tot.Base.length (goals ())
val ngoals: Prims.unit -> Tac int let ngoals () : Tac int =
true
null
false
List.Tot.Base.length (goals ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.List.Tot.Base.length", "FStar.Tactics.Types.goal", "Prims.int", "Prims.list", "FStar.Tactics.V1.Derived.goals" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t
false
false
FStar.Tactics.V1.Derived.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 ngoals: Prims.unit -> Tac int
[]
FStar.Tactics.V1.Derived.ngoals
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int
{ "end_col": 57, "end_line": 371, "start_col": 26, "start_line": 371 }
FStar.Tactics.Effect.Tac
val qed: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!"
val qed: Prims.unit -> Tac unit let qed () : Tac unit =
true
null
false
match goals () with | [] -> () | _ -> fail "qed: not done!"
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.Types.goal", "FStar.Tactics.V1.Derived.fail", "FStar.Tactics.V1.Derived.goals" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *)
false
false
FStar.Tactics.V1.Derived.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 qed: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.qed
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 32, "end_line": 137, "start_col": 4, "start_line": 135 }
FStar.Tactics.Effect.Tac
val debug (m: string) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 debug (m:string) : Tac unit = if debugging () then print m
val debug (m: string) : Tac unit let debug (m: string) : Tac unit =
true
null
false
if debugging () then print m
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.string", "FStar.Tactics.V1.Builtins.print", "Prims.unit", "Prims.bool", "FStar.Tactics.V1.Builtins.debugging" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *)
false
false
FStar.Tactics.V1.Derived.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 debug (m: string) : Tac unit
[]
FStar.Tactics.V1.Derived.debug
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 32, "end_line": 143, "start_col": 4, "start_line": 143 }
FStar.Tactics.Effect.Tac
val name_of_bv (bv: bv) : Tac string
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname)
val name_of_bv (bv: bv) : Tac string let name_of_bv (bv: bv) : Tac string =
true
null
false
unseal ((inspect_bv bv).bv_ppname)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.bv", "FStar.Tactics.Unseal.unseal", "Prims.string", "FStar.Reflection.V1.Data.__proj__Mkbv_view__item__bv_ppname", "FStar.Reflection.V1.Builtins.inspect_bv" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At
false
false
FStar.Tactics.V1.Derived.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 name_of_bv (bv: bv) : Tac string
[]
FStar.Tactics.V1.Derived.name_of_bv
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
bv: FStar.Reflection.Types.bv -> FStar.Tactics.Effect.Tac Prims.string
{ "end_col": 38, "end_line": 33, "start_col": 4, "start_line": 33 }
FStar.Tactics.Effect.Tac
val exact_guard (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t)
val exact_guard (t: term) : Tac unit let exact_guard (t: term) : Tac unit =
true
null
false
with_policy Goal (fun () -> t_exact true false t)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.with_policy", "Prims.unit", "FStar.Tactics.Types.Goal", "FStar.Tactics.V1.Builtins.t_exact" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *)
false
false
FStar.Tactics.V1.Derived.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 exact_guard (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.exact_guard
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 53, "end_line": 212, "start_col": 4, "start_line": 212 }
FStar.Tactics.Effect.Tac
val goals: Prims.unit -> Tac (list goal)
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 goals () : Tac (list goal) = goals_of (get ())
val goals: Prims.unit -> Tac (list goal) let goals () : Tac (list goal) =
true
null
false
goals_of (get ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.goals_of", "Prims.list", "FStar.Tactics.Types.goal", "FStar.Tactics.Types.proofstate", "FStar.Tactics.Effect.get" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial
false
false
FStar.Tactics.V1.Derived.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 goals: Prims.unit -> Tac (list goal)
[]
FStar.Tactics.V1.Derived.goals
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.Types.goal)
{ "end_col": 50, "end_line": 47, "start_col": 33, "start_line": 47 }
FStar.Tactics.Effect.Tac
val apply_lemma_rw (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t
val apply_lemma_rw (t: term) : Tac unit let apply_lemma_rw (t: term) : Tac unit =
true
null
false
t_apply_lemma false true t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.term", "FStar.Tactics.V1.Builtins.t_apply_lemma", "Prims.unit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t
false
false
FStar.Tactics.V1.Derived.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_lemma_rw (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.apply_lemma_rw
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 30, "end_line": 201, "start_col": 4, "start_line": 201 }
FStar.Tactics.Effect.Tac
val smt_goals: Prims.unit -> Tac (list goal)
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 smt_goals () : Tac (list goal) = smt_goals_of (get ())
val smt_goals: Prims.unit -> Tac (list goal) let smt_goals () : Tac (list goal) =
true
null
false
smt_goals_of (get ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.Types.smt_goals_of", "Prims.list", "FStar.Tactics.Types.goal", "FStar.Tactics.Types.proofstate", "FStar.Tactics.Effect.get" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial
false
false
FStar.Tactics.V1.Derived.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 smt_goals: Prims.unit -> Tac (list goal)
[]
FStar.Tactics.V1.Derived.smt_goals
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.Types.goal)
{ "end_col": 58, "end_line": 48, "start_col": 37, "start_line": 48 }
FStar.Tactics.Effect.Tac
val fresh_bv: Prims.unit -> Tac bv
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i)
val fresh_bv: Prims.unit -> Tac bv let fresh_bv () : Tac bv =
true
null
false
let i = fresh () in fresh_bv_named ("x" ^ string_of_int i)
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.fresh_bv_named", "Prims.op_Hat", "Prims.string_of_int", "FStar.Reflection.Types.bv", "Prims.int", "FStar.Tactics.V1.Builtins.fresh" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also
false
false
FStar.Tactics.V1.Derived.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 fresh_bv: Prims.unit -> Tac bv
[]
FStar.Tactics.V1.Derived.fresh_bv
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.bv
{ "end_col": 42, "end_line": 383, "start_col": 26, "start_line": 378 }
FStar.Tactics.Effect.Tac
val iterAllSMT (t: (unit -> Tac unit)) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs')
val iterAllSMT (t: (unit -> Tac unit)) : Tac unit let iterAllSMT (t: (unit -> Tac unit)) : Tac unit =
true
null
false
let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs' @ sgs')
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.Types.goal", "FStar.Tactics.V1.Builtins.set_smt_goals", "FStar.Tactics.V1.Derived.op_At", "FStar.Tactics.V1.Builtins.set_goals", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.V1.Derived.smt_goals", "FStar.Tactics.V1.Derived.goals", "FStar.Tactics.V1.Derived.iterAll", "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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in ()
false
false
FStar.Tactics.V1.Derived.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 iterAllSMT (t: (unit -> Tac unit)) : Tac unit
[]
FStar.Tactics.V1.Derived.iterAllSMT
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 28, "end_line": 348, "start_col": 50, "start_line": 341 }
FStar.Tactics.Effect.Tac
val trefl: Prims.unit -> Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 trefl () : Tac unit = t_trefl false
val trefl: Prims.unit -> Tac unit let trefl () : Tac unit =
true
null
false
t_trefl false
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Tactics.V1.Builtins.t_trefl" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *)
false
false
FStar.Tactics.V1.Derived.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 trefl: Prims.unit -> Tac unit
[]
FStar.Tactics.V1.Derived.trefl
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 15, "end_line": 185, "start_col": 2, "start_line": 185 }
FStar.Tactics.Effect.Tac
val cur_module: Prims.unit -> Tac name
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 cur_module () : Tac name = moduleof (top_env ())
val cur_module: Prims.unit -> Tac name let cur_module () : Tac name =
true
null
false
moduleof (top_env ())
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.unit", "FStar.Reflection.V1.Builtins.moduleof", "FStar.Reflection.Types.name", "FStar.Reflection.Types.env", "FStar.Tactics.V1.Builtins.top_env" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau
false
false
FStar.Tactics.V1.Derived.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 cur_module: Prims.unit -> Tac name
[]
FStar.Tactics.V1.Derived.cur_module
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.name
{ "end_col": 25, "end_line": 269, "start_col": 4, "start_line": 269 }
FStar.Tactics.Effect.Tac
val exact_n (n: int) (t: term) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t
val exact_n (n: int) (t: term) : Tac unit let exact_n (n: int) (t: term) : Tac unit =
true
null
false
exact_args (repeatn n (fun () -> Q_Explicit)) t
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "Prims.int", "FStar.Reflection.Types.term", "FStar.Tactics.V1.Derived.exact_args", "Prims.unit", "Prims.list", "FStar.Reflection.V1.Data.aqualv", "FStar.Tactics.Util.repeatn", "FStar.Reflection.V1.Data.Q_Explicit" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) )
false
false
FStar.Tactics.V1.Derived.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 exact_n (n: int) (t: term) : Tac unit
[]
FStar.Tactics.V1.Derived.exact_n
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n: Prims.int -> t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 51, "end_line": 368, "start_col": 4, "start_line": 368 }
FStar.Tactics.Effect.Tac
val revert_all (bs: binders) : Tac unit
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V1", "short_module": null }, { "abbrev": 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 revert_all (bs:binders) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl
val revert_all (bs: binders) : Tac unit let rec revert_all (bs: binders) : Tac unit =
true
null
false
match bs with | [] -> () | _ :: tl -> revert (); revert_all tl
{ "checked_file": "FStar.Tactics.V1.Derived.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.V1.Builtins.fsti.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Types.fsti.checked", "FStar.Tactics.Result.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V1.Formula.fst.checked", "FStar.Reflection.V1.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V1.Derived.fst" }
[]
[ "FStar.Reflection.Types.binders", "Prims.unit", "FStar.Reflection.Types.binder", "Prims.list", "FStar.Tactics.V1.Derived.revert_all", "FStar.Tactics.V1.Builtins.revert" ]
[]
(* 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.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Types open FStar.Tactics.Effect open FStar.Tactics.Result open FStar.Tactics.Util open FStar.Tactics.V1.Builtins open FStar.Tactics.V1.SyntaxHelpers open FStar.VConfig module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).bv_ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = name_of_bv (bv_of_binder b) let binder_to_string (b : binder) : Tac string = bv_to_string (bv_of_binder b) //TODO: print aqual, attributes exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g (** [cur_binders] returns the list of binders in the current goal. *) let cur_binders () : Tac binders = binders_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_bv_named]. *) let fresh_bv () : Tac bv = (* These bvs are fresh anyway through a separate counter, * but adding the integer allows for more readability when * generating code *) let i = fresh () in fresh_bv_named ("x" ^ string_of_int i) let fresh_binder_named nm t : Tac binder = mk_binder (fresh_bv_named nm) t let fresh_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_binder_named ("x" ^ string_of_int i) t let fresh_implicit_binder_named nm t : Tac binder = mk_implicit_binder (fresh_bv_named nm) t let fresh_implicit_binder t : Tac binder = (* See comment in fresh_bv *) let i = fresh () in fresh_implicit_binder_named ("x" ^ string_of_int i) t let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binder) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ())
false
false
FStar.Tactics.V1.Derived.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 revert_all (bs: binders) : Tac unit
[ "recursion" ]
FStar.Tactics.V1.Derived.revert_all
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
bs: FStar.Reflection.Types.binders -> FStar.Tactics.Effect.Tac Prims.unit
{ "end_col": 28, "end_line": 533, "start_col": 4, "start_line": 530 }