]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/list/list.ma
added list.ma
[helm.git] / helm / matita / library / list / 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 set "baseuri" "cic:/matita/list/".
16 include "logic/equality.ma".
17 include "higher_order_defs/functions.ma".
18
19 interpretation "leibnitz's equality" 'eq x y =
20   (cic:/matita/logic/equality/eq.ind#xpointer(1/1) _ x y).
21
22 notation "hvbox(hd break :: tl)"
23   right associative with precedence 46
24   for @{'cons $hd $tl}.
25
26 notation "[ list0 x sep ; ]"
27   non associative with precedence 90
28   for ${fold right @'nil rec acc @{'cons $x $acc}}.
29
30 notation "hvbox(l1 break @ l2)"
31   right associative with precedence 47
32   for @{'append $l1 $l2 }.
33
34 inductive list (A:Set) : Set \def
35   | nil: list A
36   | cons: A \to list A \to list A.
37
38 interpretation "nil" 'nil = (cic:/matita/list/list.ind#xpointer(1/1/1) _).
39 interpretation "cons" 'cons hd tl =
40   (cic:/matita/list/list.ind#xpointer(1/1/2) _ hd tl).
41
42 theorem nil_cons:
43   \forall A:Set.\forall l:list A.\forall a:A.
44     a::l \neq [].
45   intros.
46   unfold; intros.
47   discriminate H.
48 qed.
49
50 let rec id_list A (l: list A) on l \def
51   match l with
52   [ nil \Rightarrow []
53   | (cons hd tl) \Rightarrow hd :: id_list A tl ].
54
55 let rec append A (l1: list A) l2 on l1 \def
56   match l1 with
57   [ nil \Rightarrow l2
58   | (cons hd tl) \Rightarrow hd :: append A tl l2 ].
59
60 interpretation "append" 'append l1 l2 = (cic:/matita/list/append.con _ l1 l2).
61
62 theorem append_nil: \forall A:Set.\forall l:list A.l @ [] = l.
63   intros.
64   elim l.
65   reflexivity.
66   simplify.
67   rewrite > H.
68   reflexivity.
69 qed.
70
71 theorem associative_append: \forall A:Set.associative (list A) (append A).
72   intros; unfold; intros.
73   elim x.
74   simplify; reflexivity.
75   simplify.
76   rewrite > H.
77   reflexivity.
78 qed.
79
80 theorem cons_append_commute:
81   \forall A:Set.\forall l1,l2:list A.\forall a:A.
82     a :: (l1 @ l2) = (a :: l1) @ l2.
83   intros.
84   reflexivity.
85 qed.
86
87 (*
88 theorem nil_append_nil_both:
89   \forall A:Set.\forall l1,l2:list A.
90     l1 @ l2 = [] \to l1 = [] \land l2 = [].
91 *)
92
93 (*
94 include "nat/nat.ma".
95
96 theorem test_notation: [O; S O; S (S O)] = O :: S O :: S (S O) :: []. 
97 reflexivity.
98 qed.
99
100 theorem test_append: [O;O;O;O;O;O] = [O;O;O] @ [O;O] @ [O].
101 simplify.
102 reflexivity.
103 qed.
104 *)