]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground/lib/list_length.ma
propagating the arithmetics library, partial commit
[helm.git] / matita / matita / contribs / lambdadelta / ground / lib / list_length.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "ground/lib/list.ma".
16 include "ground/arith/nat_succ.ma".
17
18 (* LENGTH FOR LISTS *********************************************************)
19
20 rec definition list_length A (l:list A) on l ≝
21 match l with
22 [ list_nil      ⇒ 𝟎
23 | list_cons _ l ⇒ ↑(list_length A l)
24 ].
25
26 interpretation
27   "length (lists)"
28   'card l = (list_length ? l).
29
30 (* Basic constructions ******************************************************)
31
32 lemma list_length_nil (A:Type[0]): |list_nil A| = 𝟎.
33 // qed.
34
35 lemma list_length_cons (A:Type[0]) (l:list A) (a:A): |a⨮l| = ↑|l|.
36 // qed.
37
38 (* Basic inversions *********************************************************)
39
40 lemma list_length_inv_zero_dx (A:Type[0]) (l:list A):
41       |l| = 𝟎 → l = Ⓔ.
42 #A * // #a #l >list_length_cons #H
43 elim (eq_inv_nsucc_zero … H)
44 qed-.
45
46 lemma list_length_inv_zero_sn (A:Type[0]) (l:list A):
47       (𝟎) = |l| → l = Ⓔ.
48 /2 width=1 by list_length_inv_zero_dx/ qed-.
49
50 lemma list_length_inv_succ_dx (A:Type[0]) (l:list A) (x):
51       |l| = ↑x →
52       ∃∃tl,a. x = |tl| & l = a ⨮ tl.
53 #A *
54 [ #x >list_length_nil #H
55   elim (eq_inv_zero_nsucc … H)
56 | #a #l #x >list_length_cons #H
57   /3 width=4 by eq_inv_nsucc_bi, ex2_2_intro/
58 ]
59 qed-.
60
61 lemma list_length_inv_succ_sn (A:Type[0]) (l:list A) (x):
62       ↑x = |l| →
63       ∃∃tl,a. x = |tl| & l = a ⨮ tl.
64 /2 width=1 by list_length_inv_succ_dx/ qed-.