1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "ground/notation/functions/double_semicolon_2.ma".
16 include "basic_2A/notation/functions/snbind2_3.ma".
17 include "basic_2A/notation/functions/snabbr_2.ma".
18 include "basic_2A/notation/functions/snabst_2.ma".
19 include "basic_2A/grammar/lenv_length.ma".
21 (* LOCAL ENVIRONMENTS *******************************************************)
23 let rec append L K on K ≝ match K with
25 | LPair K I V ⇒ (append L K). ⓑ{I} V
29 "append (local environment)"
30 'DoubleSemicolon L1 L2 = (append L1 L2).
33 "local environment tail binding construction (binary)"
34 'SnBind2 I T L = (append (LPair LAtom I T) L).
37 "tail abbreviation (local environment)"
38 'SnAbbr T L = (append (LPair LAtom Abbr T) L).
41 "tail abstraction (local environment)"
42 'SnAbst L T = (append (LPair LAtom Abst T) L).
44 definition d_appendable_sn: predicate (lenv→relation term) ≝ λR.
45 ∀K,T1,T2. R K T1 T2 → ∀L. R (L ;; K) T1 T2.
47 (* Basic properties *********************************************************)
49 lemma append_atom_sn: ∀L. ⋆ ;; L = L.
50 #L elim L -L normalize //
53 lemma append_assoc: associative … append.
54 #L1 #L2 #L3 elim L3 -L3 normalize //
57 lemma append_length: ∀L1,L2. |L1 ;; L2| = |L1| + |L2|.
58 #L1 #L2 elim L2 -L2 normalize //
61 lemma ltail_length: ∀I,L,V. |ⓑ{I}V.L| = |L| + 1.
62 #I #L #V >append_length //
65 lemma lpair_ltail: ∀L,I,V. ∃∃J,K,W. L.ⓑ{I}V = ⓑ{J}W.K & |L| = |K|.
66 #L elim L -L /2 width=5 by ex2_3_intro/
67 #L #Z #X #IHL #I #V elim (IHL Z X) -IHL
68 #J #K #W #H #_ >H -H >ltail_length
69 @(ex2_3_intro … J (K.ⓑ{I}V) W) //
72 (* Basic inversion lemmas ***************************************************)
74 lemma append_inj_sn: ∀K1,K2,L1,L2. L1 ;; K1 = L2 ;; K2 → |K1| = |K2| →
77 [ * normalize /2 width=1 by conj/
78 #K2 #I2 #V2 #L1 #L2 #_ <plus_n_Sm #H destruct
79 | #K1 #I1 #V1 #IH * normalize
80 [ #L1 #L2 #_ <plus_n_Sm #H destruct
81 | #K2 #I2 #V2 #L1 #L2 #H1 #H2
82 elim (destruct_lpair_lpair_aux … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
83 elim (IH … H1) -IH -H1 /2 width=1 by conj/
89 lemma append_inj_dx: ∀K1,K2,L1,L2. L1 ;; K1 = L2 ;; K2 → |L1| = |L2| →
92 [ * normalize /2 width=1 by conj/
93 #K2 #I2 #V2 #L1 #L2 #H1 #H2 destruct
94 normalize in H2; >append_length in H2; #H
95 elim (plus_xySz_x_false … H)
96 | #K1 #I1 #V1 #IH * normalize
97 [ #L1 #L2 #H1 #H2 destruct
98 normalize in H2; >append_length in H2; #H
99 elim (plus_xySz_x_false … (sym_eq … H))
100 | #K2 #I2 #V2 #L1 #L2 #H1 #H2
101 elim (destruct_lpair_lpair_aux … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
102 elim (IH … H1) -IH -H1 /2 width=1 by conj/
107 lemma append_inv_refl_dx: ∀L,K. L ;; K = L → K = ⋆.
108 #L #K #H elim (append_inj_dx … (⋆) … H) //
111 lemma append_inv_pair_dx: ∀I,L,K,V. L ;; K = L.ⓑ{I}V → K = ⋆.ⓑ{I}V.
112 #I #L #K #V #H elim (append_inj_dx … (⋆.ⓑ{I}V) … H) //
115 lemma length_inv_pos_dx_ltail: ∀L,l. |L| = l + 1 →
116 ∃∃I,K,V. |K| = l & L = ⓑ{I}V.K.
117 #Y #l #H elim (length_inv_pos_dx … H) -H #I #L #V #Hl #HLK destruct
118 elim (lpair_ltail L I V) /2 width=5 by ex2_3_intro/
121 lemma length_inv_pos_sn_ltail: ∀L,l. l + 1 = |L| →
122 ∃∃I,K,V. l = |K| & L = ⓑ{I}V.K.
123 #Y #l #H elim (length_inv_pos_sn … H) -H #I #L #V #Hl #HLK destruct
124 elim (lpair_ltail L I V) /2 width=5 by ex2_3_intro/
127 (* Basic eliminators ********************************************************)
129 lemma lenv_ind_alt: ∀R:predicate lenv.
130 R (⋆) → (∀I,L,T. R L → R (ⓑ{I}T.L)) →
132 #R #IH1 #IH2 #L @(f_ind … length … L) -L #x #IHx * // -IH1
133 #L #I #V normalize #H destruct elim (lpair_ltail L I V) /3 width=1 by/