2015-09-16 14:49:39 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
2015-09-24 01:13:18 +00:00
|
|
|
#include "util/rb_map.h"
|
2015-09-16 14:49:39 +00:00
|
|
|
#include "kernel/expr.h"
|
2015-09-29 01:28:11 +00:00
|
|
|
#include "library/tactic/goal.h"
|
2015-09-24 01:13:18 +00:00
|
|
|
#include "library/blast/hypothesis.h"
|
2015-09-25 21:43:42 +00:00
|
|
|
#include "library/blast/branch.h"
|
2015-09-24 01:13:18 +00:00
|
|
|
|
2015-09-16 14:49:39 +00:00
|
|
|
namespace lean {
|
|
|
|
namespace blast {
|
2015-09-24 01:13:18 +00:00
|
|
|
class metavar_decl {
|
2015-09-28 23:40:19 +00:00
|
|
|
hypothesis_idx_list m_context;
|
|
|
|
hypothesis_idx_set m_context_as_set;
|
|
|
|
expr m_type;
|
2015-09-25 21:43:42 +00:00
|
|
|
public:
|
|
|
|
metavar_decl() {}
|
2015-09-28 23:40:19 +00:00
|
|
|
metavar_decl(hypothesis_idx_list const & c, hypothesis_idx_set const & s, expr const & t):
|
|
|
|
m_context(c), m_context_as_set(s), m_type(t) {}
|
2015-09-29 01:28:11 +00:00
|
|
|
hypothesis_idx_list get_context() const { return m_context; }
|
|
|
|
expr const & get_type() const { return m_type; }
|
2015-09-24 01:13:18 +00:00
|
|
|
};
|
|
|
|
|
2015-09-16 14:49:39 +00:00
|
|
|
class state {
|
2015-09-25 21:43:42 +00:00
|
|
|
friend class context;
|
2015-09-29 01:28:11 +00:00
|
|
|
typedef metavar_idx_map<metavar_decl> metavar_decls;
|
|
|
|
typedef metavar_idx_map<expr> assignment;
|
|
|
|
unsigned m_next_mref_index;
|
2015-09-24 01:13:18 +00:00
|
|
|
metavar_decls m_metavar_decls;
|
2015-09-25 19:45:16 +00:00
|
|
|
assignment m_assignment;
|
2015-09-28 23:40:19 +00:00
|
|
|
branch m_main;
|
|
|
|
|
|
|
|
unsigned add_metavar_decl(metavar_decl const & decl);
|
2015-09-29 01:28:11 +00:00
|
|
|
goal to_goal(branch const &) const;
|
2015-09-28 23:40:19 +00:00
|
|
|
|
2015-09-29 01:55:24 +00:00
|
|
|
#ifdef LEAN_DEBUG
|
2015-09-29 19:42:20 +00:00
|
|
|
bool check_hypothesis(expr const & e, branch const & b, unsigned hidx, hypothesis const & h) const;
|
|
|
|
bool check_hypothesis(branch const & b, unsigned hidx, hypothesis const & h) const;
|
|
|
|
bool check_target(branch const & b) const;
|
2015-09-29 01:55:24 +00:00
|
|
|
bool check_invariant(branch const &) const;
|
|
|
|
#endif
|
2015-09-25 21:43:42 +00:00
|
|
|
public:
|
|
|
|
state();
|
2015-09-28 23:40:19 +00:00
|
|
|
/** \brief Create a new metavariable using the given type and context.
|
|
|
|
\pre ctx must be a subset of the hypotheses in the main branch. */
|
|
|
|
expr mk_metavar(hypothesis_idx_buffer const & ctx, expr const & type);
|
|
|
|
/** \brief Create a new metavariable using the given type.
|
|
|
|
The context of this metavariable will be all hypotheses occurring in the main branch. */
|
|
|
|
expr mk_metavar(expr const & type);
|
|
|
|
|
2015-09-29 00:39:30 +00:00
|
|
|
/** \brief Add a new hypothesis to the main branch */
|
|
|
|
expr add_hypothesis(name const & n, expr const & type, optional<expr> const & value, optional<expr> const & jst) {
|
|
|
|
return m_main.add_hypothesis(n, type, value, jst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Add a new hypothesis to the main branch */
|
|
|
|
expr add_hypothesis(expr const & type, optional<expr> const & value, optional<expr> const & jst) {
|
|
|
|
return m_main.add_hypothesis(type, value, jst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Set target (aka conclusion, aka type of the goal, aka type of the term that must be synthesize in this branch)
|
|
|
|
of the main branch */
|
|
|
|
void set_target(expr const & type) {
|
|
|
|
return m_main.set_target(type);
|
|
|
|
}
|
|
|
|
|
2015-09-25 21:43:42 +00:00
|
|
|
metavar_decl const * get_metavar_decl(unsigned idx) const { return m_metavar_decls.find(idx); }
|
|
|
|
metavar_decl const * get_metavar_decl(expr const & e) const { return get_metavar_decl(mref_index(e)); }
|
2015-09-29 01:28:11 +00:00
|
|
|
|
|
|
|
/** \brief Convert main branch to a goal.
|
|
|
|
This is mainly used for pretty printing. However, in the future, we may use this capability
|
|
|
|
to invoke the tactic framework from the blast tactic. */
|
|
|
|
goal to_goal() const;
|
2015-09-29 01:55:24 +00:00
|
|
|
|
2015-09-29 17:04:11 +00:00
|
|
|
void display(environment const & env, io_state const & ios) const;
|
|
|
|
|
2015-09-29 01:55:24 +00:00
|
|
|
#ifdef LEAN_DEBUG
|
|
|
|
bool check_invariant() const;
|
|
|
|
#endif
|
2015-09-16 14:49:39 +00:00
|
|
|
};
|
|
|
|
}}
|