]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground_2/lib/list.ma
ground_2 milestone: multiple relocation with lists of booleans
[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/cons_2.ma".
17 include "ground_2/notation/constructors/cons_3.ma".
18 include "ground_2/notation/functions/append_2.ma".
19 include "ground_2/lib/arith.ma".
20
21 (* LISTS ********************************************************************)
22
23 inductive list (A:Type[0]) : Type[0] :=
24   | nil : list A
25   | cons: A → list A → list A.
26
27 interpretation "nil (list)" 'Nil = (nil ?).
28
29 interpretation "cons (list)" 'Cons hd tl = (cons ? hd tl).
30
31 let rec length (A:Type[0]) (l:list A) on l ≝ match l with
32 [ nil      ⇒ 0
33 | cons _ l ⇒ length A l + 1
34 ].
35
36 interpretation "length (list)"
37    'card l = (length ? l).
38
39 let rec all A (R:predicate A) (l:list A) on l ≝
40   match l with
41   [ nil        ⇒ ⊤
42   | cons hd tl ⇒ R hd ∧ all A R tl
43   ].
44
45 inductive list2 (A1,A2:Type[0]) : Type[0] :=
46   | nil2 : list2 A1 A2
47   | cons2: A1 → A2 → list2 A1 A2 → list2 A1 A2.
48
49 interpretation "nil (list of pairs)" 'Nil = (nil2 ? ?).
50
51 interpretation "cons (list of pairs)" 'Cons hd1 hd2 tl = (cons2 ? ? hd1 hd2 tl).
52
53 let rec append2 (A1,A2:Type[0]) (l1,l2:list2 A1 A2) on l1 ≝ match l1 with
54 [ nil2           ⇒ l2
55 | cons2 a1 a2 tl ⇒ {a1, a2} @ append2 A1 A2 tl l2
56 ].
57
58 interpretation "append (list of pairs)"
59    'Append l1 l2 = (append2 ? ? l1 l2).
60
61 let rec length2 (A1,A2:Type[0]) (l:list2 A1 A2) on l ≝ match l with
62 [ nil2        ⇒ 0
63 | cons2 _ _ l ⇒ length2 A1 A2 l + 1
64 ].
65
66 interpretation "length (list of pairs)"
67    'card l = (length2 ? ? l).