I read that the induction principle for a type is simply a proposition theorem for P Therefore, I built the induction principle for List based on the right (or reverse) list constructor.
Definition rcons {X:Type} (l:list X) (x:X) : list X := l ++ x::nil.
The principle of induction itself:
Definition true_for_nil {X:Type}(P:list X -> Prop) : Prop := P nil. Definition true_for_list {X:Type} (P:list X -> Prop) : Prop := forall xs, P xs. Definition preserved_by_rcons {X:Type} (P: list X -> Prop): Prop := forall xs' x, P xs' -> P (rcons xs' x). Theorem list_ind_rcons: forall {X:Type} (P:list X -> Prop), true_for_nil P -> preserved_by_rcons P -> true_for_list P. Proof. Admitted.
But now I am having problems using the theorem. I cannot use it the same way as induction tactics.
For example, I tried:
Theorem rev_app_dist: forall {X} (l1 l2:list X), rev (l1 ++ l2) = rev l2 ++ rev l1. Proof. intros X l1 l2. induction l2 using list_ind_rcons.
But in the last line, I got:
Error: Cannot recognize an induction scheme.
What are the right steps to define and apply a custom induction principle like list_ind_rcons ?
thanks
source share