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