optional<expr> unfold_step(type_context & ctx, expr const & e, name_set const & to_unfold, bool unfold_reducible) { if (!unfold_reducible && to_unfold.empty()) return none_expr(); if (!is_app(e) && !is_constant(e)) return none_expr(); expr const & fn = get_app_fn(e); if (!is_constant(fn)) return none_expr(); name const & fn_name = const_name(fn); bool in_to_unfold = to_unfold.contains(const_name(fn)); if (!in_to_unfold && !unfold_reducible) return none_expr(); if (is_projection(ctx.env(), const_name(fn))) { if (in_to_unfold) { type_context::transparency_scope scope(ctx, transparency_mode::Instances); return ctx.reduce_projection(e); } else { return none_expr(); } } else if (in_to_unfold) { return unfold_term(ctx.env(), e); } else if (unfold_reducible && is_reducible(ctx.env(), fn_name)) { type_context::transparency_scope scope(ctx, transparency_mode::Reducible); return unfold_term(ctx.env(), e); } else { return none_expr(); } }
backward_lemma_index::backward_lemma_index(type_context & ctx): m_index(get_intro_attribute().get_instances_by_prio(ctx.env())) { buffer<name> lemmas; get_intro_attribute().get_instances(ctx.env(), lemmas); unsigned i = lemmas.size(); while (i > 0) { --i; optional<head_index> target = get_backward_target(ctx, lemmas[i]); if (!target || target->kind() != expr_kind::Constant) { lean_trace(name({"tactic", "back_chaining"}), tout() << "discarding [intro] lemma '" << lemmas[i] << "', failed to find target type\n";); } else {
expr gexpr::to_expr(type_context & ctx) const { if (m_univ_poly) { declaration const & fdecl = ctx.env().get(const_name(m_expr)); buffer<level> ls_buffer; unsigned num_univ_ps = fdecl.get_num_univ_params(); for (unsigned i = 0; i < num_univ_ps; i++) ls_buffer.push_back(ctx.mk_uvar()); levels ls = to_list(ls_buffer.begin(), ls_buffer.end()); return mk_constant(const_name(m_expr), ls); } else { return m_expr; } }
static optional<head_index> get_backward_target(type_context & ctx, name const & c) { declaration const & d = ctx.env().get(c); list<level> us = param_names_to_levels(d.get_univ_params()); expr type = ctx.try_to_pi(instantiate_type_univ_params(d, us)); return get_backward_target(ctx, type); }