feat(library/tactic/tactic): apply substitution in 'then' combinator

closes #778
This commit is contained in:
Leonardo de Moura 2015-08-08 03:42:21 -07:00
parent 7df59d8b12
commit d46dbce86e
3 changed files with 48 additions and 1 deletions

View file

@ -17,6 +17,7 @@ Author: Leonardo de Moura
#include "kernel/for_each_fn.h" #include "kernel/for_each_fn.h"
#include "kernel/replace_fn.h" #include "kernel/replace_fn.h"
#include "library/normalize.h" #include "library/normalize.h"
#include "library/util.h"
#include "library/kernel_bindings.h" #include "library/kernel_bindings.h"
#include "library/tactic/tactic.h" #include "library/tactic/tactic.h"
#include "library/io_state_stream.h" #include "library/io_state_stream.h"
@ -108,7 +109,26 @@ tactic then(tactic const & t1, tactic const & t2) {
return tactic([=](environment const & env, io_state const & ios, proof_state const & s1) -> proof_state_seq { return tactic([=](environment const & env, io_state const & ios, proof_state const & s1) -> proof_state_seq {
return map_append(t1(env, ios, s1), [=](proof_state const & s2) { return map_append(t1(env, ios, s1), [=](proof_state const & s2) {
check_interrupted(); check_interrupted();
return t2(env, ios, s2); bool has_meta = false;
goals const & gs = s2.get_goals();
for (goal const & g : gs) {
if (has_expr_metavar_relaxed(g.get_type())) {
has_meta = true;
break;
}
}
if (has_meta) {
buffer<goal> gs;
substitution subst = s2.get_subst();
to_buffer(s2.get_goals(), gs);
for (unsigned i = 0; i < gs.size(); i++) {
gs[i] = gs[i].instantiate(subst);
}
proof_state new_s2(s2, to_list(gs));
return t2(env, ios, new_s2);
} else {
return t2(env, ios, s2);
}
}, "THEN tactical"); }, "THEN tactical");
}); });
} }

9
tests/lean/778.hlean Normal file
View file

@ -0,0 +1,9 @@
open bool
definition is_equiv_bnot : is_equiv bnot :=
begin
fapply is_equiv.mk,
exact bnot,
all_goals (intro b;cases b),
state,
repeat reflexivity
end

View file

@ -0,0 +1,18 @@
778.hlean:7:4: proof state
⊢ bnot (bnot ff) = ff
⊢ bnot (bnot tt) = tt
⊢ bnot (bnot ff) = ff
⊢ bnot (bnot tt) = tt
⊢ bool.cases_on (bnot ff) ?M_1 ?M_2 = eq.ap bnot (bool.cases_on ff ?M_3 ?M_4)
⊢ bool.cases_on (bnot tt) ?M_1 ?M_2 = eq.ap bnot (bool.cases_on tt ?M_3 ?M_4)