Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Pattern matching on vectors

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Pattern matching on vectors


chronological Thread 
  • From: Adam Chlipala <adamc AT hcoop.net>
  • To: Jeff Vaughan <jeff AT seas.harvard.edu>
  • Cc: Coq List <coq-club AT pauillac.inria.fr>
  • Subject: Re: [Coq-Club] Pattern matching on vectors
  • Date: Thu, 08 Oct 2009 19:00:01 -0400
  • List-archive: <http://pauillac.inria.fr/pipermail/coq-club/>

Jeff Vaughan wrote:
Vectors are defined as follows:

  Set Implicit Arguments.

  Inductive vector (A: Type): nat -> Type :=
  | vnil: vector A O
  | vcons: forall len, A -> vector A len -> vector A (S len).
  Implicit Arguments vnil [A].

And I would like to prove, for instance, this lemma:

  Lemma openVector: forall A n (v: vector A (S n)),
    exists a, exists v0, v = vcons a v0.

This is one of my favorite examples, because it's easy to prove directly with a proof term:

Definition openVector A n (v: vector A (S n))
 : exists a, exists v0, v = vcons a v0 :=
   match v in vector _ N return match N return vector A N -> Prop with
                                  | O => fun _ => True
| S n => fun v => exists a, exists v0, v = vcons a v0
                                end v with
     | vnil => I
     | vcons _ a v0 => ex_intro _ a (ex_intro _ v0 (refl_equal _))
   end.

I could try to "explain" what's going on here, but it's probably better to treat this code as a koan and come to your own understanding. :)





Archive powered by MhonArc 2.6.16.

Top of Page