]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground/lib/list_append.ma
e4c3d743e2d17273430c19d9672a86fe3bd7a70c
[helm.git] / matita / matita / contribs / lambdadelta / ground / lib / list_append.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/notation/functions/oplus_3.ma".
16 include "ground/lib/list.ma".
17
18 (* APPEND FOR LISTS *********************************************************)
19
20 rec definition list_append A (l1:list A) (l2:list A) on l1 ≝ match l1 with
21 [ list_empty       ⇒ l2
22 | list_lcons hd tl ⇒ hd ⨮ (list_append A tl l2)
23 ].
24
25 interpretation
26   "append (lists)"
27   'OPlus A l1 l2 = (list_append A l1 l2).
28
29 (* Basic constructions ******************************************************)
30
31 lemma list_append_empty_sn (A):
32       ∀l2. l2 = ⓔ ⨁{A} l2.
33 // qed.
34
35 lemma list_append_lcons_sn (A):
36       ∀a,l1,l2. a ⨮ l1 ⨁ l2 = (a⨮l1) ⨁{A} l2.
37 // qed.
38
39 (* Advanced constructions ***************************************************)
40
41 lemma list_append_empty_dx (A):
42       ∀l1. l1 = l1 ⨁{A} ⓔ.
43 #A #l1 elim l1 -l1
44 [ <list_append_empty_sn //
45 | #hd #tl #IH <list_append_lcons_sn <IH //
46 ]
47 qed.
48
49 lemma list_append_assoc (A):
50       associative … (list_append A).
51 #A #l1 elim l1 -l1
52 [ <list_append_empty_sn //
53 | #a1 #l1 #IH *
54   [ #l3 <list_append_empty_dx <list_append_empty_sn //
55   | #a2 #l2 #l3 <list_append_lcons_sn <list_append_lcons_sn <IH //
56   ]
57 ]
58 qed.
59
60 (* Basic inversions *********************************************************)
61
62 lemma eq_inv_list_empty_append (A):
63       ∀l1,l2. ⓔ = l1⨁{A}l2 →
64       ∧∧ ⓔ = l1 & ⓔ = l2.
65 #A *
66 [ #l2 /2 width=1 by conj/
67 | #a1 #l1 #l2 <list_append_lcons_sn #H destruct
68 ]
69 qed-.
70
71 lemma eq_inv_list_append_empty (A):
72       ∀l1,l2. l1⨁{A}l2 = ⓔ →
73       ∧∧ l1 = ⓔ & l2 = ⓔ.
74 #A *
75 [ #l2 /2 width=1 by conj/
76 | #a1 #l1 #l2 <list_append_lcons_sn #H destruct
77 ]
78 qed-.
79
80 (* Advanced inversions ******************************************************)
81
82 lemma eq_inv_list_append_dx_sn_refl (A) (l1) (l2):
83       l1 = l1⨁{A}l2 → ⓔ = l2.
84 #A #l1 elim l1 -l1 [ // ]
85 #a1 #l1 #IH #l2 <list_append_lcons_sn #H0 destruct -H0
86 /2 width=1 by/
87 qed-.
88
89 (* Advanced eliminations ****************************************************)
90
91 lemma list_ind_append_dx (A) (Q:predicate …):
92       Q (ⓔ{A}) →
93       (∀l1,l2. Q l1 -> Q (l1⨁l2)) →
94       ∀l. Q l.
95 #A #Q #IH1 #IH2 * //
96 #a #l >(list_append_empty_sn … (a⨮l))
97 /2 width=1 by/
98 qed-.