Iota.v 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. (* SPDX-License-Identifier: GPL-2.0 or GPL-3.0
  2. Copyright © 2019 Ariadne Devos *)
  3. Require Import Coq.Lists.List.
  4. Local Open Scope list_scope.
  5. (* Countdown up to 0, starting from n (exclusive).
  6. Compare with `seq` from Coq.Lists.List *)
  7. (* Element-wise transformations
  8. of a vector, without looking at neighbours,
  9. length ... . Except the index.
  10. Mostly a reiteration of lemma's in Coq's standard
  11. library *)
  12. (* For the exponents of positional numbers: 1111 = 10 ** 3 + 10 ** 2 + 10 ** 1 + 1 *)
  13. Fixpoint countdown n : list nat :=
  14. match n with
  15. | 0 => nil
  16. | S n' => n' :: countdown n'
  17. end.
  18. Theorem countdown_length n : length (countdown n) = n.
  19. Proof.
  20. induction n.
  21. + reflexivity.
  22. + cbn.
  23. rewrite IHn.
  24. reflexivity.
  25. Qed.
  26. Theorem countdown0 : countdown 0 = nil.
  27. Proof. reflexivity. Qed.
  28. Theorem countdown_peell n : countdown (S n) = n :: countdown n.
  29. Proof. reflexivity. Qed.
  30. (* An analogue lemma for seq exists. *)
  31. Theorem countdown_shift n : map S (countdown n) ++ 0 :: nil = countdown (S n).
  32. Proof.
  33. induction n.
  34. + reflexivity.
  35. + rewrite (countdown_peell (S n)).
  36. set (t := map S (countdown (S n))).
  37. cbn in t.
  38. subst t.
  39. rewrite <- app_comm_cons.
  40. rewrite IHn.
  41. reflexivity.
  42. Qed.