default.txt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. Inductive seq : nat -> Set :=
  2. | niln : seq 0
  3. | consn : forall n : nat, nat -> seq n -> seq (S n).
  4. Fixpoint length (n : nat) (s : seq n) {struct s} : nat :=
  5. match s with
  6. | niln => 0
  7. | consn i _ s' => S (length i s')
  8. end.
  9. Theorem length_corr : forall (n : nat) (s : seq n), length n s = n.
  10. Proof.
  11. intros n s.
  12. (* reasoning by induction over s. Then, we have two new goals
  13. corresponding on the case analysis about s (either it is
  14. niln or some consn *)
  15. induction s.
  16. (* We are in the case where s is void. We can reduce the
  17. term: length 0 niln *)
  18. simpl.
  19. (* We obtain the goal 0 = 0. *)
  20. trivial.
  21. (* now, we treat the case s = consn n e s with induction
  22. hypothesis IHs *)
  23. simpl.
  24. (* The induction hypothesis has type length n s = n.
  25. So we can use it to perform some rewriting in the goal: *)
  26. rewrite IHs.
  27. (* Now the goal is the trivial equality: S n = S n *)
  28. trivial.
  29. (* Now all sub cases are closed, we perform the ultimate
  30. step: typing the term built using tactics and save it as
  31. a witness of the theorem. *)
  32. Qed.