Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Inductive family of finite types

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Inductive family of finite types


chronological Thread 
  • From: Gert Smolka <smolka AT ps.uni-saarland.de>
  • To: coq-club AT inria.fr
  • Cc: Adam Chlipala <adam AT chlipala.net>
  • Subject: Re: [Coq-Club] Inductive family of finite types
  • Date: Tue, 28 Jun 2011 18:28:52 +0200

Thanks Adam, you made my day.

So the trick is to formulate the inversion
lemma with a match so that it type checks.

Inductive Fin : nat -> Type :=
| FinO : forall n, Fin (S n)
| FinS : forall n, Fin n -> Fin (S n).

Lemma Fin_inversion {n : nat} (k : Fin n) :
match n as z return Fin z -> Prop with
| 0 => fun k => False
| S n' => fun k =>  k = FinO n' \/ exists k', k = FinS n' k'
end k.
Proof. destruct k. tauto. right. exists k. reflexivity. Qed.

Lemma Fin1 (k : Fin 1) :
k = FinO 0.
Proof. destruct (Fin_inversion k) as [A|[k' A]]. exact A.
contradiction (Fin_inversion k'). Qed.


Am 28.06.2011 17:11, schrieb Adam Chlipala:
Definition out n (k : Fin n) :=
  match k in Fin n return match n return Fin n -> Type with
                            | O => fun _ => Empty_set
| S n' => fun k => {k' | k = FinS _ k'} + {k = FinO _}
                          end k with
    | FinO _ => inright _ (refl_equal _)
    | FinS _ _ => inleft _ (exist _ _ (refl_equal _))
  end.

Definition Fin1 (k : Fin 1) : k = FinO 0 :=
  match out _ k with
    | inleft (exist k' _) => match out _ k' with end
    | inright pf => pf
  end.





Archive powered by MhonArc 2.6.16.

Top of Page