2013-11-21 01:02:41 +00:00
|
|
|
/*
|
2014-06-27 13:59:17 +00:00
|
|
|
Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved.
|
2013-11-21 01:02:41 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <utility>
|
2013-11-27 03:15:49 +00:00
|
|
|
#include "util/lua.h"
|
2013-11-21 01:02:41 +00:00
|
|
|
#include "util/list.h"
|
|
|
|
#include "util/name.h"
|
2013-11-22 00:44:31 +00:00
|
|
|
#include "kernel/formatter.h"
|
2013-11-21 01:02:41 +00:00
|
|
|
#include "kernel/environment.h"
|
2014-06-27 13:59:17 +00:00
|
|
|
#include "library/io_state_stream.h"
|
2013-11-21 01:02:41 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-06-27 18:11:12 +00:00
|
|
|
/**
|
|
|
|
\brief A hypothesis is a local variable + a flag indicating whether it is "contextual" or not.
|
|
|
|
Only contextual ones are used to build the context of new metavariables.
|
|
|
|
*/
|
|
|
|
typedef std::pair<expr, bool> hypothesis;
|
2013-11-25 09:06:11 +00:00
|
|
|
typedef list<hypothesis> hypotheses;
|
2013-11-21 01:02:41 +00:00
|
|
|
class goal {
|
2013-11-25 09:06:11 +00:00
|
|
|
hypotheses m_hypotheses;
|
|
|
|
expr m_conclusion;
|
2013-11-21 01:02:41 +00:00
|
|
|
public:
|
2013-11-21 23:31:55 +00:00
|
|
|
goal() {}
|
2013-11-25 09:06:11 +00:00
|
|
|
goal(hypotheses const & hs, expr const & c);
|
|
|
|
hypotheses const & get_hypotheses() const { return m_hypotheses; }
|
2013-11-21 01:02:41 +00:00
|
|
|
expr const & get_conclusion() const { return m_conclusion; }
|
2014-06-27 18:11:12 +00:00
|
|
|
/**
|
|
|
|
\brief Create a metavarible application <tt>(m l_1 ... l_n)</tt> with type \c type,
|
|
|
|
where \c l_1 ... \c l_n are the contextual hypotheses of this goal, and
|
|
|
|
\c m is a metavariable with name \c n.
|
|
|
|
*/
|
|
|
|
expr mk_meta(name const & n, expr const & type) const;
|
|
|
|
/**
|
|
|
|
brief Return true iff this is a valid goal.
|
|
|
|
We say a goal is valid when the conclusion only contains local constants that are in hypotheses,
|
|
|
|
and each hypothesis only contains local constants that occur in the previous hypotheses.
|
|
|
|
*/
|
|
|
|
bool validate() const;
|
2014-06-27 13:59:17 +00:00
|
|
|
format pp(environment const & env, formatter const & fmt, options const & opts) const;
|
2013-11-21 01:02:41 +00:00
|
|
|
};
|
|
|
|
|
2013-11-25 09:06:11 +00:00
|
|
|
inline goal update(goal const & g, expr const & c) { return goal(g.get_hypotheses(), c); }
|
|
|
|
inline goal update(goal const & g, hypotheses const & hs) { return goal(hs, g.get_conclusion()); }
|
|
|
|
inline goal update(goal const & g, buffer<hypothesis> const & hs) { return goal(to_list(hs.begin(), hs.end()), g.get_conclusion()); }
|
2014-06-27 18:11:12 +00:00
|
|
|
inline hypotheses add_hypothesis(expr const & l, hypotheses const & hs) {
|
|
|
|
lean_assert(is_local(l));
|
|
|
|
return cons(hypothesis(l, true), hs);
|
2013-11-25 09:06:11 +00:00
|
|
|
}
|
|
|
|
inline hypotheses add_hypothesis(hypothesis const & h, hypotheses const & hs) {
|
|
|
|
return cons(h, hs);
|
|
|
|
}
|
|
|
|
|
2014-06-27 13:59:17 +00:00
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, goal const & g);
|
2013-11-27 03:15:49 +00:00
|
|
|
|
|
|
|
UDATA_DEFS_CORE(hypotheses)
|
|
|
|
UDATA_DEFS(goal)
|
|
|
|
void open_goal(lua_State * L);
|
2013-11-21 01:02:41 +00:00
|
|
|
}
|