2014-12-05 23:47:04 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
2015-02-21 00:30:32 +00:00
|
|
|
Module: init.tactic
|
2014-12-05 23:47:04 +00:00
|
|
|
Author: Leonardo de Moura
|
|
|
|
|
|
|
|
This is just a trick to embed the 'tactic language' as a Lean
|
|
|
|
expression. We should view 'tactic' as automation that when execute
|
|
|
|
produces a term. tactic.builtin is just a "dummy" for creating the
|
|
|
|
definitions that are actually implemented in C++
|
|
|
|
-/
|
|
|
|
prelude
|
2015-03-03 21:37:38 +00:00
|
|
|
import init.datatypes init.reserved_notation init.num
|
2014-12-05 23:47:04 +00:00
|
|
|
|
|
|
|
inductive tactic :
|
|
|
|
Type := builtin : tactic
|
|
|
|
|
|
|
|
namespace tactic
|
|
|
|
-- Remark the following names are not arbitrary, the tactic module
|
|
|
|
-- uses them when converting Lean expressions into actual tactic objects.
|
|
|
|
-- The bultin 'by' construct triggers the process of converting a
|
|
|
|
-- a term of type 'tactic' into a tactic that sythesizes a term
|
|
|
|
opaque definition and_then (t1 t2 : tactic) : tactic := builtin
|
|
|
|
opaque definition or_else (t1 t2 : tactic) : tactic := builtin
|
|
|
|
opaque definition append (t1 t2 : tactic) : tactic := builtin
|
|
|
|
opaque definition interleave (t1 t2 : tactic) : tactic := builtin
|
|
|
|
opaque definition par (t1 t2 : tactic) : tactic := builtin
|
|
|
|
opaque definition fixpoint (f : tactic → tactic) : tactic := builtin
|
|
|
|
opaque definition repeat (t : tactic) : tactic := builtin
|
|
|
|
opaque definition at_most (t : tactic) (k : num) : tactic := builtin
|
|
|
|
opaque definition discard (t : tactic) (k : num) : tactic := builtin
|
|
|
|
opaque definition focus_at (t : tactic) (i : num) : tactic := builtin
|
|
|
|
opaque definition try_for (t : tactic) (ms : num) : tactic := builtin
|
2015-03-26 00:42:34 +00:00
|
|
|
opaque definition all_goals (t : tactic) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
opaque definition now : tactic := builtin
|
|
|
|
opaque definition assumption : tactic := builtin
|
|
|
|
opaque definition eassumption : tactic := builtin
|
|
|
|
opaque definition state : tactic := builtin
|
|
|
|
opaque definition fail : tactic := builtin
|
|
|
|
opaque definition id : tactic := builtin
|
|
|
|
opaque definition beta : tactic := builtin
|
|
|
|
opaque definition info : tactic := builtin
|
|
|
|
opaque definition whnf : tactic := builtin
|
|
|
|
opaque definition rotate_left (k : num) := builtin
|
|
|
|
opaque definition rotate_right (k : num) := builtin
|
|
|
|
definition rotate (k : num) := rotate_left k
|
|
|
|
|
|
|
|
-- This is just a trick to embed expressions into tactics.
|
|
|
|
-- The nested expressions are "raw". They tactic should
|
|
|
|
-- elaborate them when it is executed.
|
|
|
|
inductive expr : Type :=
|
|
|
|
builtin : expr
|
|
|
|
|
|
|
|
inductive expr_list : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| nil : expr_list
|
|
|
|
| cons : expr → expr_list → expr_list
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-03-06 02:07:06 +00:00
|
|
|
-- auxiliary type used to mark optional list of arguments
|
|
|
|
definition opt_expr_list := expr_list
|
|
|
|
|
2015-04-22 23:03:22 +00:00
|
|
|
-- auxiliary types used to mark that the expression (list) is an identifier (list)
|
|
|
|
definition identifier := expr
|
|
|
|
definition identifier_list := expr_list
|
|
|
|
definition opt_identifier_list := expr_list
|
|
|
|
|
|
|
|
opaque definition apply (e : expr) : tactic := builtin
|
|
|
|
opaque definition fapply (e : expr) : tactic := builtin
|
|
|
|
opaque definition rename (a b : identifier) : tactic := builtin
|
|
|
|
opaque definition intro (e : identifier) : tactic := builtin
|
|
|
|
opaque definition generalize (e : expr) : tactic := builtin
|
|
|
|
opaque definition clear (e : identifier) : tactic := builtin
|
|
|
|
opaque definition revert (e : identifier) : tactic := builtin
|
|
|
|
opaque definition refine (e : expr) : tactic := builtin
|
|
|
|
opaque definition exact (e : expr) : tactic := builtin
|
|
|
|
-- Relaxed version of exact that does not enforce goal type
|
|
|
|
opaque definition rexact (e : expr) : tactic := builtin
|
|
|
|
opaque definition check_expr (e : expr) : tactic := builtin
|
|
|
|
opaque definition trace (s : string) : tactic := builtin
|
|
|
|
|
2015-02-03 03:20:24 +00:00
|
|
|
-- rewrite_tac is just a marker for the builtin 'rewrite' notation
|
|
|
|
-- used to create instances of this tactic.
|
2015-04-22 23:03:22 +00:00
|
|
|
opaque definition rewrite_tac (e : expr_list) : tactic := builtin
|
2015-02-03 03:20:24 +00:00
|
|
|
|
2015-04-22 23:03:22 +00:00
|
|
|
opaque definition cases (id : identifier) (ids : opt_identifier_list) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-04-22 23:03:22 +00:00
|
|
|
opaque definition intros (ids : opt_identifier_list) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-03-06 02:07:06 +00:00
|
|
|
opaque definition generalizes (es : expr_list) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-04-22 23:03:22 +00:00
|
|
|
opaque definition clears (ids : identifier_list) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-04-22 23:03:22 +00:00
|
|
|
opaque definition reverts (ids : identifier_list) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-03-06 02:07:06 +00:00
|
|
|
opaque definition change (e : expr) : tactic := builtin
|
2015-03-01 22:15:23 +00:00
|
|
|
|
2015-04-22 23:03:22 +00:00
|
|
|
opaque definition assert_hypothesis (id : identifier) (e : expr) : tactic := builtin
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-04-29 00:20:39 +00:00
|
|
|
opaque definition lettac (id : identifier) (e : expr) : tactic := builtin
|
|
|
|
|
2015-04-28 00:46:13 +00:00
|
|
|
definition try (t : tactic) : tactic := or_else t id
|
|
|
|
definition repeat1 (t : tactic) : tactic := and_then t (repeat t)
|
2014-12-05 23:47:04 +00:00
|
|
|
definition focus (t : tactic) : tactic := focus_at t 0
|
|
|
|
definition determ (t : tactic) : tactic := at_most t 1
|
2015-04-28 00:46:13 +00:00
|
|
|
definition trivial : tactic := or_else (apply eq.refl) assumption
|
2015-03-03 21:37:38 +00:00
|
|
|
definition do (n : num) (t : tactic) : tactic :=
|
2015-04-28 00:46:13 +00:00
|
|
|
nat.rec id (λn t', and_then t t') (nat.of_num n)
|
2015-03-03 21:37:38 +00:00
|
|
|
|
2014-12-05 23:47:04 +00:00
|
|
|
end tactic
|
2015-04-28 00:46:13 +00:00
|
|
|
tactic_infixl `;`:15 := tactic.and_then
|
|
|
|
tactic_notation `(` h `|` r:(foldl `|` (e r, tactic.or_else r e) h) `)` := r
|