feat(kernel/inductive): add get_num_minor_premises and get_num_type_formers APIs

This commit is contained in:
Leonardo de Moura 2014-10-25 11:17:29 -07:00
parent 2bc034da2c
commit 7240a1a640
2 changed files with 26 additions and 0 deletions

View file

@ -971,6 +971,24 @@ optional<unsigned> get_num_indices(environment const & env, name const & n) {
} }
} }
optional<unsigned> get_num_type_formers(environment const & env, name const & n) {
if (auto decls = is_inductive_decl(env, n)) {
return some(length(std::get<2>(*decls)));
} else {
return optional<unsigned>();
}
}
optional<unsigned> get_num_minor_premises(environment const & env, name const & n) {
inductive_env_ext const & ext = get_extension(env);
if (auto it = ext.m_elim_info.find(get_elim_name(n))) {
unsigned num_Cs = *get_num_type_formers(env, n);
return some(it->m_num_ACe - it->m_num_params - num_Cs);
} else {
return optional<unsigned>();
}
}
optional<name> is_intro_rule(environment const & env, name const & n) { optional<name> is_intro_rule(environment const & env, name const & n) {
inductive_env_ext const & ext = get_extension(env); inductive_env_ext const & ext = get_extension(env);
if (auto it = ext.m_intro_info.find(n)) if (auto it = ext.m_intro_info.find(n))

View file

@ -72,6 +72,14 @@ bool is_elim_meta_app(type_checker & tc, expr const & e);
If \c n is not an inductive datatype in \c env, then return none. If \c n is not an inductive datatype in \c env, then return none.
*/ */
optional<unsigned> get_num_indices(environment const & env, name const & n); optional<unsigned> get_num_indices(environment const & env, name const & n);
/** \brief Return the number of minor premises in the given inductive datatype.
If \c n is not an inductive datatype in \c env, then return none.
*/
optional<unsigned> get_num_minor_premises(environment const & env, name const & n);
/** \brief Return the number of type formers in the given inductive datatype.
If \c n is not an inductive datatype in \c env, then return none.
*/
optional<unsigned> get_num_type_formers(environment const & env, name const & n);
/** \brief Return the eliminator/recursor associated with an inductive datatype */ /** \brief Return the eliminator/recursor associated with an inductive datatype */
name get_elim_name(name const & n); name get_elim_name(name const & n);