| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
{ |
| 12 |
|
| 13 |
open Pp |
| 14 |
open Stdarg |
| 15 |
open Tacarg |
| 16 |
open Extraargs |
| 17 |
open Mod_subst |
| 18 |
open Names |
| 19 |
open CErrors |
| 20 |
open Util |
| 21 |
open Equality |
| 22 |
open Tactypes |
| 23 |
open Proofview.Notations |
| 24 |
open Attributes |
| 25 |
open Vernacextend |
| 26 |
open G_redexpr |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
DECLARE PLUGIN "rocq-runtime.plugins.ltac" |
| 31 |
|
| 32 |
TACTIC EXTEND assert_succeeds |
| 33 |
| [ "assert_succeeds" tactic3(tac) ] |
| 34 |
-> { Internals.assert_succeeds (Tacinterp.tactic_of_value ist tac) } |
| 35 |
END |
| 36 |
|
| 37 |
TACTIC EXTEND replace |
| 38 |
| [ "replace" uconstr(c1) "with" constr(c2) clause(cl) by_arg_tac(tac) ] |
| 39 |
-> { Internals.replace_in_clause_maybe_by ist None c1 c2 cl tac } |
| 40 |
END |
| 41 |
|
| 42 |
TACTIC EXTEND replace_term_left |
| 43 |
| [ "replace" "->" uconstr(c) clause(cl) ] |
| 44 |
-> { Internals.replace_term ist (Some true) c cl } |
| 45 |
END |
| 46 |
|
| 47 |
TACTIC EXTEND replace_left |
| 48 |
| ["replace" "->" uconstr(c1) "with" constr(c2) clause(cl) by_arg_tac(tac) ] |
| 49 |
-> { Internals.replace_in_clause_maybe_by ist (Some true) c1 c2 cl tac } |
| 50 |
END |
| 51 |
|
| 52 |
TACTIC EXTEND replace_term_right |
| 53 |
| [ "replace" "<-" uconstr(c) clause(cl) ] |
| 54 |
-> { Internals.replace_term ist (Some false) c cl } |
| 55 |
END |
| 56 |
|
| 57 |
TACTIC EXTEND replace_right |
| 58 |
| [ "replace" "<-" uconstr(c1) "with" constr(c2) clause(cl) by_arg_tac(tac) ] |
| 59 |
-> { Internals.replace_in_clause_maybe_by ist (Some false) c1 c2 cl tac } |
| 60 |
END |
| 61 |
|
| 62 |
TACTIC EXTEND replace_term |
| 63 |
| [ "replace" uconstr(c) clause(cl) ] |
| 64 |
-> { Internals.replace_term ist None c cl } |
| 65 |
END |
| 66 |
|
| 67 |
TACTIC EXTEND simplify_eq |
| 68 |
| [ "simplify_eq" ] -> { dEq ~keep_proofs:None false None } |
| 69 |
| [ "simplify_eq" destruction_arg(c) ] -> { Internals.mytclWithHoles (dEq ~keep_proofs:None) false c } |
| 70 |
END |
| 71 |
TACTIC EXTEND esimplify_eq |
| 72 |
| [ "esimplify_eq" ] -> { dEq ~keep_proofs:None true None } |
| 73 |
| [ "esimplify_eq" destruction_arg(c) ] -> { Internals.mytclWithHoles (dEq ~keep_proofs:None) true c } |
| 74 |
END |
| 75 |
|
| 76 |
TACTIC EXTEND discriminate |
| 77 |
| [ "discriminate" ] -> { discr_tac false None } |
| 78 |
| [ "discriminate" destruction_arg(c) ] -> |
| 79 |
{ Internals.mytclWithHoles discr_tac false c } |
| 80 |
END |
| 81 |
TACTIC EXTEND ediscriminate |
| 82 |
| [ "ediscriminate" ] -> { discr_tac true None } |
| 83 |
| [ "ediscriminate" destruction_arg(c) ] -> |
| 84 |
{ Internals.mytclWithHoles discr_tac true c } |
| 85 |
END |
| 86 |
|
| 87 |
{ |
| 88 |
|
| 89 |
let isInjPat pat = match pat.CAst.v with IntroAction (IntroInjection _) -> Some pat.CAst.loc | _ -> None |
| 90 |
|
| 91 |
let decode_inj_ipat ?loc = function |
| 92 |
(* For the "as [= pat1 ... patn ]" syntax *) |
| 93 |
| [{ CAst.v = IntroAction (IntroInjection ipat) }] -> ipat |
| 94 |
(* For the "as pat1 ... patn" syntax *) |
| 95 |
| ([] | [_]) as ipat -> ipat |
| 96 |
| pat1::pat2::_ as ipat -> |
| 97 |
(* To be sure that there is no confusion of syntax, we check that no [= ...] occurs |
| 98 |
in the non-singleton list of patterns *) |
| 99 |
match isInjPat pat1 with |
| 100 |
| Some _ -> user_err ?loc:pat2.CAst.loc (str "Unexpected pattern.") |
| 101 |
| None -> |
| 102 |
match List.map_filter isInjPat ipat with |
| 103 |
| loc :: _ -> user_err ?loc (str "Unexpected injection pattern.") |
| 104 |
| [] -> ipat |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
TACTIC EXTEND injection |
| 109 |
| [ "injection" ] -> { injClause None None false None } |
| 110 |
| [ "injection" destruction_arg(c) ] -> { Internals.mytclWithHoles (injClause None None) false c } |
| 111 |
END |
| 112 |
TACTIC EXTEND einjection |
| 113 |
| [ "einjection" ] -> { injClause None None true None } |
| 114 |
| [ "einjection" destruction_arg(c) ] -> { Internals.mytclWithHoles (injClause None None) true c } |
| 115 |
END |
| 116 |
TACTIC EXTEND injection_as |
| 117 |
| [ "injection" "as" simple_intropattern_list(ipat)] -> |
| 118 |
{ injClause None (Some (decode_inj_ipat ipat)) false None } |
| 119 |
| [ "injection" destruction_arg(c) "as" simple_intropattern_list(ipat)] -> |
| 120 |
{ Internals.mytclWithHoles (injClause None (Some (decode_inj_ipat ipat))) false c } |
| 121 |
END |
| 122 |
TACTIC EXTEND einjection_as |
| 123 |
| [ "einjection" "as" simple_intropattern_list(ipat)] -> |
| 124 |
{ injClause None (Some (decode_inj_ipat ipat)) true None } |
| 125 |
| [ "einjection" destruction_arg(c) "as" simple_intropattern_list(ipat)] -> |
| 126 |
{ Internals.mytclWithHoles (injClause None (Some (decode_inj_ipat ipat))) true c } |
| 127 |
END |
| 128 |
TACTIC EXTEND simple_injection |
| 129 |
| [ "simple" "injection" ] -> { simpleInjClause None false None } |
| 130 |
| [ "simple" "injection" destruction_arg(c) ] -> { Internals.mytclWithHoles (simpleInjClause None) false c } |
| 131 |
END |
| 132 |
|
| 133 |
TACTIC EXTEND dependent_rewrite |
| 134 |
| [ "dependent" "rewrite" orient(b) constr(c) ] -> { rewriteInConcl b c } |
| 135 |
| [ "dependent" "rewrite" orient(b) constr(c) "in" hyp(id) ] |
| 136 |
-> { rewriteInHyp b c id } |
| 137 |
END |
| 138 |
|
| 139 |
(**********************************************************************) |
| 140 |
(* Decompose *) |
| 141 |
|
| 142 |
TACTIC EXTEND decompose_sum |
| 143 |
| [ "decompose" "sum" constr(c) ] -> { Elim.h_decompose_or c } |
| 144 |
END |
| 145 |
|
| 146 |
TACTIC EXTEND decompose_record |
| 147 |
| [ "decompose" "record" constr(c) ] -> { Elim.h_decompose_and c } |
| 148 |
END |
| 149 |
|
| 150 |
(**********************************************************************) |
| 151 |
(* Contradiction *) |
| 152 |
|
| 153 |
{ |
| 154 |
|
| 155 |
open Contradiction |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
TACTIC EXTEND absurd |
| 160 |
| [ "absurd" constr(c) ] -> { absurd c } |
| 161 |
END |
| 162 |
|
| 163 |
TACTIC EXTEND contradiction |
| 164 |
| [ "contradiction" constr_with_bindings_opt(c) ] -> |
| 165 |
{ Internals.onSomeWithHoles contradiction c } |
| 166 |
END |
| 167 |
|
| 168 |
(**********************************************************************) |
| 169 |
(* AutoRewrite *) |
| 170 |
|
| 171 |
{ |
| 172 |
|
| 173 |
open Autorewrite |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
TACTIC EXTEND autorewrite |
| 178 |
| [ "autorewrite" "with" ne_preident_list(l) clause(cl) ] -> |
| 179 |
{ auto_multi_rewrite l ( cl) } |
| 180 |
| [ "autorewrite" "with" ne_preident_list(l) clause(cl) "using" tactic(t) ] -> |
| 181 |
{ |
| 182 |
auto_multi_rewrite_with (Tacinterp.tactic_of_value ist t) l cl |
| 183 |
} |
| 184 |
END |
| 185 |
|
| 186 |
TACTIC EXTEND autorewrite_star |
| 187 |
| [ "autorewrite" "*" "with" ne_preident_list(l) clause(cl) ] -> |
| 188 |
{ auto_multi_rewrite ~conds:AllMatches l cl } |
| 189 |
| [ "autorewrite" "*" "with" ne_preident_list(l) clause(cl) "using" tactic(t) ] -> |
| 190 |
{ auto_multi_rewrite_with ~conds:AllMatches (Tacinterp.tactic_of_value ist t) l cl } |
| 191 |
END |
| 192 |
|
| 193 |
(**********************************************************************) |
| 194 |
(* Rewrite star *) |
| 195 |
|
| 196 |
{ |
| 197 |
|
| 198 |
let rewrite_star ist clause orient occs c (tac : Geninterp.Val.t option) = |
| 199 |
let tac' = Option.map (fun t -> Tacinterp.tactic_of_value ist t, FirstSolved) tac in |
| 200 |
Internals.with_delayed_uconstr ist c |
| 201 |
(fun c -> general_rewrite ~where:clause ~l2r:orient occs ?tac:tac' ~freeze:true ~dep:true ~with_evars:true (c,NoBindings)) |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
TACTIC EXTEND rewrite_star |
| 206 |
| [ "rewrite" "*" orient(o) uconstr(c) "in" hyp(id) "at" occurrences(occ) by_arg_tac(tac) ] -> |
| 207 |
{ rewrite_star ist (Some id) o (occurrences_of occ) c tac } |
| 208 |
| [ "rewrite" "*" orient(o) uconstr(c) "at" occurrences(occ) "in" hyp(id) by_arg_tac(tac) ] -> |
| 209 |
{ rewrite_star ist (Some id) o (occurrences_of occ) c tac } |
| 210 |
| [ "rewrite" "*" orient(o) uconstr(c) "in" hyp(id) by_arg_tac(tac) ] -> |
| 211 |
{ rewrite_star ist (Some id) o Locus.AllOccurrences c tac } |
| 212 |
| [ "rewrite" "*" orient(o) uconstr(c) "at" occurrences(occ) by_arg_tac(tac) ] -> |
| 213 |
{ rewrite_star ist None o (occurrences_of occ) c tac } |
| 214 |
| [ "rewrite" "*" orient(o) uconstr(c) by_arg_tac(tac) ] -> |
| 215 |
{ rewrite_star ist None o Locus.AllOccurrences c tac } |
| 216 |
END |
| 217 |
|
| 218 |
(**********************************************************************) |
| 219 |
(* Hint Rewrite *) |
| 220 |
|
| 221 |
{ |
| 222 |
|
| 223 |
let classify_hint _ = VtSideff ([], VtLater) |
| 224 |
|
| 225 |
} |
| 226 |
|
| 227 |
(* XXX get this out of ltac plugin (need to bring orient with it) *) |
| 228 |
|
| 229 |
VERNAC COMMAND EXTEND HintRewrite CLASSIFIED BY { classify_hint } |
| 230 |
| #[ poly_def; locality = hint_locality; ] [ "Hint" "Rewrite" orient(o) ne_constr_list(l) ":" ne_preident_list(bl) ] -> |
| 231 |
{ add_rewrite_hint ~locality ~poly:poly_def bl o None l } |
| 232 |
| #[ poly_def; locality = hint_locality; ] [ "Hint" "Rewrite" orient(o) ne_constr_list(l) "using" generic_tactic(t) |
| 233 |
":" ne_preident_list(bl) ] -> |
| 234 |
{ add_rewrite_hint ~locality ~poly:poly_def bl o (Some t) l } |
| 235 |
| #[ poly_def; locality = hint_locality; ] [ "Hint" "Rewrite" orient(o) ne_constr_list(l) ] -> |
| 236 |
{ add_rewrite_hint ~locality ~poly:poly_def ["core"] o None l } |
| 237 |
| #[ poly_def; locality = hint_locality; ] [ "Hint" "Rewrite" orient(o) ne_constr_list(l) "using" generic_tactic(t) ] -> |
| 238 |
{ add_rewrite_hint ~locality ~poly:poly_def ["core"] o (Some t) l } |
| 239 |
END |
| 240 |
|
| 241 |
VERNAC COMMAND EXTEND HintCreateRewriteDb CLASSIFIED BY { classify_hint } |
| 242 |
| #[ locality = Synterp.module_locality ] [ "Create" "Rewrite" "HintDb" ident(id) ] -> |
| 243 |
{ create_rewrite_hint_db ~local:locality ~name:(Id.to_string id) } |
| 244 |
END |
| 245 |
|
| 246 |
(**********************************************************************) |
| 247 |
(* Refine *) |
| 248 |
|
| 249 |
TACTIC EXTEND refine |
| 250 |
| [ "refine" uconstr(c) ] -> |
| 251 |
{ Internals.refine_tac ist ~simple:false ~with_classes:true c } |
| 252 |
END |
| 253 |
|
| 254 |
TACTIC EXTEND simple_refine |
| 255 |
| [ "simple" "refine" uconstr(c) ] -> |
| 256 |
{ Internals.refine_tac ist ~simple:true ~with_classes:true c } |
| 257 |
END |
| 258 |
|
| 259 |
TACTIC EXTEND notcs_refine |
| 260 |
| [ "notypeclasses" "refine" uconstr(c) ] -> |
| 261 |
{ Internals.refine_tac ist ~simple:false ~with_classes:false c } |
| 262 |
END |
| 263 |
|
| 264 |
TACTIC EXTEND notcs_simple_refine |
| 265 |
| [ "simple" "notypeclasses" "refine" uconstr(c) ] -> |
| 266 |
{ Internals.refine_tac ist ~simple:true ~with_classes:false c } |
| 267 |
END |
| 268 |
|
| 269 |
(* Solve unification constraints using heuristics or fail if any remain *) |
| 270 |
TACTIC EXTEND solve_constraints |
| 271 |
| [ "solve_constraints" ] -> { Refine.solve_constraints } |
| 272 |
END |
| 273 |
|
| 274 |
(**********************************************************************) |
| 275 |
(* Inversion lemmas (Leminv) *) |
| 276 |
|
| 277 |
{ |
| 278 |
|
| 279 |
open Inv |
| 280 |
open Leminv |
| 281 |
|
| 282 |
let seff id = VtSideff ([id.CAst.v], VtLater) |
| 283 |
|
| 284 |
} |
| 285 |
|
| 286 |
VERNAC COMMAND EXTEND DeriveInversionClear |
| 287 |
| #[ polymorphic; ] [ "Derive" "Inversion_clear" identref(na) "with" constr(c) "Sort" sort_quality_or_set(s) ] |
| 288 |
=> { seff na } |
| 289 |
-> { let poly = PolyFlags.of_univ_poly polymorphic in |
| 290 |
add_inversion_lemma_exn ~poly na c s false inv_clear_tac } |
| 291 |
|
| 292 |
| #[ polymorphic; ] [ "Derive" "Inversion_clear" identref(na) "with" constr(c) ] => { seff na } |
| 293 |
-> { let poly = PolyFlags.of_univ_poly polymorphic in |
| 294 |
add_inversion_lemma_exn ~poly na c UnivGen.QualityOrSet.prop false inv_clear_tac } |
| 295 |
END |
| 296 |
|
| 297 |
VERNAC COMMAND EXTEND DeriveInversion |
| 298 |
| #[ polymorphic; ] [ "Derive" "Inversion" identref(na) "with" constr(c) "Sort" sort_quality_or_set(s) ] |
| 299 |
=> { seff na } |
| 300 |
-> { let poly = PolyFlags.of_univ_poly polymorphic in |
| 301 |
add_inversion_lemma_exn ~poly na c s false inv_tac } |
| 302 |
|
| 303 |
| #[ polymorphic; ] [ "Derive" "Inversion" identref(na) "with" constr(c) ] => { seff na } |
| 304 |
-> { let poly = PolyFlags.of_univ_poly polymorphic in |
| 305 |
add_inversion_lemma_exn ~poly na c UnivGen.QualityOrSet.prop false inv_tac } |
| 306 |
END |
| 307 |
|
| 308 |
VERNAC COMMAND EXTEND DeriveDependentInversion |
| 309 |
| #[ polymorphic; ] [ "Derive" "Dependent" "Inversion" identref(na) "with" constr(c) "Sort" sort_quality_or_set(s) ] |
| 310 |
=> { seff na } |
| 311 |
-> { let poly = PolyFlags.of_univ_poly polymorphic in |
| 312 |
add_inversion_lemma_exn ~poly na c s true dinv_tac } |
| 313 |
END |
| 314 |
|
| 315 |
VERNAC COMMAND EXTEND DeriveDependentInversionClear |
| 316 |
| #[ polymorphic; ] [ "Derive" "Dependent" "Inversion_clear" identref(na) "with" constr(c) "Sort" sort_quality_or_set(s) ] |
| 317 |
=> { seff na } |
| 318 |
-> { let poly = PolyFlags.of_univ_poly polymorphic in |
| 319 |
add_inversion_lemma_exn ~poly na c s true dinv_clear_tac } |
| 320 |
END |
| 321 |
|
| 322 |
(**********************************************************************) |
| 323 |
(* Subst *) |
| 324 |
|
| 325 |
TACTIC EXTEND subst |
| 326 |
| [ "subst" ne_hyp_list(l) ] -> { subst l } |
| 327 |
| [ "subst" ] -> { subst_all () } |
| 328 |
END |
| 329 |
|
| 330 |
{ |
| 331 |
|
| 332 |
let simple_subst_tactic_flags = |
| 333 |
{ only_leibniz = true; rewrite_dependent_proof = false } |
| 334 |
|
| 335 |
} |
| 336 |
|
| 337 |
TACTIC EXTEND simple_subst |
| 338 |
| [ "simple" "subst" ] -> { subst_all ~flags:simple_subst_tactic_flags () } |
| 339 |
END |
| 340 |
|
| 341 |
{ |
| 342 |
|
| 343 |
open Evar_tactics |
| 344 |
|
| 345 |
} |
| 346 |
|
| 347 |
(**********************************************************************) |
| 348 |
(* Evar creation *) |
| 349 |
|
| 350 |
(* TODO: add support for some test similar to g_constr.name_colon so that |
| 351 |
expressions like "evar (list A)" do not raise a syntax error *) |
| 352 |
TACTIC EXTEND evar |
| 353 |
| [ "evar" test_lpar_id_colon "(" ident(id) ":" lconstr(typ) ")" ] -> { let_evar (Name.Name id) typ } |
| 354 |
| [ "evar" constr(typ) ] -> { let_evar Name.Anonymous typ } |
| 355 |
END |
| 356 |
|
| 357 |
TACTIC EXTEND instantiate |
| 358 |
| [ "instantiate" "(" ident(id) ":=" lglob(c) ")" ] -> |
| 359 |
{ instantiate_tac_by_name id c } |
| 360 |
| [ "instantiate" "(" natural(i) ":=" lglob(c) ")" hloc(hl) ] -> |
| 361 |
{ instantiate_tac i c hl } |
| 362 |
END |
| 363 |
|
| 364 |
(**********************************************************************) |
| 365 |
(** Nijmegen "step" tactic for setoid rewriting *) |
| 366 |
|
| 367 |
{ |
| 368 |
|
| 369 |
open Tactics |
| 370 |
open Libobject |
| 371 |
|
| 372 |
(* Registered lemmas are expected to be of the form |
| 373 |
x R y -> y == z -> x R z (in the right table) |
| 374 |
x R y -> x == z -> z R y (in the left table) |
| 375 |
*) |
| 376 |
|
| 377 |
let transitivity_right_table = Summary.ref [] ~name:"transitivity-steps-r" |
| 378 |
let transitivity_left_table = Summary.ref [] ~name:"transitivity-steps-l" |
| 379 |
|
| 380 |
(* [step] tries to apply a rewriting lemma; then apply [tac] intended to |
| 381 |
complete to proof of the last hypothesis (assumed to state an equality) *) |
| 382 |
|
| 383 |
let step left x tac = |
| 384 |
let l = |
| 385 |
List.map (fun lem -> |
| 386 |
let lem = EConstr.of_constr lem in |
| 387 |
Tacticals.tclTHENLAST |
| 388 |
(apply_with_bindings (lem, ImplicitBindings [x])) |
| 389 |
tac) |
| 390 |
!(if left then transitivity_left_table else transitivity_right_table) |
| 391 |
in |
| 392 |
Tacticals.tclFIRST l |
| 393 |
|
| 394 |
(* Main function to push lemmas in persistent environment *) |
| 395 |
|
| 396 |
let cache_transitivity_lemma (left,lem) = |
| 397 |
if left then |
| 398 |
transitivity_left_table := lem :: !transitivity_left_table |
| 399 |
else |
| 400 |
transitivity_right_table := lem :: !transitivity_right_table |
| 401 |
|
| 402 |
let subst_transitivity_lemma (subst,(b,ref)) = (b,subst_mps subst ref) |
| 403 |
|
| 404 |
let inTransitivity : bool * Constr.t -> obj = |
| 405 |
declare_object @@ global_object_nodischarge "TRANSITIVITY-STEPS" |
| 406 |
~cache:cache_transitivity_lemma |
| 407 |
~subst:(Some subst_transitivity_lemma) |
| 408 |
|
| 409 |
(* Main entry points *) |
| 410 |
|
| 411 |
let add_transitivity_lemma left lem = |
| 412 |
let env = Global.env () in |
| 413 |
let sigma = Evd.from_env env in |
| 414 |
let lem',ctx (*FIXME*) = Constrintern.interp_constr env sigma lem in |
| 415 |
let lem' = EConstr.to_constr sigma lem' in |
| 416 |
Lib.add_leaf (inTransitivity (left,lem')) |
| 417 |
|
| 418 |
} |
| 419 |
|
| 420 |
(* Vernacular syntax *) |
| 421 |
|
| 422 |
TACTIC EXTEND stepl |
| 423 |
| ["stepl" constr(c) "by" tactic(tac) ] -> { step true c (Tacinterp.tactic_of_value ist tac) } |
| 424 |
| ["stepl" constr(c) ] -> { step true c (Proofview.tclUNIT ()) } |
| 425 |
END |
| 426 |
|
| 427 |
TACTIC EXTEND stepr |
| 428 |
| ["stepr" constr(c) "by" tactic(tac) ] -> { step false c (Tacinterp.tactic_of_value ist tac) } |
| 429 |
| ["stepr" constr(c) ] -> { step false c (Proofview.tclUNIT ()) } |
| 430 |
END |
| 431 |
|
| 432 |
VERNAC COMMAND EXTEND AddStepl CLASSIFIED AS SIDEFF |
| 433 |
| [ "Declare" "Left" "Step" constr(t) ] -> |
| 434 |
{ add_transitivity_lemma true t } |
| 435 |
END |
| 436 |
|
| 437 |
VERNAC COMMAND EXTEND AddStepr CLASSIFIED AS SIDEFF |
| 438 |
| [ "Declare" "Right" "Step" constr(t) ] -> |
| 439 |
{ add_transitivity_lemma false t } |
| 440 |
END |
| 441 |
|
| 442 |
(**********************************************************************) |
| 443 |
(* sozeau: abs/gen for induction on instantiated dependent inductives, using "Ford" induction as |
| 444 |
defined by Conor McBride *) |
| 445 |
TACTIC EXTEND generalize_eqs |
| 446 |
| ["generalize_eqs" hyp(id) ] -> { Generalize.abstract_generalize ~generalize_vars:false id } |
| 447 |
END |
| 448 |
TACTIC EXTEND dep_generalize_eqs |
| 449 |
| ["dependent" "generalize_eqs" hyp(id) ] -> { Generalize.abstract_generalize ~generalize_vars:false ~force_dep:true id } |
| 450 |
END |
| 451 |
TACTIC EXTEND generalize_eqs_vars |
| 452 |
| ["generalize_eqs_vars" hyp(id) ] -> { Generalize.abstract_generalize ~generalize_vars:true id } |
| 453 |
END |
| 454 |
TACTIC EXTEND dep_generalize_eqs_vars |
| 455 |
| ["dependent" "generalize_eqs_vars" hyp(id) ] -> { Generalize.abstract_generalize ~force_dep:true ~generalize_vars:true id } |
| 456 |
END |
| 457 |
|
| 458 |
(** Tactic to automatically simplify hypotheses of the form [Π Δ, x_i = t_i -> T] |
| 459 |
where [t_i] is closed w.r.t. Δ. Such hypotheses are automatically generated |
| 460 |
during dependent induction. For internal use. *) |
| 461 |
|
| 462 |
TACTIC EXTEND specialize_eqs |
| 463 |
| [ "specialize_eqs" hyp(id) ] -> { specialize_eqs id } |
| 464 |
END |
| 465 |
|
| 466 |
(**********************************************************************) |
| 467 |
|
| 468 |
(**********************************************************************) |
| 469 |
(* A version of abstract constructing transparent terms *) |
| 470 |
(* Introduced by Jason Gross and Benjamin Delaware in June 2016 *) |
| 471 |
(**********************************************************************) |
| 472 |
|
| 473 |
TACTIC EXTEND transparent_abstract |
| 474 |
| [ "transparent_abstract" tactic3(t) ] -> { Proofview.Goal.enter begin fun gl -> |
| 475 |
Abstract.tclABSTRACT ~opaque:false None (Tacinterp.tactic_of_value ist t) end; } |
| 476 |
| [ "transparent_abstract" tactic3(t) "using" ident(id) ] -> { Proofview.Goal.enter begin fun gl -> |
| 477 |
Abstract.tclABSTRACT ~opaque:false (Some id) (Tacinterp.tactic_of_value ist t) end; } |
| 478 |
END |
| 479 |
|
| 480 |
(* ********************************************************************* *) |
| 481 |
|
| 482 |
TACTIC EXTEND constr_eq |
| 483 |
| [ "constr_eq" constr(x) constr(y) ] -> { Tactics.constr_eq ~strict:false x y } |
| 484 |
END |
| 485 |
|
| 486 |
TACTIC EXTEND constr_eq_strict |
| 487 |
| [ "constr_eq_strict" constr(x) constr(y) ] -> { Tactics.constr_eq ~strict:true x y } |
| 488 |
END |
| 489 |
|
| 490 |
TACTIC EXTEND constr_eq_nounivs |
| 491 |
| [ "constr_eq_nounivs" constr(x) constr(y) ] -> { |
| 492 |
Proofview.tclEVARMAP >>= fun sigma -> |
| 493 |
if EConstr.eq_constr_nounivs sigma x y then Proofview.tclUNIT () else Tacticals.tclFAIL (str "Not equal") } |
| 494 |
END |
| 495 |
|
| 496 |
TACTIC EXTEND is_evar |
| 497 |
| [ "is_evar" constr(x) ] -> { Internals.is_evar x } |
| 498 |
END |
| 499 |
|
| 500 |
TACTIC EXTEND has_evar |
| 501 |
| [ "has_evar" constr(x) ] -> { Internals.has_evar x } |
| 502 |
END |
| 503 |
|
| 504 |
TACTIC EXTEND is_hyp |
| 505 |
| [ "is_var" constr(x) ] -> { Internals.is_var x } |
| 506 |
END |
| 507 |
|
| 508 |
TACTIC EXTEND is_fix |
| 509 |
| [ "is_fix" constr(x) ] -> { Internals.is_fix x } |
| 510 |
END |
| 511 |
|
| 512 |
TACTIC EXTEND is_cofix |
| 513 |
| [ "is_cofix" constr(x) ] -> { Internals.is_cofix x } |
| 514 |
END |
| 515 |
|
| 516 |
TACTIC EXTEND is_ind |
| 517 |
| [ "is_ind" constr(x) ] -> { Internals.is_ind x } |
| 518 |
END |
| 519 |
|
| 520 |
TACTIC EXTEND is_constructor |
| 521 |
| [ "is_constructor" constr(x) ] -> { Internals.is_constructor x } |
| 522 |
END |
| 523 |
|
| 524 |
TACTIC EXTEND is_proj |
| 525 |
| [ "is_proj" constr(x) ] -> { Internals.is_proj x } |
| 526 |
END |
| 527 |
|
| 528 |
TACTIC EXTEND is_const |
| 529 |
| [ "is_const" constr(x) ] -> { Internals.is_const x } |
| 530 |
END |
| 531 |
|
| 532 |
(* Shelves all the goals under focus. *) |
| 533 |
TACTIC EXTEND shelve |
| 534 |
| [ "shelve" ] -> { Proofview.shelve } |
| 535 |
END |
| 536 |
|
| 537 |
(* Shelves the unifiable goals under focus, i.e. the goals which |
| 538 |
appear in other goals under focus (the unfocused goals are not |
| 539 |
considered). *) |
| 540 |
TACTIC EXTEND shelve_unifiable |
| 541 |
| [ "shelve_unifiable" ] -> { Proofview.shelve_unifiable } |
| 542 |
END |
| 543 |
|
| 544 |
(* Unshelves the goal shelved by the tactic. *) |
| 545 |
TACTIC EXTEND unshelve |
| 546 |
| [ "unshelve" tactic1(t) ] -> { Internals.unshelve ist t } |
| 547 |
END |
| 548 |
|
| 549 |
(* Command to add every unshelved variables to the focus *) |
| 550 |
VERNAC COMMAND EXTEND Unshelve STATE proof |
| 551 |
| [ "Unshelve" ] |
| 552 |
=> { classify_as_proofstep } |
| 553 |
-> { fun ~pstate -> Declare.Proof.map ~f:(fun p -> Proof.unshelve p) pstate } |
| 554 |
END |
| 555 |
|
| 556 |
(* Gives up on the goals under focus: the goals are considered solved, |
| 557 |
but the proof cannot be closed until the user goes back and solve |
| 558 |
these goals. *) |
| 559 |
TACTIC EXTEND give_up |
| 560 |
| [ "give_up" ] -> |
| 561 |
{ Proofview.give_up } |
| 562 |
END |
| 563 |
|
| 564 |
(* cycles [n] goals *) |
| 565 |
TACTIC EXTEND cycle |
| 566 |
| [ "cycle" int_or_var(n) ] -> { Proofview.cycle n } |
| 567 |
END |
| 568 |
|
| 569 |
(* swaps goals number [i] and [j] *) |
| 570 |
TACTIC EXTEND swap |
| 571 |
| [ "swap" int_or_var(i) int_or_var(j) ] -> { Proofview.swap i j } |
| 572 |
END |
| 573 |
|
| 574 |
(* reverses the list of focused goals *) |
| 575 |
TACTIC EXTEND revgoals |
| 576 |
| [ "revgoals" ] -> { Proofview.revgoals } |
| 577 |
END |
| 578 |
|
| 579 |
{ |
| 580 |
|
| 581 |
type cmp = |
| 582 |
| Eq |
| 583 |
| Lt | Le |
| 584 |
| Gt | Ge |
| 585 |
|
| 586 |
type 'i test = |
| 587 |
| Test of cmp * 'i * 'i |
| 588 |
|
| 589 |
let pr_cmp = function |
| 590 |
| Eq -> Pp.str"=" |
| 591 |
| Lt -> Pp.str"<" |
| 592 |
| Le -> Pp.str"<=" |
| 593 |
| Gt -> Pp.str">" |
| 594 |
| Ge -> Pp.str">=" |
| 595 |
|
| 596 |
let pr_cmp' _prc _prlc _prt = pr_cmp |
| 597 |
|
| 598 |
let pr_test_gen f (Test(c,x,y)) = |
| 599 |
Pp.(f x ++ pr_cmp c ++ f y) |
| 600 |
|
| 601 |
let pr_test = pr_test_gen (Pputils.pr_or_var Pp.int) |
| 602 |
|
| 603 |
let pr_test' _prc _prlc _prt = pr_test |
| 604 |
|
| 605 |
let pr_itest = pr_test_gen Pp.int |
| 606 |
|
| 607 |
let pr_itest' _prc _prlc _prt = pr_itest |
| 608 |
|
| 609 |
} |
| 610 |
|
| 611 |
ARGUMENT EXTEND comparison PRINTED BY { pr_cmp' } |
| 612 |
| [ "=" ] -> { Eq } |
| 613 |
| [ "<" ] -> { Lt } |
| 614 |
| [ "<=" ] -> { Le } |
| 615 |
| [ ">" ] -> { Gt } |
| 616 |
| [ ">=" ] -> { Ge } |
| 617 |
END |
| 618 |
|
| 619 |
{ |
| 620 |
|
| 621 |
let interp_test ist env sigma = function |
| 622 |
| Test (c,x,y) -> |
| 623 |
Test(c,Tacinterp.interp_int_or_var ist x,Tacinterp.interp_int_or_var ist y) |
| 624 |
|
| 625 |
} |
| 626 |
|
| 627 |
ARGUMENT EXTEND test |
| 628 |
PRINTED BY { pr_itest' } |
| 629 |
INTERPRETED BY { interp_test } |
| 630 |
RAW_PRINTED BY { pr_test' } |
| 631 |
GLOB_PRINTED BY { pr_test' } |
| 632 |
| [ int_or_var(x) comparison(c) int_or_var(y) ] -> { Test(c,x,y) } |
| 633 |
END |
| 634 |
|
| 635 |
{ |
| 636 |
|
| 637 |
let interp_cmp = function |
| 638 |
| Eq -> Int.equal |
| 639 |
| Lt -> ((<):int->int->bool) |
| 640 |
| Le -> ((<=):int->int->bool) |
| 641 |
| Gt -> ((>):int->int->bool) |
| 642 |
| Ge -> ((>=):int->int->bool) |
| 643 |
|
| 644 |
let run_test = function |
| 645 |
| Test(c,x,y) -> interp_cmp c x y |
| 646 |
|
| 647 |
let guard tst = |
| 648 |
if run_test tst then |
| 649 |
Proofview.tclUNIT () |
| 650 |
else |
| 651 |
let msg = Pp.(str"Condition not satisfied:"++ws 1++(pr_itest tst)) in |
| 652 |
Tacticals.tclZEROMSG msg |
| 653 |
|
| 654 |
} |
| 655 |
|
| 656 |
TACTIC EXTEND guard |
| 657 |
| [ "guard" test(tst) ] -> { guard tst } |
| 658 |
END |
| 659 |
|
| 660 |
TACTIC EXTEND decompose |
| 661 |
| [ "decompose" "[" ne_constr_list(l) "]" constr(c) ] -> { Internals.decompose l c } |
| 662 |
END |
| 663 |
|
| 664 |
(** library/keys *) |
| 665 |
|
| 666 |
VERNAC COMMAND EXTEND Declare_keys CLASSIFIED AS SIDEFF |
| 667 |
| [ "Declare" "Equivalent" "Keys" constr(c) constr(c') ] -> { Internals.declare_equivalent_keys c c' } |
| 668 |
END |
| 669 |
|
| 670 |
VERNAC COMMAND EXTEND Print_keys CLASSIFIED AS QUERY |
| 671 |
| [ "Print" "Equivalent" "Keys" ] -> { Feedback.msg_notice (Keys.pr_keys Printer.pr_global) } |
| 672 |
END |
| 673 |
|
| 674 |
TACTIC EXTEND optimize_heap |
| 675 |
| [ "optimize_heap" ] -> { Internals.tclOPTIMIZE_HEAP } |
| 676 |
END |
| 677 |
|
| 678 |
VERNAC COMMAND EXTEND infoH CLASSIFIED AS QUERY |
| 679 |
| ![ proof_query ] [ "infoH" tactic(tac) ] -> { Internals.infoH tac } |
| 680 |
END |
| 681 |
|
| 682 |
(** Tactic analogous to [Strategy] vernacular *) |
| 683 |
|
| 684 |
TACTIC EXTEND with_strategy |
| 685 |
| [ "with_strategy" strategy_level_or_var(v) "[" ne_smart_global_list(q) "]" tactic3(tac) ] -> { |
| 686 |
with_set_strategy [(v, q)] (Tacinterp.tactic_of_value ist tac) |
| 687 |
} |
| 688 |
END |