]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground/lib/list_length.ma
update in ground
[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 ≝ match l with
21 [ list_empty     ⇒ 𝟎
22 | list_lcons _ l ⇒ ↑(list_length A l)
23 ].
24
25 interpretation
26   "length (lists)"
27   'card l = (list_length ? l).
28
29 (* Basic constructions ******************************************************)
30
31 lemma list_length_empty (A:Type[0]): |list_empty A| = 𝟎.
32 // qed.
33
34 lemma list_length_lcons (A:Type[0]) (l:list A) (a:A): |a⨮l| = ↑|l|.
35 // qed.
36
37 (* Basic inversions *********************************************************)
38
39 lemma list_length_inv_zero_dx (A:Type[0]) (l:list A):
40       |l| = 𝟎 → l = ⓔ.
41 #A * // #a #l >list_length_lcons #H
42 elim (eq_inv_nsucc_zero … H)
43 qed-.
44
45 lemma list_length_inv_zero_sn (A:Type[0]) (l:list A):
46       (𝟎) = |l| → l = ⓔ.
47 /2 width=1 by list_length_inv_zero_dx/ qed-.
48
49 lemma list_length_inv_succ_dx (A:Type[0]) (l:list A) (x):
50       |l| = ↑x →
51       ∃∃tl,a. x = |tl| & l = a ⨮ tl.
52 #A *
53 [ #x >list_length_empty #H
54   elim (eq_inv_zero_nsucc … H)
55 | #a #l #x >list_length_lcons #H
56   /3 width=4 by eq_inv_nsucc_bi, ex2_2_intro/
57 ]
58 qed-.
59
60 lemma list_length_inv_succ_sn (A:Type[0]) (l:list A) (x):
61       ↑x = |l| →
62       ∃∃tl,a. x = |tl| & l = a ⨮ tl.
63 /2 width=1 by list_length_inv_succ_dx/ qed-.