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
|
|
|
/**
|
2014-07-01 23:11:19 +00:00
|
|
|
\brief A goal is just encoding the synthesis problem <tt>(?m l_1 .... l_n) : t</tt>
|
|
|
|
That is, we want to find a term \c ?m s.t. <tt>(?m l_1 ... l_n)</tt> has type \c t
|
|
|
|
The terms \c l_i are just local constants.
|
|
|
|
|
|
|
|
We can convert any metavariable
|
|
|
|
<tt>?m : Pi (x_1 : A_1) ... (x_n : A_n[x_1, ..., x_{n-1}]), B[x_1, ..., x_n]</tt>
|
|
|
|
into a goal by simply creating the local constants
|
|
|
|
<tt>l_1 : A_1, ..., l_n : A_n[l_1, ..., l_{n-1}]</tt>
|
|
|
|
and then, create the goal
|
|
|
|
<tt>?m l_1 ... l_n : B[l_1, ..., l_n]</tt>
|
|
|
|
Now, suppose we find a term \c b with type <tt>B[l_1, ... l_n]</tt>, then we can simply
|
|
|
|
find \c ?m by abstracting <tt>l_1, ..., l_n</tt>
|
|
|
|
|
|
|
|
We can check whether a goal is well formed in an environment by type checking.
|
2014-06-27 18:11:12 +00:00
|
|
|
*/
|
2013-11-21 01:02:41 +00:00
|
|
|
class goal {
|
2014-07-01 23:11:19 +00:00
|
|
|
expr m_meta;
|
|
|
|
expr m_type;
|
2013-11-21 01:02:41 +00:00
|
|
|
public:
|
2013-11-21 23:31:55 +00:00
|
|
|
goal() {}
|
2014-07-01 23:11:19 +00:00
|
|
|
goal(expr const & m, expr const & t):m_meta(m), m_type(t) {}
|
|
|
|
|
|
|
|
expr const & get_meta() const { return m_meta; }
|
|
|
|
expr const & get_type() const { return m_type; }
|
|
|
|
|
|
|
|
name get_name() const { return mlocal_name(get_app_fn(m_meta)); }
|
|
|
|
|
|
|
|
expr get_mvar() const { return get_app_fn(m_meta); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Given a term \c v with type get_type(), build a lambda abstraction
|
|
|
|
that is the solution for the metavariable associated with this goal.
|
|
|
|
*/
|
|
|
|
expr abstract(expr const & v) const;
|
|
|
|
|
2014-06-27 18:11:12 +00:00
|
|
|
/**
|
2014-07-01 23:11:19 +00:00
|
|
|
\brief Create a metavariable application <tt>(?m l_1 ... l_n)</tt> with the given type,
|
|
|
|
and the locals from this goal. If <tt>only_contextual == true</tt>, then we only include
|
|
|
|
the local constants that are marked as contextual.
|
2014-06-27 18:11:12 +00:00
|
|
|
*/
|
2014-07-01 23:11:19 +00:00
|
|
|
expr mk_meta(name const & m, expr const & type, bool only_contextual = true) const;
|
|
|
|
|
2014-06-27 18:11:12 +00:00
|
|
|
/**
|
2014-07-01 23:11:19 +00:00
|
|
|
brief Return true iff get_type() only contains local constants that arguments
|
|
|
|
of get_meta(), and each argument of get_meta() only contains local constants
|
|
|
|
that are previous arguments.
|
2014-06-27 18:11:12 +00:00
|
|
|
*/
|
2014-07-01 23:11:19 +00:00
|
|
|
bool validate_locals() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return true iff \c validate_locals() return true and type of \c get_meta() in
|
|
|
|
\c env is get_type()
|
|
|
|
*/
|
|
|
|
bool validate(environment const & env) 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
|
|
|
};
|
|
|
|
|
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(goal)
|
|
|
|
void open_goal(lua_State * L);
|
2013-11-21 01:02:41 +00:00
|
|
|
}
|