2015-11-10 19:44:18 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include "library/blast/blast.h"
|
|
|
|
#include "library/blast/options.h"
|
|
|
|
#include "library/blast/choice_point.h"
|
2015-11-11 08:02:47 +00:00
|
|
|
#include "library/blast/simple_actions.h"
|
2015-11-13 23:21:26 +00:00
|
|
|
#include "library/blast/proof_expr.h"
|
2015-11-14 21:21:47 +00:00
|
|
|
#include "library/blast/intros_action.h"
|
|
|
|
#include "library/blast/subst_action.h"
|
|
|
|
#include "library/blast/backward_action.h"
|
|
|
|
#include "library/blast/no_confusion_action.h"
|
2015-11-14 23:58:11 +00:00
|
|
|
#include "library/blast/simplify_actions.h"
|
2015-11-15 21:12:21 +00:00
|
|
|
#include "library/blast/recursor_action.h"
|
|
|
|
#include "library/blast/strategy.h"
|
2015-11-10 19:44:18 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
namespace blast {
|
|
|
|
/** \brief Implement a simple proof strategy for blast.
|
|
|
|
We use it mainly for testing new actions and the whole blast infra-structure. */
|
2015-11-15 21:12:21 +00:00
|
|
|
class simple_strategy : public strategy {
|
2015-11-11 08:02:47 +00:00
|
|
|
optional<hypothesis_idx> activate_hypothesis() {
|
2015-11-10 19:44:18 +00:00
|
|
|
return curr_state().activate_hypothesis();
|
|
|
|
}
|
|
|
|
|
2015-11-14 23:58:11 +00:00
|
|
|
/* \brief Preprocess state
|
|
|
|
It keeps applying intros, activating and finally simplify target.
|
|
|
|
Return an expression if the goal has been proved during preprocessing step. */
|
2015-11-15 21:12:21 +00:00
|
|
|
virtual optional<expr> preprocess() {
|
2015-11-14 23:58:11 +00:00
|
|
|
display_msg("* Preprocess");
|
|
|
|
while (true) {
|
|
|
|
if (intros_action())
|
|
|
|
continue;
|
|
|
|
if (auto hidx = activate_hypothesis()) {
|
|
|
|
if (auto pr = assumption_contradiction_actions(*hidx)) {
|
|
|
|
return pr;
|
|
|
|
}
|
|
|
|
if (subst_action(*hidx))
|
|
|
|
continue;
|
|
|
|
action_result r = no_confusion_action(*hidx);
|
|
|
|
if (solved(r))
|
|
|
|
return r.to_opt_expr();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (auto pr = assumption_action())
|
|
|
|
return pr;
|
|
|
|
return simplify_target_action().to_opt_expr();
|
|
|
|
}
|
|
|
|
|
2015-11-15 21:12:21 +00:00
|
|
|
virtual action_result next_action() {
|
2015-11-13 21:05:20 +00:00
|
|
|
if (intros_action()) {
|
|
|
|
display_action("intros");
|
2015-11-11 00:57:57 +00:00
|
|
|
return action_result::new_branch();
|
2015-11-13 21:05:20 +00:00
|
|
|
}
|
2015-11-11 00:57:57 +00:00
|
|
|
|
2015-11-11 08:02:47 +00:00
|
|
|
if (auto hidx = activate_hypothesis()) {
|
2015-11-13 21:05:20 +00:00
|
|
|
display_action("activate");
|
|
|
|
if (auto pr = assumption_contradiction_actions(*hidx)) {
|
|
|
|
display_action("assumption-contradiction");
|
2015-11-11 08:02:47 +00:00
|
|
|
return action_result::solved(*pr);
|
2015-11-13 21:05:20 +00:00
|
|
|
}
|
2015-11-13 23:21:26 +00:00
|
|
|
if (subst_action(*hidx)) {
|
|
|
|
display_action("subst");
|
2015-11-14 02:19:05 +00:00
|
|
|
return action_result::new_branch();
|
|
|
|
}
|
|
|
|
action_result r = no_confusion_action(*hidx);
|
|
|
|
if (!failed(r)) {
|
|
|
|
display_action("no_confusion");
|
|
|
|
return r;
|
2015-11-13 23:21:26 +00:00
|
|
|
}
|
2015-11-11 00:57:57 +00:00
|
|
|
return action_result::new_branch();
|
|
|
|
}
|
|
|
|
|
2015-11-14 23:02:14 +00:00
|
|
|
if (auto pr = trivial_action()) {
|
|
|
|
display_action("trivial");
|
|
|
|
return action_result::solved(*pr);
|
|
|
|
}
|
|
|
|
|
2015-11-11 00:57:57 +00:00
|
|
|
if (auto pr = assumption_action()) {
|
2015-11-11 08:02:47 +00:00
|
|
|
// Remark: this action is only relevant
|
|
|
|
// when the target has been modified.
|
2015-11-13 21:05:20 +00:00
|
|
|
display_action("assumption");
|
2015-11-11 00:57:57 +00:00
|
|
|
return action_result::solved(*pr);
|
2015-11-10 19:44:18 +00:00
|
|
|
}
|
2015-11-11 00:57:57 +00:00
|
|
|
|
|
|
|
action_result r = constructor_action();
|
2015-11-13 21:05:20 +00:00
|
|
|
if (!failed(r)) {
|
|
|
|
display_action("constructor");
|
|
|
|
return r;
|
|
|
|
}
|
2015-11-11 00:57:57 +00:00
|
|
|
|
|
|
|
// TODO(Leo): add more actions...
|
2015-11-13 21:05:20 +00:00
|
|
|
|
|
|
|
display_msg(">>> FAILED <<<");
|
2015-11-11 00:57:57 +00:00
|
|
|
return action_result::failed();
|
2015-11-10 19:44:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
optional<expr> apply_simple_strategy() {
|
|
|
|
return simple_strategy()();
|
|
|
|
}
|
|
|
|
}}
|