]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground_2/lib/list.ma
notational update in lambdadelta completed
[helm.git] / matita / matita / contribs / lambdadelta / ground_2 / lib / list.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_2/notation/constructors/nil_0.ma".
16 include "ground_2/notation/constructors/oplusright_3.ma".
17 include "ground_2/lib/arith.ma".
18
19 (* LISTS ********************************************************************)
20
21 inductive list (A:Type[0]) : Type[0] :=
22   | nil : list A
23   | cons: A → list A → list A.
24
25 interpretation "nil (list)" 'Nil = (nil ?).
26
27 interpretation "cons (list)" 'OPlusRight A hd tl = (cons A hd tl).
28
29 rec definition length A (l:list A) on l ≝ match l with
30 [ nil      ⇒ 0
31 | cons _ l ⇒ ↑(length A l)
32 ].
33
34 interpretation "length (list)"
35    'card l = (length ? l).
36
37 rec definition all A (R:predicate A) (l:list A) on l ≝
38   match l with
39   [ nil        ⇒ ⊤
40   | cons hd tl ⇒ R hd ∧ all A R tl
41   ].
42
43 (* Basic properties on length ***********************************************)
44
45 lemma length_nil (A:Type[0]): |nil A| = 0.
46 // qed.
47
48 lemma length_cons (A:Type[0]) (l:list A) (a:A): |a⨮l| = ↑|l|.
49 // qed.
50
51 (* Basic inversion lemmas on length *****************************************)
52
53 lemma length_inv_zero_dx (A:Type[0]) (l:list A): |l| = 0 → l = ◊.
54 #A * // #a #l >length_cons #H destruct
55 qed-.
56
57 lemma length_inv_zero_sn (A:Type[0]) (l:list A): 0 = |l| → l = ◊.
58 /2 width=1 by length_inv_zero_dx/ qed-.
59
60 lemma length_inv_succ_dx (A:Type[0]) (l:list A) (x): |l| = ↑x →
61                          ∃∃tl,a. x = |tl| & l = a ⨮ tl.
62 #A * /2 width=4 by ex2_2_intro/
63 >length_nil #x #H destruct
64 qed-.
65
66 lemma length_inv_succ_sn (A:Type[0]) (l:list A) (x): ↑x = |l| →
67                          ∃∃tl,a. x = |tl| & l = a ⨮ tl.
68 /2 width=1 by length_inv_succ_dx/ qed.