feat(kernel): define metavar substitution based on red-black trees

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-02-21 17:55:59 -08:00
parent f855dbb7b0
commit 5f4b1cf47e
2 changed files with 52 additions and 0 deletions

12
src/kernel/metavar.cpp Normal file
View file

@ -0,0 +1,12 @@
/*
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 "util/metavar.h"
namespace lean {
}

40
src/kernel/metavar.h Normal file
View file

@ -0,0 +1,40 @@
/*
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 "util/rb_map.h"
#include "util/optional.h"
#include "kernel/expr.h"
#include "kernel/justification.h"
namespace lean {
class substitution {
rb_map<name, std::pair<expr, justification>, name_quick_cmp> m_subst;
public:
substitution();
bool is_assigned(name const & m) const;
optional<std::pair<expr, justification>> get_assignment(name const & m) const;
void assign(name const & m, expr const & t, justification const & j);
void assign(name const & m, expr const & t);
void for_each(std::function<void(name const & n, expr const & e, justification const & j)> const & fn);
};
/**
\brief Instantiate metavariables in \c e assigned in the substitution \c s.
*/
std::pair<expr, justification> instantiate_metavars(expr const & e, substitution const & s);
/**
\brief Similar to the previous function, but it compress the substitution.
By compress, we mean, for any metavariable \c m reachable from \c e,
if s[m] = t, and t has asssigned metavariables, then s[m] <- instantiate_metavars(t, s).
*/
std::pair<expr, justification> d_instantiate_metavars(expr const & e, substitution & s);
/**
\brief Instantiate metavariables in \c e assigned in the substitution \c s,
but does not return a justification object for the new expression.
*/
expr instantiate_metavars_wo_jst(expr const & e, substitution const & s);
}