feat(library/idx_metavar): add has_idx_metavar

This commit is contained in:
Leonardo de Moura 2015-11-30 09:22:37 -07:00
parent 4d63a27f13
commit d5b2efc74f
2 changed files with 36 additions and 0 deletions

View file

@ -5,6 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "util/interrupt.h"
#include "kernel/for_each_fn.h"
#include "library/idx_metavar.h"
#ifndef LEAN_INSTANTIATE_METAIDX_CACHE_CAPACITY
@ -53,4 +54,36 @@ unsigned to_meta_idx(expr const & e) {
lean_assert(is_idx_metavar(e));
return mlocal_name(e).get_numeral();
}
bool has_idx_metauniv(level const & l) {
if (!has_meta(l))
return false;
bool found = false;
for_each(l, [&](level const & l) {
if (found) return false;
if (!has_meta(l)) return false;
if (is_idx_metauniv(l))
found = true;
return true;
});
return found;
}
bool has_idx_metavar(expr const & e) {
if (!has_univ_metavar(e) && !has_expr_metavar(e))
return false;
bool found = false;
for_each(e, [&](expr const & e, unsigned) {
if (found) return false;
if (!has_univ_metavar(e) && !has_expr_metavar(e)) return false;
if (is_idx_metavar(e))
found = true;
else if (is_constant(e) && std::any_of(const_levels(e).begin(), const_levels(e).end(), has_idx_metauniv))
found = true;
else if (is_sort(e) && has_idx_metauniv(sort_level(e)))
found = true;
return true;
});
return found;
}
}

View file

@ -27,6 +27,9 @@ expr mk_idx_metavar(unsigned i, expr const & type);
bool is_idx_metavar(expr const & l);
unsigned to_meta_idx(expr const & e);
/** \brief Return true iff \c e contains idx metavariables or universe metavariables */
bool has_idx_metavar(expr const & e);
void initialize_idx_metavar();
void finalize_idx_metavar();
}