2014-06-21 20:37:44 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <utility>
|
|
|
|
#include <functional>
|
|
|
|
#include "util/lua.h"
|
|
|
|
#include "util/lazy_list.h"
|
|
|
|
#include "util/name_generator.h"
|
2014-06-23 19:38:57 +00:00
|
|
|
#include "util/sexpr/options.h"
|
2014-06-21 20:37:44 +00:00
|
|
|
#include "kernel/constraint.h"
|
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "kernel/metavar.h"
|
|
|
|
|
2014-06-23 19:38:57 +00:00
|
|
|
#ifndef LEAN_DEFAULT_UNIFIER_MAX_STEPS
|
|
|
|
#define LEAN_DEFAULT_UNIFIER_MAX_STEPS 10000
|
|
|
|
#endif
|
|
|
|
|
2014-06-21 20:37:44 +00:00
|
|
|
namespace lean {
|
|
|
|
enum class unify_status { Solved, Failed, Unsupported };
|
|
|
|
/**
|
|
|
|
\brief Handle the easy-cases: first-order unification, higher-order patterns, identical terms, and terms without metavariables.
|
|
|
|
|
|
|
|
This function assumes that all assigned metavariables have been substituted.
|
|
|
|
*/
|
|
|
|
std::pair<unify_status, substitution> unify_simple(substitution const & s, expr const & lhs, expr const & rhs, justification const & j);
|
|
|
|
std::pair<unify_status, substitution> unify_simple(substitution const & s, level const & lhs, level const & rhs, justification const & j);
|
|
|
|
std::pair<unify_status, substitution> unify_simple(substitution const & s, constraint const & c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief A unifier_plugin provides a simple way to extend the \c unify procedures.
|
|
|
|
Whenever, the default implementation does not know how to solve a constraint, it invokes the plugin.
|
|
|
|
The plugin return a lazy_list (stream) of possible solutions. Each "solution" is represented as
|
|
|
|
a new list of constraints.
|
|
|
|
*/
|
|
|
|
typedef std::function<lazy_list<constraints>(constraint const &, name_generator const &)> unifier_plugin;
|
|
|
|
|
|
|
|
lazy_list<substitution> unify(environment const & env, unsigned num_cs, constraint const * cs, name_generator const & ngen,
|
2014-06-23 19:38:57 +00:00
|
|
|
unifier_plugin const & p, bool use_exception = true, unsigned max_steps = LEAN_DEFAULT_UNIFIER_MAX_STEPS);
|
|
|
|
lazy_list<substitution> unify(environment const & env, unsigned num_cs, constraint const * cs, name_generator const & ngen,
|
|
|
|
bool use_exception = true, unsigned max_steps = LEAN_DEFAULT_UNIFIER_MAX_STEPS);
|
2014-06-21 20:37:44 +00:00
|
|
|
lazy_list<substitution> unify(environment const & env, unsigned num_cs, constraint const * cs, name_generator const & ngen,
|
2014-06-23 19:38:57 +00:00
|
|
|
unifier_plugin const & p, options const & o);
|
|
|
|
lazy_list<substitution> unify(environment const & env, unsigned num_cs, constraint const * cs, name_generator const & ngen,
|
|
|
|
options const & o);
|
|
|
|
lazy_list<substitution> unify(environment const & env, expr const & lhs, expr const & rhs, name_generator const & ngen, unifier_plugin const & p,
|
|
|
|
unsigned max_steps = LEAN_DEFAULT_UNIFIER_MAX_STEPS);
|
|
|
|
lazy_list<substitution> unify(environment const & env, expr const & lhs, expr const & rhs, name_generator const & ngen,
|
|
|
|
unsigned max_sharing = LEAN_DEFAULT_UNIFIER_MAX_STEPS);
|
|
|
|
lazy_list<substitution> unify(environment const & env, expr const & lhs, expr const & rhs, name_generator const & ngen, unifier_plugin const & p,
|
|
|
|
options const & o);
|
|
|
|
lazy_list<substitution> unify(environment const & env, expr const & lhs, expr const & rhs, name_generator const & ngen,
|
|
|
|
options const & o);
|
|
|
|
|
|
|
|
class unifier_exception : public exception {
|
|
|
|
justification m_jst;
|
|
|
|
public:
|
|
|
|
unifier_exception(justification const & j):exception("unifier exception"), m_jst(j) {}
|
|
|
|
virtual exception * clone() const { return new unifier_exception(m_jst); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
|
|
|
justification const & get_justification() const { return m_jst; }
|
|
|
|
};
|
2014-06-21 20:37:44 +00:00
|
|
|
|
|
|
|
void open_unifier(lua_State * L);
|
|
|
|
}
|