2013-07-23 18:31:31 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2013-09-13 10:35:29 +00:00
|
|
|
#include "kernel/expr.h"
|
2013-12-13 01:47:11 +00:00
|
|
|
#include "kernel/metavar.h"
|
2013-07-23 18:31:31 +00:00
|
|
|
namespace lean {
|
|
|
|
/**
|
2013-07-26 19:27:55 +00:00
|
|
|
\brief Return true iff the given expression has free variables.
|
2013-07-23 18:31:31 +00:00
|
|
|
*/
|
|
|
|
bool has_free_vars(expr const & a);
|
2013-07-26 18:43:53 +00:00
|
|
|
/**
|
2013-07-26 19:27:55 +00:00
|
|
|
\brief Return true iff the given expression does not have free variables.
|
2013-07-26 18:43:53 +00:00
|
|
|
*/
|
2013-07-23 18:31:31 +00:00
|
|
|
inline bool closed(expr const & a) { return !has_free_vars(a); }
|
2013-07-26 19:27:55 +00:00
|
|
|
|
2013-12-11 23:21:52 +00:00
|
|
|
class metavar_env;
|
|
|
|
/**
|
|
|
|
\brief Return \c R s.t. the de Bruijn index of all free variables
|
|
|
|
occurring in \c e is in the interval <tt>[0, R)</tt>.
|
|
|
|
|
|
|
|
\pre All metavariables occurring in \c e must have been created
|
|
|
|
at \c menv.
|
|
|
|
|
|
|
|
\remark Regarding metavariables, if a metavariable \c m was defined
|
|
|
|
in a context \c ctx and <tt>ctx.size() == R</tt>, then \c m can
|
|
|
|
only contain free variables in the range <tt>[0, R)</tt>
|
|
|
|
|
|
|
|
So, if \c m does not have an associated local context, the answer is just \c R.
|
|
|
|
If \c m has an associated local context, we process it using the following rules
|
|
|
|
|
|
|
|
[inst:s v] R ===> if s >= R then R else max(R-1, range_of(v))
|
|
|
|
[lift:s:n] R ===> if s >= R then R else R + n
|
|
|
|
*/
|
|
|
|
unsigned free_var_range(expr const & e, metavar_env const & menv);
|
2014-01-13 01:06:57 +00:00
|
|
|
unsigned free_var_range(expr const & e);
|
2013-12-11 23:21:52 +00:00
|
|
|
|
2013-07-26 19:27:55 +00:00
|
|
|
/**
|
|
|
|
\brief Return true iff \c e constains a free variable <tt>(var i)</tt> s.t. \c i in <tt>[low, high)</tt>.
|
|
|
|
\pre low < high
|
2013-12-11 23:49:32 +00:00
|
|
|
|
2013-12-13 01:47:11 +00:00
|
|
|
\remark If menv is not none, then we use \c free_var_range to compute the free variables that may
|
2013-12-11 23:49:32 +00:00
|
|
|
occur in a metavariable.
|
2013-07-26 19:27:55 +00:00
|
|
|
*/
|
2013-12-13 01:47:11 +00:00
|
|
|
bool has_free_var(expr const & e, unsigned low, unsigned high, optional<metavar_env> const & menv);
|
|
|
|
bool has_free_var(expr const & e, unsigned low, unsigned high, metavar_env const & menv);
|
|
|
|
bool has_free_var(expr const & e, unsigned low, unsigned high);
|
2013-12-11 23:49:32 +00:00
|
|
|
/**
|
|
|
|
\brief Return true iff \c e contains the free variable <tt>(var i)</tt>.
|
|
|
|
*/
|
2013-12-13 01:47:11 +00:00
|
|
|
bool has_free_var(expr const & e, unsigned i, optional<metavar_env> const & menv);
|
|
|
|
bool has_free_var(expr const & e, unsigned i, metavar_env const & menv);
|
|
|
|
bool has_free_var(expr const & e, unsigned i);
|
2013-07-26 19:27:55 +00:00
|
|
|
|
2014-01-01 11:02:41 +00:00
|
|
|
bool has_free_var(context_entry const & e, unsigned low, unsigned high, metavar_env const & menv);
|
|
|
|
|
2013-07-26 19:27:55 +00:00
|
|
|
/**
|
2013-12-11 23:49:32 +00:00
|
|
|
\brief Lower the free variables >= s in \c e by \c d. That is, a free variable <tt>(var i)</tt> s.t.
|
2013-09-13 01:25:38 +00:00
|
|
|
<tt>i >= s</tt> is mapped into <tt>(var i-d)</tt>.
|
2013-07-26 19:27:55 +00:00
|
|
|
|
2013-12-11 23:49:32 +00:00
|
|
|
\pre s >= d
|
2014-01-01 11:02:41 +00:00
|
|
|
\pre !has_free_var(e, s-d, s, menv)
|
2013-12-11 23:49:32 +00:00
|
|
|
|
|
|
|
\remark The parameter menv is only used for debugging purposes
|
2013-07-26 19:27:55 +00:00
|
|
|
*/
|
2013-12-13 01:47:11 +00:00
|
|
|
expr lower_free_vars(expr const & e, unsigned s, unsigned d, optional<metavar_env> const & menv);
|
|
|
|
expr lower_free_vars(expr const & e, unsigned s, unsigned d, metavar_env const & menv);
|
|
|
|
expr lower_free_vars(expr const & e, unsigned s, unsigned d);
|
|
|
|
expr lower_free_vars(expr const & e, unsigned d, optional<metavar_env> const & menv);
|
|
|
|
expr lower_free_vars(expr const & e, unsigned d, metavar_env const & menv);
|
|
|
|
expr lower_free_vars(expr const & e, unsigned d);
|
2013-07-30 08:39:29 +00:00
|
|
|
|
2014-01-01 11:02:41 +00:00
|
|
|
context_entry lower_free_vars(context_entry const & e, unsigned s, unsigned d, metavar_env const & menv);
|
|
|
|
|
2013-07-30 08:39:29 +00:00
|
|
|
/**
|
2013-09-13 01:25:38 +00:00
|
|
|
\brief Lift free variables >= s in \c e by d.
|
2013-12-12 18:50:07 +00:00
|
|
|
|
2013-12-13 01:47:11 +00:00
|
|
|
\remark When the parameter menv is not none, this function will minimize the use
|
2013-12-12 18:50:07 +00:00
|
|
|
of the local entry lift in metavariables occurring in \c e.
|
2013-07-30 08:39:29 +00:00
|
|
|
*/
|
2013-12-13 01:47:11 +00:00
|
|
|
expr lift_free_vars(expr const & e, unsigned s, unsigned d, optional<metavar_env> const & menv);
|
|
|
|
expr lift_free_vars(expr const & e, unsigned s, unsigned d);
|
|
|
|
expr lift_free_vars(expr const & e, unsigned s, unsigned d, metavar_env const & menv);
|
|
|
|
expr lift_free_vars(expr const & e, unsigned d, optional<metavar_env> const & menv);
|
|
|
|
expr lift_free_vars(expr const & e, unsigned d, metavar_env const & menv);
|
|
|
|
expr lift_free_vars(expr const & e, unsigned d);
|
2014-01-01 11:02:41 +00:00
|
|
|
|
|
|
|
context_entry lift_free_vars(context_entry const & e, unsigned s, unsigned d, metavar_env const & menv);
|
2013-07-23 18:31:31 +00:00
|
|
|
}
|