feat(library/tactic): add apply tactic

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-03 09:20:01 -07:00
parent c1538bfc40
commit 0ff145e59b
5 changed files with 33 additions and 1 deletions

View file

@ -24,6 +24,7 @@ definition interleave (t1 t2 : tactic) : tactic := builtin_tactic
definition par (t1 t2 : tactic) : tactic := builtin_tactic
definition repeat (t : tactic) : tactic := builtin_tactic
definition at_most (t : tactic) (k : num) : tactic := builtin_tactic
definition discard (t : tactic) (k : num) : tactic := builtin_tactic
definition focus_at (t : tactic) (i : num) : tactic := builtin_tactic
definition try_for (t : tactic) (ms : num) : tactic := builtin_tactic
definition now : tactic := builtin_tactic

View file

@ -185,6 +185,7 @@ static register_tac reg_unfold(name(g_tac, "unfold"), [](type_checker &, expr co
return unfold_tactic(const_name(id));
});
static register_unary_num_tac reg_at_most(name(g_tac, "at_most"), [](tactic const & t, unsigned k) { return take(t, k); });
static register_unary_num_tac reg_discard(name(g_tac, "discard"), [](tactic const & t, unsigned k) { return discard(t, k); });
static register_unary_num_tac reg_focus_at(name(g_tac, "focus_at"), [](tactic const & t, unsigned k) { return focus(t, k); });
static register_unary_num_tac reg_try_for(name(g_tac, "try_for"), [](tactic const & t, unsigned k) { return try_for(t, k); });

View file

@ -190,6 +190,19 @@ tactic take(tactic const & t, unsigned k) {
});
}
tactic discard(tactic const & t, unsigned k) {
return tactic([=](environment const & env, io_state const & ios, proof_state const & s) -> proof_state_seq {
auto r = t(env, ios, s);
for (unsigned i = 0; i < k; i++) {
auto m = r.pull();
if (!m)
return proof_state_seq();
r = m->second;
}
return r;
});
}
tactic assumption_tactic() {
return tactic01([](environment const &, io_state const &, proof_state const & s) -> optional<proof_state> {
substitution subst = s.get_subst();

View file

@ -112,9 +112,15 @@ tactic repeat(tactic const & t);
tactic repeat_at_most(tactic const & t, unsigned k);
/**
\brief Return a tactic that applies \c t, but takes at most \c
k elements from the sequence produced by \c t.
\c k elements from the sequence produced by \c t.
*/
tactic take(tactic const & t, unsigned k);
/**
\brief Return a tactic that applies \c t, but discards the first
\c k elements from the sequence produced by \c t.
*/
tactic discard(tactic const & t, unsigned k);
typedef std::function<bool(environment const & env, io_state const & ios, proof_state const & s)> proof_state_pred; // NOLINT
/**
\brief Return a tactic that applies the predicate \c p to the input state.

View file

@ -0,0 +1,11 @@
import standard
using tactic
variable A : Type.{1}
variable f : A → A → A
theorem tst {a b c : A} (H1 : a = b) (H2 : b = c) : f a (f b b) = f b (f c c)
:= by discard (apply (subst H1)) 3; -- discard the first 3 solutions produced by apply
trace "after subst H1";
apply (subst H2);
apply refl