lean2/src/library/blast/revert.cpp
Leonardo de Moura 453e90261b refactor(library/blast): make sure all actions return action_result, add macros for simplifying strategy definition
revert is not an action, but a procedure for helping us to build actions.
2015-11-18 12:29:43 -08:00

47 lines
1.4 KiB
C++

/*
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/revert.h"
#include "library/blast/blast.h"
namespace lean {
namespace blast {
struct revert_proof_step_cell : public proof_step_cell {
list<expr> m_hs;
revert_proof_step_cell(list<expr> const & hs):m_hs(hs) {}
virtual ~revert_proof_step_cell() {}
virtual action_result resolve(expr const & pr) const override {
expr new_pr = mk_app(pr, m_hs);
return action_result::solved(new_pr);
}
virtual bool is_silent() const override { return true; }
};
unsigned revert(hypothesis_idx_buffer_set & hidxs) {
state & s = curr_state();
unsigned hidxs_size = hidxs.as_buffer().size();
for (unsigned i = 0; i < hidxs_size; i++) {
s.collect_forward_deps(hidxs.as_buffer()[i], hidxs);
}
s.sort_hypotheses(hidxs);
buffer<expr> hs;
s.to_hrefs(hidxs.as_buffer(), hs);
expr target = s.get_target();
expr new_target = s.mk_pi(hs, target);
s.set_target(new_target);
s.push_proof_step(new revert_proof_step_cell(to_list(hs)));
lean_verify(s.del_hypotheses(hidxs.as_buffer()));
return hidxs.as_buffer().size();
}
unsigned revert(buffer<hypothesis_idx> & hidxs) {
hypothesis_idx_buffer_set _hidxs(hidxs);
return revert(_hidxs);
}
}}