2013-11-21 20:34:37 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include "util/sstream.h"
|
2013-11-25 21:04:09 +00:00
|
|
|
#include "kernel/builtin.h"
|
2013-11-21 20:34:37 +00:00
|
|
|
#include "library/tactic/proof_state.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2013-11-25 19:43:16 +00:00
|
|
|
precision mk_union(precision p1, precision p2) {
|
|
|
|
if (p1 == p2) return p1;
|
|
|
|
else if (p1 == precision::Precise) return p2;
|
|
|
|
else if (p2 == precision::Precise) return p1;
|
|
|
|
else return precision::UnderOver;
|
|
|
|
}
|
|
|
|
|
2013-11-25 21:04:09 +00:00
|
|
|
bool trust_proof(precision p) {
|
2013-11-25 19:43:16 +00:00
|
|
|
return p == precision::Precise || p == precision::Over;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool trust_cex(precision p) {
|
|
|
|
return p == precision::Precise || p == precision::Under;
|
|
|
|
}
|
|
|
|
|
2013-11-22 00:44:31 +00:00
|
|
|
format proof_state::pp(formatter const & fmt, options const & opts) const {
|
|
|
|
format r;
|
|
|
|
bool first = true;
|
2013-11-25 18:39:40 +00:00
|
|
|
for (auto const & p : get_goals()) {
|
2013-11-22 00:44:31 +00:00
|
|
|
if (first)
|
|
|
|
first = false;
|
|
|
|
else
|
|
|
|
r += line();
|
2013-11-25 04:22:47 +00:00
|
|
|
r += p.second.pp(fmt, opts);
|
2013-11-22 00:44:31 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-11-25 21:04:09 +00:00
|
|
|
bool proof_state::is_proof_final_state() const {
|
|
|
|
return empty(get_goals()) && trust_proof(get_precision());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool proof_state::is_cex_final_state() const {
|
|
|
|
if (length(get_goals()) == 1 && trust_cex(get_precision())) {
|
|
|
|
goal const & g = head(get_goals()).second;
|
|
|
|
return is_false(g.get_conclusion()) && empty(g.get_hypotheses());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 20:34:37 +00:00
|
|
|
static name g_main("main");
|
|
|
|
|
|
|
|
proof_state to_proof_state(environment const & env, context const & ctx, expr const & t) {
|
2013-11-25 18:50:33 +00:00
|
|
|
auto gfn = to_goal(env, ctx, t);
|
|
|
|
goal g = gfn.first;
|
|
|
|
goal_proof_fn fn = gfn.second;
|
|
|
|
proof_builder pr_builder = mk_proof_builder(
|
|
|
|
[=](proof_map const & m, assignment const &) -> expr {
|
2013-11-25 19:43:16 +00:00
|
|
|
return fn(find(m, g_main));
|
|
|
|
});
|
|
|
|
cex_builder cex_builder = mk_cex_builder(
|
|
|
|
[](name const & n, optional<counterexample> const & cex, assignment const &) -> counterexample {
|
|
|
|
if (n != g_main || !cex)
|
|
|
|
throw exception(sstream() << "failed to build counterexample for '" << g_main << "' goal");
|
|
|
|
return *cex;
|
2013-11-21 23:31:55 +00:00
|
|
|
});
|
2013-11-25 19:43:16 +00:00
|
|
|
return proof_state(goals(mk_pair(g_main, g)), metavar_env(), pr_builder, cex_builder);
|
2013-11-21 20:34:37 +00:00
|
|
|
}
|
|
|
|
}
|