]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/etc_new/lenv/lenv_append.etc
4f5f26fc99cb1d76f8d98b27616e2aa3e1d264eb
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / etc_new / lenv / lenv_append.etc
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/functions/append_2.ma".
16 include "ground_2/ynat/ynat_plus.ma".
17 include "basic_2/notation/functions/snbind2_3.ma".
18 include "basic_2/notation/functions/snabbr_2.ma".
19 include "basic_2/notation/functions/snabst_2.ma".
20 include "basic_2/grammar/lenv_length.ma".
21
22 (* LOCAL ENVIRONMENTS *******************************************************)
23
24 let rec append L K on K ≝ match K with
25 [ LAtom       ⇒ L
26 | LPair K I V ⇒ (append L K). ⓑ{I} V
27 ].
28
29 interpretation "append (local environment)" 'Append L1 L2 = (append L1 L2).
30
31 interpretation "local environment tail binding construction (binary)"
32    'SnBind2 I T L = (append (LPair LAtom I T) L).
33
34 interpretation "tail abbreviation (local environment)"
35    'SnAbbr T L = (append (LPair LAtom Abbr T) L).
36
37 interpretation "tail abstraction (local environment)"
38    'SnAbst L T = (append (LPair LAtom Abst T) L).
39
40 definition d_appendable_sn: predicate (lenv→relation term) ≝ λR.
41                             ∀K,T1,T2. R K T1 T2 → ∀L. R (L @@ K) T1 T2.
42
43 (* Basic properties *********************************************************)
44
45 lemma append_atom: ∀L. L @@ ⋆ = L.
46 // qed.
47
48 lemma append_pair: ∀I,L,K,V. L @@ (K.ⓑ{I}V) = (L @@ K).ⓑ{I}V.
49 // qed.
50
51 lemma append_atom_sn: ∀L. ⋆ @@ L = L.
52 #L elim L -L //
53 #L #I #V >append_pair //
54 qed.
55
56 lemma append_assoc: associative … append.
57 #L1 #L2 #L3 elim L3 -L3 //
58 qed.
59
60 lemma append_length: ∀L1,L2. |L1 @@ L2| = |L1| + |L2|.
61 #L1 #L2 elim L2 -L2 //
62 #L2 #I #V2 >append_pair >length_pair >length_pair //
63 qed.
64
65 lemma ltail_length: ∀I,L,V. |ⓑ{I}V.L| = ⫯|L|.
66 #I #L #V >append_length //
67 qed.
68
69 (* Basic_1: was just: chead_ctail *)
70 lemma lpair_ltail: ∀L,I,V. ∃∃J,K,W. L.ⓑ{I}V = ⓑ{J}W.K & |L| = |K|.
71 #L elim L -L /2 width=5 by ex2_3_intro/
72 #L #Z #X #IHL #I #V elim (IHL Z X) -IHL
73 #J #K #W #H #_ >H -H >ltail_length
74 @(ex2_3_intro … J (K.ⓑ{I}V) W) //
75 qed-.
76
77 (* Basic inversion lemmas ***************************************************)
78
79 lemma append_inj_sn: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |K1| = |K2| →
80                      L1 = L2 ∧ K1 = K2.
81 #K1 elim K1 -K1
82 [ * /2 width=1 by conj/
83   #K2 #I2 #V2 #L1 #L2 #_ >length_atom >length_pair
84   #H elim (ysucc_inv_O_sn … H)
85 | #K1 #I1 #V1 #IH *
86   [ #L1 #L2 #_ >length_atom >length_pair
87     #H elim (ysucc_inv_O_dx … H)
88   | #K2 #I2 #V2 #L1 #L2 #H1 #H2
89     elim (destruct_lpair_lpair_aux … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
90     elim (IH … H1) -IH -H1 /3 width=1 by ysucc_inv_inj, conj/
91   ]
92 ]
93 qed-.
94
95 (* Note: lemma 750 *)
96 lemma append_inj_dx: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |L1| = |L2| →
97                      L1 = L2 ∧ K1 = K2.
98 #K1 elim K1 -K1
99 [ * /2 width=1 by conj/
100   #K2 #I2 #V2 #L1 #L2 >append_atom >append_pair #H destruct
101   >length_pair >append_length <yplus_succ2 #H
102   elim (discr_yplus_xy_x … H) -H #H
103   [ elim (ylt_yle_false (|L2|) (∞)) // | elim (ysucc_inv_O_dx … H) ]
104 | #K1 #I1 #V1 #IH *
105   [ #L1 #L2 >append_pair >append_atom #H destruct
106     >length_pair >append_length <yplus_succ2 #H
107     elim (discr_yplus_x_xy … H) -H #H
108     [ elim (ylt_yle_false (|L1|) (∞)) // | elim (ysucc_inv_O_dx … H) ]
109   | #K2 #I2 #V2 #L1 #L2 >append_pair >append_pair #H1 #H2
110     elim (destruct_lpair_lpair_aux … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
111     elim (IH … H1) -IH -H1 /2 width=1 by conj/
112   ]
113 ]
114 qed-.
115
116 lemma append_inv_refl_dx: ∀L,K. L @@ K = L → K = ⋆.
117 #L #K #H elim (append_inj_dx … (⋆) … H) //
118 qed-.
119
120 lemma append_inv_pair_dx: ∀I,L,K,V. L @@ K = L.ⓑ{I}V → K = ⋆.ⓑ{I}V.
121 #I #L #K #V #H elim (append_inj_dx … (⋆.ⓑ{I}V) … H) //
122 qed-.
123
124 lemma length_inv_pos_dx_ltail: ∀L,l. |L| = ⫯l →
125                                ∃∃I,K,V. |K| = l & L = ⓑ{I}V.K.
126 #Y #l #H elim (length_inv_pos_dx … H) -H #I #L #V #Hl #HLK destruct
127 elim (lpair_ltail L I V) /2 width=5 by ex2_3_intro/
128 qed-.
129
130 lemma length_inv_pos_sn_ltail: ∀L,l. ⫯l = |L| →
131                                ∃∃I,K,V. l = |K| & L = ⓑ{I}V.K.
132 #Y #l #H elim (length_inv_pos_sn … H) -H #I #L #V #Hl #HLK destruct
133 elim (lpair_ltail L I V) /2 width=5 by ex2_3_intro/
134 qed-.
135
136 (* Basic eliminators ********************************************************)
137
138 (* Basic_1: was: c_tail_ind *)
139 lemma lenv_ind_alt: ∀R:predicate lenv.
140                     R (⋆) → (∀I,L,T. R L → R (ⓑ{I}T.L)) →
141                     ∀L. R L.
142 #R #IH1 #IH2 #L @(ynat_f_ind … length … L) -L #x #IHx * // -IH1
143 #L #I #V #H destruct elim (lpair_ltail L I V)
144 /4 width=1 by monotonic_ylt_plus_sn/
145 qed-.