2

How do I prove the following trivial lemma:

Require Import Vector.

Lemma t0_nil: forall A (x:t A 0), x = nil A.
Proof.
Qed.

FAQ recommends decide equality and discriminate tactics but I could not find a way to apply either of them. For the reference, here is inductive definition:

Inductive t A : nat -> Type :=
  |nil : t A 0
  |cons : forall (h:A) (n:nat), t A n -> t A (S n).
krokodil
  • 1,326
  • 10
  • 18

1 Answers1

3

What you want to do is to invert on x. Unfortunately, it turns out that general inversion of dependently typed hypotheses is undecidable, see Adam Chlipala's CPDT. You can pattern match on the structure manually though, e.g. with:

Lemma t0_nil: forall A (x:t A 0), x = nil A.
  intros.
  refine (match x with 
  | nil => _
  | cons _ _ _ => _
  end).
  - reflexivity.
  - exact @id.
Qed.

In many cases you can also use the tactic dep_destruct provided by CPDT . In that case your proof simply becomes:

Require Import CpdtTactics.

Lemma t0_nil: forall A (x:t A 0), x = nil A.
  intros.
  dep_destruct x.
  reflexivity.
Qed.
Konstantin Weitz
  • 6,180
  • 8
  • 26
  • 43
  • An elegant solution by Pierre Boutillier, taken from this [Coq-club post](http://coq-club.inria.narkive.com/wrDwvaNY/how-to-prove-that-all-vectors-of-0-length-are-equal-to-vector-nil#post2): `Definition t0_nil A (x:t A 0) : x = nil A := match x with nil _ => eq_refl end.` – Anton Trunov Feb 18 '17 at 16:20