feat(library/tactic/induction_tactic): try available recursors until one works

closes #615
This commit is contained in:
Leonardo de Moura 2015-05-20 23:23:05 -07:00
parent 2164ba6f20
commit d6b72ef4d7
2 changed files with 36 additions and 2 deletions

View file

@ -332,8 +332,21 @@ public:
return execute(g, H, H_type, *m_rec_name);
} else if (inductive::is_inductive_decl(m_env, const_name(I))) {
return execute(g, H, H_type, inductive::get_elim_name(const_name(I)));
} else if (auto rs = get_recursors_for(m_env, const_name(I))) {
return execute(g, H, H_type, head(rs));
} else if (list<name> rs = get_recursors_for(m_env, const_name(I))) {
while (rs) {
name r = head(rs);
rs = tail(rs);
if (!rs) {
// last one
return execute(g, H, H_type, r);
} else {
try {
flet<list<name>> save_ids(m_ids, m_ids);
flet<constraint_seq> save_cs(m_cs, m_cs);
return execute(g, H, H_type, r);
} catch (exception &) {}
}
}
}
}
throw tactic_exception(sstream() << "invalid 'induction' tactic, hypothesis '" << m_h_name

21
tests/lean/hott/615.hlean Normal file
View file

@ -0,0 +1,21 @@
-- HoTT
import hit.circle
open circle eq int
attribute circle.rec circle.elim [recursor 4]
protected definition my_code (x : circle) : Type₀ :=
begin
induction x,
{ exact },
{ apply ua, apply equiv_succ}
end
protected definition my_decode {x : circle} : my_code x → base = x :=
begin
induction x,
{ exact power loop},
{ apply eq_of_homotopy, intro a,
refine !arrow.arrow_transport ⬝ !transport_eq_r ⬝ _,
rewrite [transport_code_loop_inv,power_con,succ_pred]}
end