file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.sign_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))
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)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 116, "start_col": 0, "start_line": 104 }
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 ->
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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)
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul
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)
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 522, "start_col": 0, "start_line": 521 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
Prims.Tot
[ "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_" ]
[]
false
false
false
false
false
let bn_karatsuba_mul #t #aLen a b =
bn_karatsuba_mul_ aLen a b
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_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))
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 363, "start_col": 0, "start_line": 349 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)
Prims.Tot
[ "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" ]
[]
false
false
false
false
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 c7 = c5 +. c6 in let c8, res = bn_lshift_add res c7 (aLen + aLen2) in c8, res
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.fail_silently
val fail_silently (#a: Type) (m: string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps))
val fail_silently (#a: Type) (m: string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps))
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)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 57, "start_col": 0, "start_line": 54 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.string -> FStar.Tactics.Effect.TAC a
FStar.Tactics.Effect.TAC
[]
[]
[ "Prims.string", "FStar.Tactics.Effect.raise", "FStar.Stubs.Tactics.Common.TacticFailure", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.set_urgency", "FStar.Stubs.Tactics.Types.proofstate", "FStar.Stubs.Tactics.Result.__result", "Prims.l_Forall", "FStar.Stubs.Tactics.Result.Failed", "Prims.logical" ]
[]
false
true
false
false
false
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)
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add
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)
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'
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 256, "start_col": 0, "start_line": 252 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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
Prims.Tot
[ "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" ]
[]
false
false
false
false
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'
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.fail
val fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps))
val fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps))
let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 52, "start_col": 0, "start_line": 50 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.V1.Derived open FStar.Reflection.V1 open FStar.Reflection.V1.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.string -> FStar.Tactics.Effect.TAC a
FStar.Tactics.Effect.TAC
[]
[]
[ "Prims.string", "FStar.Tactics.Effect.raise", "FStar.Stubs.Tactics.Common.TacticFailure", "FStar.Stubs.Tactics.Types.proofstate", "FStar.Stubs.Tactics.Result.__result", "FStar.Stubs.Tactics.Result.Failed" ]
[]
false
true
false
false
false
let fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) =
raise #a (TacticFailure m)
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr_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)
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 570, "start_col": 0, "start_line": 565 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.qed
val qed: Prims.unit -> Tac unit
val qed: Prims.unit -> Tac unit
let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!"
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 137, "start_col": 0, "start_line": 134 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "FStar.Tactics.V1.Derived.fail", "FStar.Tactics.V1.Derived.goals" ]
[]
false
true
false
false
false
let qed () : Tac unit =
match goals () with | [] -> () | _ -> fail "qed: not done!"
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.debug
val debug (m: string) : Tac unit
val debug (m: string) : Tac unit
let debug (m:string) : Tac unit = if debugging () then print m
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 143, "start_col": 0, "start_line": 142 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Stubs.Tactics.V1.Builtins.print", "Prims.unit", "Prims.bool", "FStar.Stubs.Tactics.V1.Builtins.debugging" ]
[]
false
true
false
false
false
let debug (m: string) : Tac unit =
if debugging () then print m
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived._cur_goal
val _cur_goal: Prims.unit -> Tac goal
val _cur_goal: Prims.unit -> Tac goal
let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 63, "start_col": 0, "start_line": 60 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Stubs.Tactics.Types.goal
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.fail", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Tactics.V1.Derived.goals" ]
[]
false
true
false
false
false
let _cur_goal () : Tac goal =
match goals () with | [] -> fail "no more goals" | g :: _ -> g
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.later
val later: Prims.unit -> Tac unit
val later: Prims.unit -> Tac unit
let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals"
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 164, "start_col": 0, "start_line": 161 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.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" ]
[]
false
true
false
false
false
let later () : Tac unit =
match goals () with | g :: gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals"
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.cur_goal_safe
val cur_goal_safe: Prims.unit -> TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0))
val cur_goal_safe: Prims.unit -> TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0))
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 80, "start_col": 0, "start_line": 77 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.TacH FStar.Stubs.Tactics.Types.goal
FStar.Tactics.Effect.TacH
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.Types.goals_of", "FStar.Stubs.Tactics.Types.proofstate", "FStar.Tactics.Effect.get", "Prims.l_not", "Prims.eq2", "Prims.Nil", "FStar.Stubs.Tactics.Result.__result", "Prims.l_Exists", "FStar.Stubs.Tactics.Result.Success" ]
[]
false
true
false
false
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.apply_noinst
val apply_noinst (t: term) : Tac unit
val apply_noinst (t: term) : Tac unit
let apply_noinst (t : term) : Tac unit = t_apply true true false t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 174, "start_col": 0, "start_line": 173 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.t_apply", "Prims.unit" ]
[]
false
true
false
false
false
let apply_noinst (t: term) : Tac unit =
t_apply true true false t
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr
val bn_karatsuba_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 618, "start_col": 0, "start_line": 617 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
Prims.Tot
[ "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_" ]
[]
false
false
false
false
false
let bn_karatsuba_sqr #t #aLen a =
bn_karatsuba_sqr_ aLen a
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_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)
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)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 540, "start_col": 0, "start_line": 533 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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)
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.apply
val apply (t: term) : Tac unit
val apply (t: term) : Tac unit
let apply (t : term) : Tac unit = t_apply true false false t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 171, "start_col": 0, "start_line": 170 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.t_apply", "Prims.unit" ]
[]
false
true
false
false
false
let apply (t: term) : Tac unit =
t_apply true false false t
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_sqr
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
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 553, "start_col": 0, "start_line": 551 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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
Prims.Tot
[ "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" ]
[]
false
false
false
false
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
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_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)
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 = 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)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 635, "start_col": 0, "start_line": 628 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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)
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.trefl
val trefl: Prims.unit -> Tac unit
val trefl: Prims.unit -> Tac unit
let trefl () : Tac unit = t_trefl false
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 185, "start_col": 0, "start_line": 184 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.t_trefl" ]
[]
false
true
false
false
false
let trefl () : Tac unit =
t_trefl false
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.apply_lemma
val apply_lemma (t: term) : Tac unit
val apply_lemma (t: term) : Tac unit
let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 181, "start_col": 0, "start_line": 180 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.t_apply_lemma", "Prims.unit" ]
[]
false
true
false
false
false
let apply_lemma (t: term) : Tac unit =
t_apply_lemma false false t
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_sign_abs_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))
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 69, "start_col": 0, "start_line": 49 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.commute_applied_match
val commute_applied_match: Prims.unit -> Tac unit
val commute_applied_match: Prims.unit -> Tac unit
let commute_applied_match () : Tac unit = t_commute_applied_match ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 193, "start_col": 0, "start_line": 192 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.t_commute_applied_match" ]
[]
false
true
false
false
false
let commute_applied_match () : Tac unit =
t_commute_applied_match ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.trefl_guard
val trefl_guard: Prims.unit -> Tac unit
val trefl_guard: Prims.unit -> Tac unit
let trefl_guard () : Tac unit = t_trefl true
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 189, "start_col": 0, "start_line": 188 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.t_trefl" ]
[]
false
true
false
false
false
let trefl_guard () : Tac unit =
t_trefl true
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_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)
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'
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 152, "start_col": 0, "start_line": 136 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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; let c5 = mask_select mask c4' c3' in mask_select_lemma mask c4' c3'
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_no_last_carry
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)
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)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 461, "start_col": 0, "start_line": 456 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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)
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.apply_lemma_noinst
val apply_lemma_noinst (t: term) : Tac unit
val apply_lemma_noinst (t: term) : Tac unit
let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 198, "start_col": 0, "start_line": 197 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.t_apply_lemma", "Prims.unit" ]
[]
false
true
false
false
false
let apply_lemma_noinst (t: term) : Tac unit =
t_apply_lemma true false t
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.apply_lemma_rw
val apply_lemma_rw (t: term) : Tac unit
val apply_lemma_rw (t: term) : Tac unit
let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 201, "start_col": 0, "start_line": 200 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.t_apply_lemma", "Prims.unit" ]
[]
false
true
false
false
false
let apply_lemma_rw (t: term) : Tac unit =
t_apply_lemma false true t
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.apply_raw
val apply_raw (t: term) : Tac unit
val apply_raw (t: term) : Tac unit
let apply_raw (t : term) : Tac unit = t_apply false false false t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 207, "start_col": 0, "start_line": 206 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.t_apply", "Prims.unit" ]
[]
false
true
false
false
false
let apply_raw (t: term) : Tac unit =
t_apply false false false t
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.exact_guard
val exact_guard (t: term) : Tac unit
val exact_guard (t: term) : Tac unit
let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 212, "start_col": 0, "start_line": 211 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.V1.Derived.with_policy", "Prims.unit", "FStar.Stubs.Tactics.Types.Goal", "FStar.Stubs.Tactics.V1.Builtins.t_exact" ]
[]
false
true
false
false
false
let exact_guard (t: term) : Tac unit =
with_policy Goal (fun () -> t_exact true false t)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.t_pointwise
val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit
val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 228, "start_col": 0, "start_line": 221 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: FStar.Stubs.Tactics.Types.direction -> tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Tactics.Types.direction", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.ctrl_rewrite", "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.tuple2", "Prims.bool", "FStar.Stubs.Tactics.Types.ctrl_flag", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Tactics.Types.Continue" ]
[]
false
true
false
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.dismiss
val dismiss: Prims.unit -> Tac unit
val dismiss: Prims.unit -> Tac unit
let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 124, "start_col": 0, "start_line": 121 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.fail", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V1.Builtins.set_goals", "FStar.Tactics.V1.Derived.goals" ]
[]
false
true
false
false
false
let dismiss () : Tac unit =
match goals () with | [] -> fail "dismiss: no more goals" | _ :: gs -> set_goals gs
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.pointwise'
val pointwise' (tau: (unit -> Tac unit)) : Tac unit
val pointwise' (tau: (unit -> Tac unit)) : Tac unit
let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 77, "end_line": 266, "start_col": 0, "start_line": 266 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.t_pointwise", "FStar.Stubs.Tactics.Types.TopDown" ]
[]
false
true
false
false
false
let pointwise' (tau: (unit -> Tac unit)) : Tac unit =
t_pointwise TopDown tau
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.flip
val flip: Prims.unit -> Tac unit
val flip: Prims.unit -> Tac unit
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)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 131, "start_col": 0, "start_line": 127 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.fail", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V1.Builtins.set_goals", "Prims.Cons", "FStar.Tactics.V1.Derived.goals" ]
[]
false
true
false
false
false
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)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.pointwise
val pointwise (tau: (unit -> Tac unit)) : Tac unit
val pointwise (tau: (unit -> Tac unit)) : Tac unit
let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 77, "end_line": 265, "start_col": 0, "start_line": 265 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.t_pointwise", "FStar.Stubs.Tactics.Types.BottomUp" ]
[]
false
true
false
false
false
let pointwise (tau: (unit -> Tac unit)) : Tac unit =
t_pointwise BottomUp tau
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.fresh_uvar
val fresh_uvar (o: option typ) : Tac term
val fresh_uvar (o: option typ) : Tac term
let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 276, "start_col": 0, "start_line": 274 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Tactics.V1.Builtins.uvar_env", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
false
true
false
false
false
let fresh_uvar (o: option typ) : Tac term =
let e = cur_env () in uvar_env e o
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.topdown_rewrite
val topdown_rewrite (ctrl: (term -> Tac (bool * int))) (rw: (unit -> Tac unit)) : Tac unit
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 = 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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 263, "start_col": 0, "start_line": 250 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ctrl: (_: FStar.Stubs.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
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.tuple2", "Prims.bool", "Prims.int", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.ctrl_rewrite", "FStar.Stubs.Tactics.Types.TopDown", "FStar.Stubs.Tactics.Types.ctrl_flag", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Tactics.Types.Continue", "FStar.Stubs.Tactics.Types.Skip", "FStar.Stubs.Tactics.Types.Abort", "FStar.Tactics.V1.Derived.fail" ]
[]
false
true
false
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.unify
val unify (t1 t2: term) : Tac bool
val unify (t1 t2: term) : Tac bool
let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 280, "start_col": 0, "start_line": 278 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.unify_env", "Prims.bool", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
false
true
false
false
false
let unify (t1 t2: term) : Tac bool =
let e = cur_env () in unify_env e t1 t2
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval_aux
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)
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 172, "start_col": 0, "start_line": 171 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
false
let bn_middle_karatsuba_eval_aux #t #aLen a0 a1 b0 b1 res c2 c3 =
bn_eval_bound res aLen
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.cur_module
val cur_module: Prims.unit -> Tac name
val cur_module: Prims.unit -> Tac name
let cur_module () : Tac name = moduleof (top_env ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 269, "start_col": 0, "start_line": 268 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.name
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Reflection.V1.Builtins.moduleof", "FStar.Stubs.Reflection.Types.name", "FStar.Stubs.Reflection.Types.env", "FStar.Stubs.Tactics.V1.Builtins.top_env" ]
[]
false
true
false
false
false
let cur_module () : Tac name =
moduleof (top_env ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.open_modules
val open_modules: Prims.unit -> Tac (list name)
val open_modules: Prims.unit -> Tac (list name)
let open_modules () : Tac (list name) = env_open_modules (top_env ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 272, "start_col": 0, "start_line": 271 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Stubs.Reflection.Types.name)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Reflection.V1.Builtins.env_open_modules", "Prims.list", "FStar.Stubs.Reflection.Types.name", "FStar.Stubs.Reflection.Types.env", "FStar.Stubs.Tactics.V1.Builtins.top_env" ]
[]
false
true
false
false
false
let open_modules () : Tac (list name) =
env_open_modules (top_env ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.tmatch
val tmatch (t1 t2: term) : Tac bool
val tmatch (t1 t2: term) : Tac bool
let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 288, "start_col": 0, "start_line": 286 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.match_env", "Prims.bool", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
false
true
false
false
false
let tmatch (t1 t2: term) : Tac bool =
let e = cur_env () in match_env e t1 t2
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.smt
val smt: Prims.unit -> Tac unit
val smt: Prims.unit -> Tac unit
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 156, "start_col": 0, "start_line": 149 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "FStar.Tactics.V1.Derived.fail", "FStar.Stubs.Tactics.V1.Builtins.set_smt_goals", "Prims.Cons", "FStar.Stubs.Tactics.V1.Builtins.set_goals", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.V1.Derived.smt_goals", "FStar.Tactics.V1.Derived.goals" ]
[]
false
true
false
false
false
let smt () : Tac unit =
match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g :: gs, gs' -> set_goals gs; set_smt_goals (g :: gs')
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.unify_guard
val unify_guard (t1 t2: term) : Tac bool
val unify_guard (t1 t2: term) : Tac bool
let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 284, "start_col": 0, "start_line": 282 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.unify_guard_env", "Prims.bool", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env" ]
[]
false
true
false
false
false
let unify_guard (t1 t2: term) : Tac bool =
let e = cur_env () in unify_guard_env e t1 t2
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.exact_args
val exact_args (qs: list aqualv) (t: term) : Tac unit
val exact_args (qs: list aqualv) (t: term) : Tac unit
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) )
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 365, "start_col": 0, "start_line": 356 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
qs: Prims.list FStar.Stubs.Reflection.V1.Data.aqualv -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.V1.Data.aqualv", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.V1.Derived.focus", "Prims.unit", "FStar.Tactics.Util.iter", "FStar.Reflection.V1.Derived.is_uvar", "FStar.Stubs.Tactics.V1.Builtins.unshelve", "Prims.bool", "FStar.List.Tot.Base.rev", "FStar.Tactics.V1.Derived.exact", "FStar.Reflection.V1.Derived.mk_app", "FStar.Stubs.Reflection.V1.Data.argv", "FStar.Tactics.Util.zip", "FStar.Pervasives.Native.tuple2", "Prims.l_or", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "FStar.Tactics.Util.repeatn", "FStar.Tactics.V1.Derived.fresh_uvar", "FStar.Pervasives.Native.None", "FStar.Stubs.Reflection.Types.typ", "Prims.nat" ]
[]
false
true
false
false
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) (L.rev uvs))
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.dump1
val dump1 : m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
let dump1 (m : string) = focus (fun () -> dump m)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 328, "start_col": 0, "start_line": 328 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Tactics.V1.Derived.focus", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.dump" ]
[]
false
true
false
false
false
let dump1 (m: string) =
focus (fun () -> dump m)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.ngoals_smt
val ngoals_smt: Prims.unit -> Tac int
val ngoals_smt: Prims.unit -> Tac int
let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 374, "start_col": 0, "start_line": 374 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.List.Tot.Base.length", "FStar.Stubs.Tactics.Types.goal", "Prims.int", "Prims.list", "FStar.Tactics.V1.Derived.smt_goals" ]
[]
false
true
false
false
false
let ngoals_smt () : Tac int =
List.Tot.Base.length (smt_goals ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.seq
val seq (f g: (unit -> Tac unit)) : Tac unit
val seq (f g: (unit -> Tac unit)) : Tac unit
let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 354, "start_col": 0, "start_line": 353 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> g: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.focus", "FStar.Tactics.V1.Derived.iterAll" ]
[]
false
true
false
false
false
let seq (f g: (unit -> Tac unit)) : Tac unit =
focus (fun () -> f (); iterAll g)
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_early_stop_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))
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); }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 337, "start_col": 0, "start_line": 317 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_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" ]
[]
false
false
true
false
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); }
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.exact_n
val exact_n (n: int) (t: term) : Tac unit
val exact_n (n: int) (t: term) : Tac unit
let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 368, "start_col": 0, "start_line": 367 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.int -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.int", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.V1.Derived.exact_args", "Prims.unit", "Prims.list", "FStar.Stubs.Reflection.V1.Data.aqualv", "FStar.Tactics.Util.repeatn", "FStar.Stubs.Reflection.V1.Data.Q_Explicit", "Prims.l_or", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "FStar.List.Tot.Base.length" ]
[]
false
true
false
false
false
let exact_n (n: int) (t: term) : Tac unit =
exact_args (repeatn n (fun () -> Q_Explicit)) t
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.iterAllSMT
val iterAllSMT (t: (unit -> Tac unit)) : Tac unit
val iterAllSMT (t: (unit -> Tac unit)) : Tac unit
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')
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 348, "start_col": 0, "start_line": 341 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "FStar.Stubs.Tactics.V1.Builtins.set_smt_goals", "FStar.Tactics.V1.Derived.op_At", "FStar.Stubs.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" ]
[]
false
true
false
false
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')
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.ngoals
val ngoals: Prims.unit -> Tac int
val ngoals: Prims.unit -> Tac int
let ngoals () : Tac int = List.Tot.Base.length (goals ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 371, "start_col": 0, "start_line": 371 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.List.Tot.Base.length", "FStar.Stubs.Tactics.Types.goal", "Prims.int", "Prims.list", "FStar.Tactics.V1.Derived.goals" ]
[]
false
true
false
false
false
let ngoals () : Tac int =
List.Tot.Base.length (goals ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.or_else
val or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a
val or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a
let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 423, "start_col": 0, "start_line": 421 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> t2: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> FStar.Tactics.Effect.Tac a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.try_with", "Prims.exn" ]
[]
false
true
false
false
false
let or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a =
try t1 () with | _ -> t2 ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.first
val first (ts: list (unit -> Tac 'a)) : Tac 'a
val first (ts: list (unit -> Tac 'a)) : Tac 'a
let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 431, "start_col": 0, "start_line": 430 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "Prims.unit", "FStar.List.Tot.Base.fold_right", "FStar.Tactics.V1.Derived.op_Less_Bar_Greater", "FStar.Tactics.V1.Derived.fail" ]
[]
false
true
false
false
false
let first (ts: list (unit -> Tac 'a)) : Tac 'a =
L.fold_right ( <|> ) ts (fun () -> fail "no tactics to try") ()
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_
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)
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 511, "start_col": 0, "start_line": 471 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 })
Prims.Tot
[ "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" ]
[ "recursion" ]
false
false
false
false
false
let rec bn_karatsuba_mul_ #t aLen a b =
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.trytac
val trytac (t: (unit -> Tac 'a)) : Tac (option 'a)
val trytac (t: (unit -> Tac 'a)) : Tac (option 'a)
let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 419, "start_col": 0, "start_line": 416 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option 'a)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.try_with", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "Prims.exn", "FStar.Pervasives.Native.None" ]
[]
false
true
false
false
false
let trytac (t: (unit -> Tac 'a)) : Tac (option 'a) =
try Some (t ()) with | _ -> None
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.fresh_bv
val fresh_bv: Prims.unit -> Tac bv
val fresh_bv: Prims.unit -> Tac bv
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)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 383, "start_col": 0, "start_line": 378 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.bv
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.fresh_bv_named", "Prims.op_Hat", "Prims.string_of_int", "FStar.Stubs.Reflection.Types.bv", "Prims.int", "FStar.Stubs.Tactics.V1.Builtins.fresh" ]
[]
false
true
false
false
false
let fresh_bv () : Tac bv =
let i = fresh () in fresh_bv_named ("x" ^ string_of_int i)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.repeat'
val repeat' (f: (unit -> Tac 'a)) : Tac unit
val repeat' (f: (unit -> Tac 'a)) : Tac unit
let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 442, "start_col": 0, "start_line": 441 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.V1.Derived.repeat" ]
[]
false
true
false
false
false
let repeat' (f: (unit -> Tac 'a)) : Tac unit =
let _ = repeat f in ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.repeat1
val repeat1 (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
val repeat1 (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 439, "start_col": 0, "start_line": 438 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> FStar.Tactics.Effect.Tac (Prims.list a)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.Cons", "Prims.list", "FStar.Tactics.V1.Derived.repeat" ]
[]
false
true
false
false
false
let repeat1 (#a: Type) (t: (unit -> Tac a)) : Tac (list a) =
t () :: repeat t
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.discard
val discard: tau: (unit -> Tac 'a) -> unit -> Tac unit
val discard: tau: (unit -> Tac 'a) -> unit -> Tac unit
let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 465, "start_col": 0, "start_line": 464 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit" ]
[]
false
true
false
false
false
let discard (tau: (unit -> Tac 'a)) : unit -> Tac unit =
fun () -> let _ = tau () in ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.tadmit
val tadmit : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
let tadmit () = tadmit_t (`())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 471, "start_col": 0, "start_line": 471 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.tadmit_t" ]
[]
false
true
false
false
false
let tadmit () =
tadmit_t (`())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.join_all_smt_goals
val join_all_smt_goals : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
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'
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 462, "start_col": 0, "start_line": 455 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "FStar.Stubs.Tactics.V1.Builtins.set_smt_goals", "FStar.Stubs.Tactics.V1.Builtins.set_goals", "FStar.Tactics.V1.Derived.goals", "FStar.Tactics.V1.Derived.repeat'", "FStar.Stubs.Tactics.V1.Builtins.join", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.V1.Derived.smt_goals" ]
[]
false
true
false
false
false
let join_all_smt_goals () =
let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in set_goals gs; set_smt_goals sgs'
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.admit1
val admit1: Prims.unit -> Tac unit
val admit1: Prims.unit -> Tac unit
let admit1 () : Tac unit = tadmit ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 474, "start_col": 0, "start_line": 473 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 (`())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.tadmit" ]
[]
false
true
false
false
false
let admit1 () : Tac unit =
tadmit ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.repeatseq
val repeatseq (#a: Type) (t: (unit -> Tac a)) : Tac unit
val repeatseq (#a: Type) (t: (unit -> Tac a)) : Tac unit
let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 88, "end_line": 469, "start_col": 0, "start_line": 468 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Pervasives.Native.option", "FStar.Tactics.V1.Derived.trytac", "FStar.Tactics.V1.Derived.seq", "FStar.Tactics.V1.Derived.discard", "FStar.Tactics.V1.Derived.repeatseq" ]
[ "recursion" ]
false
true
false
false
false
let rec repeatseq (#a: Type) (t: (unit -> Tac a)) : Tac unit =
let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.norm_term
val norm_term (s: list norm_step) (t: term) : Tac term
val norm_term (s: list norm_step) (t: term) : Tac term
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 449, "start_col": 0, "start_line": 444 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.list FStar.Pervasives.norm_step -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Pervasives.norm_step", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.norm_term_env", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.try_with", "Prims.unit", "FStar.Tactics.V1.Derived.cur_env", "Prims.exn", "FStar.Stubs.Tactics.V1.Builtins.top_env" ]
[]
false
true
false
false
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.admit_all
val admit_all: Prims.unit -> Tac unit
val admit_all: Prims.unit -> Tac unit
let admit_all () : Tac unit = let _ = repeat tadmit in ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 478, "start_col": 0, "start_line": 476 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.V1.Derived.repeat", "FStar.Tactics.V1.Derived.tadmit" ]
[]
false
true
false
false
false
let admit_all () : Tac unit =
let _ = repeat tadmit in ()
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_
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)
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 608, "start_col": 0, "start_line": 576 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 })
Prims.Tot
[ "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" ]
[ "recursion" ]
false
false
false
false
false
let rec bn_karatsuba_sqr_ #t aLen a =
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.skip_guard
val skip_guard: Prims.unit -> Tac unit
val skip_guard: Prims.unit -> Tac unit
let skip_guard () : Tac unit = if is_guard () then smt () else fail ""
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 487, "start_col": 0, "start_line": 484 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.Tactics.Types.is_guard (_cur_goal ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.smt", "Prims.bool", "FStar.Tactics.V1.Derived.fail", "FStar.Tactics.V1.Derived.is_guard" ]
[]
false
true
false
false
false
let skip_guard () : Tac unit =
if is_guard () then smt () else fail ""
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.guards_to_smt
val guards_to_smt: Prims.unit -> Tac unit
val guards_to_smt: Prims.unit -> Tac unit
let guards_to_smt () : Tac unit = let _ = repeat skip_guard in ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 491, "start_col": 0, "start_line": 489 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail ""
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.V1.Derived.repeat", "FStar.Tactics.V1.Derived.skip_guard" ]
[]
false
true
false
false
false
let guards_to_smt () : Tac unit =
let _ = repeat skip_guard in ()
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_lshift_add_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))
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); }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 288, "start_col": 0, "start_line": 268 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t 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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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); }
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.whnf
val whnf: Prims.unit -> Tac unit
val whnf: Prims.unit -> Tac unit
let whnf () : Tac unit = norm [weak; hnf; primops; delta]
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 494, "start_col": 0, "start_line": 494 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.weak", "FStar.Pervasives.hnf", "FStar.Pervasives.primops", "FStar.Pervasives.delta", "Prims.Nil" ]
[]
false
true
false
false
false
let whnf () : Tac unit =
norm [weak; hnf; primops; delta]
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.is_guard
val is_guard: Prims.unit -> Tac bool
val is_guard: Prims.unit -> Tac bool
let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 482, "start_col": 0, "start_line": 481 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.Types.is_guard", "Prims.bool", "FStar.Stubs.Tactics.Types.goal", "FStar.Tactics.V1.Derived._cur_goal" ]
[]
false
true
false
false
false
let is_guard () : Tac bool =
Stubs.Tactics.Types.is_guard (_cur_goal ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.compute
val compute: Prims.unit -> Tac unit
val compute: Prims.unit -> Tac unit
let compute () : Tac unit = norm [primops; iota; delta; zeta]
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 61, "end_line": 495, "start_col": 0, "start_line": 495 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.primops", "FStar.Pervasives.iota", "FStar.Pervasives.delta", "FStar.Pervasives.zeta", "Prims.Nil" ]
[]
false
true
false
false
false
let compute () : Tac unit =
norm [primops; iota; delta; zeta]
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.intros
val intros: Prims.unit -> Tac (list binder)
val intros: Prims.unit -> Tac (list binder)
let intros () : Tac (list binder) = repeat intro
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 497, "start_col": 0, "start_line": 497 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Stubs.Reflection.Types.binder)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.repeat", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Tactics.V1.Builtins.intro", "Prims.list" ]
[]
false
true
false
false
false
let intros () : Tac (list binder) =
repeat intro
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.simpl
val simpl: Prims.unit -> Tac unit
val simpl: Prims.unit -> Tac unit
let simpl () : Tac unit = norm [simplify; primops]
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 493, "start_col": 0, "start_line": 493 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.simplify", "FStar.Pervasives.primops", "Prims.Nil" ]
[]
false
true
false
false
false
let simpl () : Tac unit =
norm [simplify; primops]
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_carry_bound
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)
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)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 443, "start_col": 0, "start_line": 422 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.intros'
val intros': Prims.unit -> Tac unit
val intros': Prims.unit -> Tac unit
let intros' () : Tac unit = let _ = intros () in ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 499, "start_col": 0, "start_line": 499 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.V1.Derived.intros" ]
[]
false
true
false
false
false
let intros' () : Tac unit =
let _ = intros () in ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.__cut
val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b
val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b
let __cut a b f x = f x
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 504, "start_col": 8, "start_line": 504 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> f: (_: a -> b) -> x: a -> b
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let __cut a b f x =
f x
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.focus
val focus (t: (unit -> Tac 'a)) : Tac 'a
val focus (t: (unit -> Tac 'a)) : Tac 'a
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 325, "start_col": 0, "start_line": 317 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.fail", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V1.Builtins.set_smt_goals", "FStar.Tactics.V1.Derived.op_At", "FStar.Tactics.V1.Derived.smt_goals", "FStar.Stubs.Tactics.V1.Builtins.set_goals", "FStar.Tactics.V1.Derived.goals", "Prims.Nil", "Prims.Cons" ]
[]
false
true
false
false
false
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
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.intro_as
val intro_as (s: string) : Tac binder
val intro_as (s: string) : Tac binder
let intro_as (s:string) : Tac binder = let b = intro () in rename_to b s
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 520, "start_col": 0, "start_line": 518 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.binder
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Stubs.Tactics.V1.Builtins.rename_to", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Tactics.V1.Builtins.intro" ]
[]
false
true
false
false
false
let intro_as (s: string) : Tac binder =
let b = intro () in rename_to b s
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.tcut
val tcut (t: term) : Tac binder
val tcut (t: term) : Tac binder
let tcut (t:term) : Tac binder = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 510, "start_col": 0, "start_line": 506 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.binder
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.intro", "FStar.Stubs.Reflection.Types.binder", "Prims.unit", "FStar.Tactics.V1.Derived.apply", "FStar.Reflection.V1.Derived.mk_e_app", "Prims.Cons", "Prims.Nil", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.V1.Derived.cur_goal" ]
[]
false
true
false
false
false
let tcut (t: term) : Tac binder =
let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.bv_to_term
val bv_to_term (bv: bv) : Tac term
val bv_to_term (bv: bv) : Tac term
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 536, "start_col": 0, "start_line": 536 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
bv: FStar.Stubs.Reflection.Types.bv -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.bv", "FStar.Stubs.Tactics.V1.Builtins.pack", "FStar.Stubs.Reflection.V1.Data.Tv_Var", "FStar.Stubs.Reflection.Types.term" ]
[]
false
true
false
false
false
let bv_to_term (bv: bv) : Tac term =
pack (Tv_Var bv)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.iseq
val iseq (ts: list (unit -> Tac unit)) : Tac unit
val iseq (ts: list (unit -> Tac unit)) : Tac unit
let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 313, "start_col": 0, "start_line": 310 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "Prims.unit", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V1.Derived.divide", "FStar.Tactics.V1.Derived.iseq" ]
[ "recursion" ]
false
true
false
false
false
let rec iseq (ts: list (unit -> Tac unit)) : Tac unit =
match ts with | t :: ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.pose
val pose (t: term) : Tac binder
val pose (t: term) : Tac binder
let pose (t:term) : Tac binder = apply (`__cut); flip (); exact t; intro ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 516, "start_col": 0, "start_line": 512 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.binder
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.intro", "FStar.Stubs.Reflection.Types.binder", "Prims.unit", "FStar.Tactics.V1.Derived.exact", "FStar.Tactics.V1.Derived.flip", "FStar.Tactics.V1.Derived.apply" ]
[]
false
true
false
false
false
let pose (t: term) : Tac binder =
apply (`__cut); flip (); exact t; intro ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.try_with
val try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a
val try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a
let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 414, "start_col": 0, "start_line": 411 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> h: (_: Prims.exn -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.exn", "FStar.Pervasives.either", "FStar.Stubs.Tactics.V1.Builtins.catch" ]
[]
false
true
false
false
false
let try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a =
match catch f with | Inl e -> h e | Inr x -> x
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.for_each_binder
val for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a)
val for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a)
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) = map f (cur_binders ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 527, "start_col": 0, "start_line": 526 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: FStar.Stubs.Reflection.Types.binder -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (Prims.list 'a)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.Util.map", "Prims.list", "FStar.Tactics.V1.Derived.cur_binders", "FStar.Stubs.Reflection.Types.binders" ]
[]
false
true
false
false
false
let for_each_binder (f: (binder -> Tac 'a)) : Tac (list 'a) =
map f (cur_binders ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.pose_as
val pose_as (s: string) (t: term) : Tac binder
val pose_as (s: string) (t: term) : Tac binder
let pose_as (s:string) (t:term) : Tac binder = let b = pose t in rename_to b s
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 524, "start_col": 0, "start_line": 522 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.binder
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.rename_to", "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.V1.Derived.pose" ]
[]
false
true
false
false
false
let pose_as (s: string) (t: term) : Tac binder =
let b = pose t in rename_to b s
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.iterAll
val iterAll (t: (unit -> Tac unit)) : Tac unit
val iterAll (t: (unit -> Tac unit)) : Tac unit
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 ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 339, "start_col": 0, "start_line": 335 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V1.Derived.divide", "FStar.Tactics.V1.Derived.iterAll", "FStar.Tactics.V1.Derived.goals" ]
[ "recursion" ]
false
true
false
false
false
let rec iterAll (t: (unit -> Tac unit)) : Tac unit =
match goals () with | [] -> () | _ :: _ -> let _ = divide 1 t (fun () -> iterAll t) in ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.mapAll
val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a)
val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a)
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 333, "start_col": 0, "start_line": 330 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (Prims.list 'a)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.Nil", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "Prims.Cons", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V1.Derived.divide", "FStar.Tactics.V1.Derived.mapAll", "FStar.Tactics.V1.Derived.goals" ]
[ "recursion" ]
false
true
false
false
false
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
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.binder_sort
val binder_sort (b: binder) : Tac typ
val binder_sort (b: binder) : Tac typ
let binder_sort (b : binder) : Tac typ = (inspect_binder b).binder_sort
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 544, "start_col": 0, "start_line": 543 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Stubs.Reflection.Types.binder -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.typ
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V1.Data.__proj__Mkbinder_view__item__binder_sort", "FStar.Stubs.Reflection.V1.Builtins.inspect_binder", "FStar.Stubs.Reflection.Types.typ" ]
[]
false
true
false
false
false
let binder_sort (b: binder) : Tac typ =
(inspect_binder b).binder_sort
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.binder_to_term
val binder_to_term (b: binder) : Tac term
val binder_to_term (b: binder) : Tac term
let binder_to_term (b : binder) : Tac term = let bview = inspect_binder b in bv_to_term bview.binder_bv
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 541, "start_col": 0, "start_line": 539 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Stubs.Reflection.Types.binder -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.V1.Derived.bv_to_term", "FStar.Stubs.Reflection.V1.Data.__proj__Mkbinder_view__item__binder_bv", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V1.Data.binder_view", "Prims.precedes", "FStar.Stubs.Reflection.V1.Builtins.inspect_binder" ]
[]
false
true
false
false
false
let binder_to_term (b: binder) : Tac term =
let bview = inspect_binder b in bv_to_term bview.binder_bv
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.rewrite'
val rewrite' (b: binder) : Tac unit
val rewrite' (b: binder) : Tac unit
let rewrite' (b:binder) : Tac unit = ((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 583, "start_col": 0, "start_line": 577 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Stubs.Reflection.Types.binder -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.V1.Derived.op_Less_Bar_Greater", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.rewrite", "FStar.Tactics.V1.Derived.apply_lemma", "FStar.Stubs.Tactics.V1.Builtins.binder_retype", "FStar.Tactics.V1.Derived.fail" ]
[]
false
true
false
false
false
let rewrite' (b: binder) : Tac unit =
((fun () -> rewrite b) <|> (fun () -> binder_retype b; apply_lemma (`__eq_sym); rewrite b) <|> (fun () -> fail "rewrite' failed")) ()
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.guard
val guard (b: bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r))
val guard (b: bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r))
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 ()
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 409, "start_col": 0, "start_line": 401 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> FStar.Tactics.Effect.TacH Prims.unit
FStar.Tactics.Effect.TacH
[]
[]
[ "Prims.bool", "Prims.op_Negation", "FStar.Tactics.V1.Derived.fail", "Prims.unit", "FStar.Stubs.Tactics.Types.proofstate", "Prims.l_True", "FStar.Stubs.Tactics.Result.__result", "Prims.l_and", "Prims.b2t", "FStar.Stubs.Tactics.Result.uu___is_Success", "Prims.eq2", "FStar.Stubs.Tactics.Result.__proj__Success__item__ps", "FStar.Stubs.Tactics.Result.uu___is_Failed" ]
[]
false
true
false
false
false
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)) =
if not b then fail "guard failed"
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.assumption
val assumption: Prims.unit -> Tac unit
val assumption: Prims.unit -> Tac unit
let assumption () : Tac unit = __assumption_aux (cur_binders ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 560, "start_col": 0, "start_line": 559 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.__assumption_aux", "FStar.Stubs.Reflection.Types.binders", "FStar.Tactics.V1.Derived.cur_binders" ]
[]
false
true
false
false
false
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.rewrite_eqs_from_context
val rewrite_eqs_from_context: Prims.unit -> Tac unit
val rewrite_eqs_from_context: Prims.unit -> Tac unit
let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_binders ())
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 607, "start_col": 0, "start_line": 606 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.rewrite_all_context_equalities", "FStar.Stubs.Reflection.Types.binders", "FStar.Tactics.V1.Derived.cur_binders" ]
[]
false
true
false
false
false
let rewrite_eqs_from_context () : Tac unit =
rewrite_all_context_equalities (cur_binders ())
false
Hacl.Spec.Bignum.Karatsuba.fst
Hacl.Spec.Bignum.Karatsuba.bn_middle_karatsuba_eval
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))
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
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Karatsuba.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 241, "start_col": 0, "start_line": 198 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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 (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 ); ())
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.destruct_equality_implication
val destruct_equality_implication (t: term) : Tac (option (formula * term))
val destruct_equality_implication (t: term) : Tac (option (formula * term))
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 570, "start_col": 0, "start_line": 562 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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 ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.Reflection.V1.Formula.formula * FStar.Stubs.Reflection.Types.term))
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.option", "FStar.Stubs.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" ]
[]
false
true
false
false
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 (match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None) | _ -> None
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.divide
val divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b)
val divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b)
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)
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 308, "start_col": 0, "start_line": 293 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.int -> l: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> r: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'b) -> FStar.Tactics.Effect.Tac ('a * 'b)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.int", "Prims.unit", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Tactics.V1.Builtins.set_smt_goals", "FStar.Tactics.V1.Derived.op_At", "FStar.Stubs.Tactics.V1.Builtins.set_goals", "FStar.Tactics.V1.Derived.smt_goals", "FStar.Tactics.V1.Derived.goals", "Prims.Nil", "FStar.List.Tot.Base.splitAt", "Prims.op_LessThan", "FStar.Tactics.V1.Derived.fail", "Prims.bool" ]
[]
false
true
false
false
false
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)
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.mk_squash
val mk_squash (t: term) : term
val mk_squash (t: term) : term
let mk_squash (t : term) : term = let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 632, "start_col": 0, "start_line": 630 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Reflection.V1.Derived.mk_e_app", "Prims.Cons", "Prims.Nil", "FStar.Stubs.Reflection.V1.Builtins.pack_ln", "FStar.Stubs.Reflection.V1.Data.Tv_FVar", "FStar.Stubs.Reflection.V1.Builtins.pack_fv", "FStar.Reflection.Const.squash_qn" ]
[]
false
false
false
true
false
let mk_squash (t: term) : term =
let sq:term = pack_ln (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.unfold_def
val unfold_def (t: term) : Tac unit
val unfold_def (t: term) : Tac unit
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"
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 617, "start_col": 0, "start_line": 612 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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 ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_fully", "Prims.string", "Prims.Nil", "Prims.unit", "FStar.Stubs.Reflection.V1.Builtins.implode_qn", "FStar.Stubs.Reflection.V1.Builtins.inspect_fv", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Tactics.V1.Derived.fail", "FStar.Stubs.Tactics.V1.Builtins.inspect" ]
[]
false
true
false
false
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"
false
FStar.Tactics.V1.Derived.fst
FStar.Tactics.V1.Derived.l_to_r
val l_to_r (lems: list term) : Tac unit
val l_to_r (lems: list term) : Tac unit
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
{ "file_name": "ulib/FStar.Tactics.V1.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 628, "start_col": 0, "start_line": 622 }
(* 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.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Tactics.Util open FStar.Stubs.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 = Stubs.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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V1.SyntaxHelpers.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V1.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.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" }
[ { "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.Stubs.Tactics.V1.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lems: Prims.list FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.V1.Derived.pointwise", "Prims.unit", "FStar.Tactics.Util.fold_left", "FStar.Tactics.V1.Derived.or_else", "FStar.Tactics.V1.Derived.apply_lemma_rw", "FStar.Tactics.V1.Derived.trefl" ]
[]
false
true
false
false
false
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