0

How do I prove a lemma like the following:

Require Import Coq.Lists.List.

Lemma len_seq_n : forall start n, length (seq start n)=n.

I tried

Proof.
induction n.
simpl. auto. simpl.  

and at this point Coq gives me

1 subgoal
start, n : nat
IHn : length (seq start n) = n
______________________________________(1/1)
S (length (seq (S start) n)) = S n

I'm not sure how to proceed from there.

Jason Gross
  • 5,928
  • 1
  • 26
  • 53
D. Huang
  • 445
  • 1
  • 4
  • 5

1 Answers1

3

The problem is that your induction hypothesis is not general enough. You need the following statement instead:

IHn : forall start', length (seq start' n) = n

To obtain this hypothesis, simply generalize over start before doing induction on n with the revert tactic.

Proof.
  intros start n.
  revert start.
  induction n.
  (* Continue as previously *)

(Next time, please provide a complete example so that we can help you better. Your question was missing the definition of seq.)

Arthur Azevedo De Amorim
  • 23,012
  • 3
  • 33
  • 39
  • 1
    IMVHO a slightly better style would be to reverse the declaration order of the parameters, this way you save the revert. – ejgallego Sep 29 '17 at 10:17
  • And there is the `Lemma seq_length : forall len start, length (seq start len) = len.` there. So, indeed, they stated it as ejgallego suggested. – Anton Trunov Sep 30 '17 at 12:06