I'm trying to write a--my first--Coq tactic.
It should split forall x y z ..., A <-> B into two: forall x y z ..., A -> B and forall x y z ..., B -> A.
This is my first attempt:
Ltac iff_split H :=
match type of H with
| forall x y, ?A <-> ?B =>
let Hr := fresh H "r" in
let Hl := fresh H "l" in
assert (Hr : forall x y, A -> B) by (apply H);
assert (Hl : forall x y, B -> A) by (apply H);
clear H
end.
It works only for a fixed number of quantifiers (in this case just 2), but I want to extend it to accept an arbitrary list of them.
How can I achieve this?
This answer uses a trick (for expert only ) due to Adam Chlipala. Don't hesitate to ask for more explanation if something is unclear.
Ltacdoes not allow to go under binder but you can trick it by folding the quantifiers. Let us takeforall x y, x + y = 0that is a nested universal quantification. You can fold it in intoforall p, fst p + snd p = 0that is a simple quantification. If you can arbitrary fold and unfold nested quantifications, you are done: you fold, perform your transformation then unfold.Here is the code that does the trick