feat(library/blast): add 'grind' and 'grind_simp' blast strategies
The use [intro] [intro!] [elim] [simp] lemmas. The [simp] lemmas are only used by grind_simp.
This commit is contained in:
parent
57c9ced111
commit
0963ce336f
4 changed files with 29 additions and 13 deletions
library/init
src/library/blast
|
@ -113,6 +113,8 @@ definition simp_topdown : tactic := #tactic with_options [blast.strategy "simp"
|
|||
definition inst_simp : tactic := #tactic with_options [blast.strategy "ematch_simp"] blast
|
||||
definition rec_simp : tactic := #tactic with_options [blast.strategy "rec_simp"] blast
|
||||
definition rec_inst_simp : tactic := #tactic with_options [blast.strategy "rec_ematch_simp"] blast
|
||||
definition grind : tactic := #tactic with_options [blast.strategy "grind"] blast
|
||||
definition grind_simp : tactic := #tactic with_options [blast.strategy "grind_simp"] blast
|
||||
|
||||
definition cases (h : expr) (ids : opt_identifier_list) : tactic := builtin
|
||||
|
||||
|
|
|
@ -67,9 +67,10 @@ static backward_branch_extension & get_extension() {
|
|||
|
||||
/** \brief Extensible backward chaining strategy */
|
||||
class backward_strategy_fn : public strategy_fn {
|
||||
char const * m_name;
|
||||
unsigned m_max_rounds;
|
||||
|
||||
virtual char const * get_name() const override { return "backward"; }
|
||||
virtual char const * get_name() const override { return m_name; }
|
||||
|
||||
/* action to be executed before hypothesis is activated */
|
||||
virtual action_result pre(hypothesis_idx) { return action_result::failed(); }
|
||||
|
@ -112,18 +113,17 @@ class backward_strategy_fn : public strategy_fn {
|
|||
return action_result::failed();
|
||||
}
|
||||
public:
|
||||
backward_strategy_fn(unsigned max_rounds):m_max_rounds(max_rounds) {}
|
||||
backward_strategy_fn(char const * n, unsigned max_rounds):
|
||||
m_name(n), m_max_rounds(max_rounds) {}
|
||||
};
|
||||
|
||||
/* Backward strategy that can be extended using closures. */
|
||||
class xbackward_strategy_fn : public backward_strategy_fn {
|
||||
char const * m_name;
|
||||
std::function<action_result(hypothesis_idx)> m_pre;
|
||||
std::function<action_result(hypothesis_idx)> m_post;
|
||||
std::function<action_result()> m_pre_next;
|
||||
std::function<action_result()> m_post_next;
|
||||
|
||||
virtual char const * get_name() const override { return m_name; }
|
||||
virtual action_result pre(hypothesis_idx hidx) { return m_pre(hidx); }
|
||||
virtual action_result post(hypothesis_idx hidx) { return m_post(hidx); }
|
||||
virtual action_result pre_next() { return m_pre_next(); }
|
||||
|
@ -136,19 +136,23 @@ public:
|
|||
std::function<action_result(hypothesis_idx)> const & post,
|
||||
std::function<action_result()> const & pre_next,
|
||||
std::function<action_result()> const & post_next):
|
||||
backward_strategy_fn(max_rounds),
|
||||
m_name(n), m_pre(pre), m_post(post), m_pre_next(pre_next), m_post_next(post_next) {}
|
||||
backward_strategy_fn(n, max_rounds),
|
||||
m_pre(pre), m_post(post), m_pre_next(pre_next), m_post_next(post_next) {}
|
||||
};
|
||||
|
||||
strategy mk_backward_strategy() {
|
||||
strategy mk_backward_strategy(char const * n) {
|
||||
if (!get_config().m_backward)
|
||||
return []() { return none_expr(); }; // NOLINT
|
||||
return []() { // NOLINT
|
||||
return [=]() { // NOLINT
|
||||
unsigned max_rounds = get_blast_backward_max_rounds(ios().get_options());
|
||||
return backward_strategy_fn(max_rounds)();
|
||||
return backward_strategy_fn(n, max_rounds)();
|
||||
};
|
||||
}
|
||||
|
||||
strategy mk_backward_strategy() {
|
||||
return mk_backward_strategy("backward");
|
||||
}
|
||||
|
||||
strategy mk_xbackward_strategy(char const * n,
|
||||
std::function<action_result(hypothesis_idx)> const & pre,
|
||||
std::function<action_result(hypothesis_idx)> const & post,
|
||||
|
|
|
@ -8,6 +8,7 @@ Author: Daniel Selsam
|
|||
namespace lean {
|
||||
namespace blast {
|
||||
strategy mk_backward_strategy();
|
||||
strategy mk_backward_strategy(char const * n);
|
||||
|
||||
/* Extensible backward chaining strategy
|
||||
- n : name of the new strategy
|
||||
|
|
|
@ -90,14 +90,21 @@ static optional<expr> apply_unit() {
|
|||
fail_action)();
|
||||
}
|
||||
|
||||
static optional<expr> apply_grind() {
|
||||
return preprocess_and_then(grind_and_then(fail_strategy()))();
|
||||
}
|
||||
|
||||
static optional<expr> apply_core_grind() {
|
||||
return grind_and_then(fail_strategy())();
|
||||
}
|
||||
|
||||
static optional<expr> apply_grind() {
|
||||
return preprocess_and_then(grind_and_then(mk_backward_strategy("grind_back")))();
|
||||
}
|
||||
|
||||
static optional<expr> apply_grind_simp() {
|
||||
strategy main = mk_xbackward_strategy("grind_simp",
|
||||
fail_action_h, fail_action_h, fail_action,
|
||||
[]() { TryStrategy(apply_simp); return action_result::failed(); });
|
||||
return preprocess_and_then(grind_and_then(main))();
|
||||
}
|
||||
|
||||
optional<expr> apply_strategy() {
|
||||
std::string s_name(get_config().m_strategy);
|
||||
if (s_name == "preprocess") {
|
||||
|
@ -115,6 +122,8 @@ optional<expr> apply_strategy() {
|
|||
return apply_cc();
|
||||
} else if (s_name == "grind") {
|
||||
return apply_grind();
|
||||
} else if (s_name == "grind_simp") {
|
||||
return apply_grind_simp();
|
||||
} else if (s_name == "core_grind") {
|
||||
return apply_core_grind();
|
||||
} else if (s_name == "ematch") {
|
||||
|
|
Loading…
Add table
Reference in a new issue