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_2/ynat/ynat_lt.ma".
16 include "basic_2/notation/relations/coeq_4.ma".
17 include "basic_2/grammar/lenv_length.ma".
19 (* COEQUIVALENCE FOR LOCAL ENVIRONMENTS *************************************)
21 inductive lcoeq: relation4 ynat ynat lenv lenv ≝
22 | lcoeq_atom: ∀d,e. lcoeq d e (⋆) (⋆)
23 | lcoeq_zero: ∀I,L1,L2,V.
24 lcoeq 0 0 L1 L2 → lcoeq 0 0 (L1.ⓑ{I}V) (L2.ⓑ{I}V)
25 | lcoeq_pair: ∀I1,I2,L1,L2,V1,V2,e. lcoeq 0 e L1 L2 →
26 lcoeq 0 (⫯e) (L1.ⓑ{I1}V1) (L2.ⓑ{I2}V2)
27 | lcoeq_succ: ∀I,L1,L2,V,d,e.
28 lcoeq d e L1 L2 → lcoeq (⫯d) e (L1.ⓑ{I}V) (L2.ⓑ{I}V)
32 "coequivalence (local environment)"
33 'CoEq d e L1 L2 = (lcoeq d e L1 L2).
35 (* Basic properties *********************************************************)
37 lemma lcoeq_pair_lt: ∀I1,I2,L1,L2,V1,V2,e. L1 ≅[0, ⫰e] L2 → 0 < e →
38 L1.ⓑ{I1}V1 ≅[0, e] L2.ⓑ{I2}V2.
39 #I1 #I2 #L1 #L2 #V1 #V2 #e #HL12 #He <(ylt_inv_O1 … He) /2 width=1 by lcoeq_pair/
42 lemma lcoeq_succ_lt: ∀I,L1,L2,V,d,e. L1 ≅[⫰d, e] L2 → 0 < d →
43 L1.ⓑ{I}V ≅[d, e] L2. ⓑ{I}V.
44 #I #L1 #L2 #V #d #e #HL12 #Hd <(ylt_inv_O1 … Hd) /2 width=1 by lcoeq_succ/
47 lemma lcoeq_pair_O_Y: ∀L1,L2. L1 ≅[0, ∞] L2 →
48 ∀I1,I2,V1,V2. L1.ⓑ{I1}V1 ≅[0,∞] L2.ⓑ{I2}V2.
49 #L1 #L2 #HL12 #I1 #I2 #V1 #V2 lapply (lcoeq_pair I1 I2 … V1 V2 … HL12) -HL12 //
52 lemma lcoeq_refl: ∀L,d,e. L ≅[d, e] L.
54 #L #I #V #IHL #d elim (ynat_cases … d) [| * #x ]
55 #Hd destruct /2 width=1 by lcoeq_succ/
56 #e elim (ynat_cases … e) [| * #x ]
57 #He destruct /2 width=1 by lcoeq_zero, lcoeq_pair/
60 lemma lcoeq_O_Y: ∀L1,L2. |L1| = |L2| → L1 ≅[0, ∞] L2.
61 #L1 elim L1 -L1 [| #L1 #I1 #V1 #IHL1 ]
62 * [2,4: #L2 #I2 #V1 ] normalize /3 width=2 by lcoeq_pair_O_Y/
63 <plus_n_Sm #H destruct
66 lemma lcoeq_sym: ∀d,e. symmetric … (lcoeq d e).
67 #d #e #L1 #L2 #H elim H -L1 -L2
68 /2 width=1 by lcoeq_zero, lcoeq_pair, lcoeq_succ/
71 (* Basic inversion lemmas ***************************************************)
73 fact lcoeq_inv_atom1_aux: ∀L1,L2,d,e. L1 ≅[d, e] L2 → L1 = ⋆ → L2 = ⋆.
74 #L1 #L2 #d #e * -L1 -L2 -d -e //
75 [ #I #L1 #L2 #V #_ #H destruct
76 | #I1 #I2 #L1 #L2 #V1 #V2 #e #_ #H destruct
77 | #I #L1 #L2 #V #d #e #_ #H destruct
81 lemma lcoeq_inv_atom1: ∀L2,d,e. ⋆ ≅[d, e] L2 → L2 = ⋆.
82 /2 width=5 by lcoeq_inv_atom1_aux/ qed-.
84 fact lcoeq_inv_zero1_aux: ∀L1,L2,d,e. L1 ≅[d, e] L2 →
85 ∀J,K1,W. L1 = K1.ⓑ{J}W → d = 0 → e = 0 →
86 ∃∃K2. K1 ≅[0, 0] K2 & L2 = K2.ⓑ{J}W.
87 #L1 #L2 #d #e * -L1 -L2 -d -e
88 [ #d #e #J #K1 #W #H destruct
89 | #I #L1 #L2 #V #HL12 #J #K1 #W #H destruct /2 width=3 by ex2_intro/
90 | #I1 #I2 #L1 #L2 #V1 #V2 #e #_ #J #K1 #W #_ #_ #H elim (ysucc_inv_O_dx … H)
91 | #I #L1 #L2 #V #d #e #_ #J #K1 #W #_ #H elim (ysucc_inv_O_dx … H)
95 lemma lcoeq_inv_zero1: ∀I,K1,L2,V. K1.ⓑ{I}V ≅[0, 0] L2 →
96 ∃∃K2. K1 ≅[0, 0] K2 & L2 = K2.ⓑ{I}V.
97 /2 width=7 by lcoeq_inv_zero1_aux/ qed-.
99 fact lcoeq_inv_pair1_aux: ∀L1,L2,d,e. L1 ≅[d, e] L2 →
100 ∀J1,K1,W1. L1 = K1.ⓑ{J1}W1 → d = 0 → 0 < e →
101 ∃∃J2,K2,W2. K1 ≅[0, ⫰e] K2 & L2 = K2.ⓑ{J2}W2.
102 #L1 #L2 #d #e * -L1 -L2 -d -e
103 [ #d #e #J1 #K1 #W1 #H destruct
104 | #I #L1 #L2 #V #_ #J1 #K1 #W1 #_ #_ #H elim (ylt_yle_false … H) //
105 | #I1 #I2 #L1 #L2 #V1 #V2 #e #HL12 #J1 #K1 #W1 #H #_ #_ destruct
106 /2 width=5 by ex2_3_intro/
107 | #I #L1 #L2 #V #d #e #_ #J1 #K1 #W1 #_ #H elim (ysucc_inv_O_dx … H)
111 lemma lcoeq_inv_pair1: ∀I1,K1,L2,V1,e. K1.ⓑ{I1}V1 ≅[0, e] L2 → 0 < e →
112 ∃∃I2,K2,V2. K1 ≅[0, ⫰e] K2 & L2 = K2.ⓑ{I2}V2.
113 /2 width=7 by lcoeq_inv_pair1_aux/ qed-.
115 fact lcoeq_inv_succ1_aux: ∀L1,L2,d,e. L1 ≅[d, e] L2 →
116 ∀J,K1,W. L1 = K1.ⓑ{J}W → 0 < d →
117 ∃∃K2. K1 ≅[⫰d, e] K2 & L2 = K2.ⓑ{J}W.
118 #L1 #L2 #d #e * -L1 -L2 -d -e
119 [ #d #e #J #K1 #W #H destruct
120 | #I #L1 #L2 #V #_ #J #K1 #W #_ #H elim (ylt_yle_false … H) //
121 | #I1 #I2 #L1 #L2 #V1 #V2 #e #_ #J #K1 #W #_ #H elim (ylt_yle_false … H) //
122 | #I #L1 #L2 #V #d #e #HL12 #J #K1 #W #H destruct /2 width=3 by ex2_intro/
126 lemma lcoeq_inv_succ1: ∀I,K1,L2,V,d,e. K1.ⓑ{I}V ≅[d, e] L2 → 0 < d →
127 ∃∃K2. K1 ≅[⫰d, e] K2 & L2 = K2.ⓑ{I}V.
128 /2 width=3 by lcoeq_inv_succ1_aux/ qed-.
130 lemma lcoeq_inv_atom2: ∀L1,d,e. L1 ≅[d, e] ⋆ → L1 = ⋆.
131 /3 width=3 by lcoeq_inv_atom1, lcoeq_sym/ qed-.
133 lemma lcoeq_inv_zero2: ∀I,K2,L1,V. L1 ≅[0, 0] K2.ⓑ{I}V →
134 ∃∃K1. K1 ≅[0, 0] K2 & L1 = K1.ⓑ{I}V.
135 #I #K2 #L1 #V #H elim (lcoeq_inv_zero1 … (lcoeq_sym … H)) -H
136 /3 width=3 by lcoeq_sym, ex2_intro/
139 lemma lcoeq_inv_pair2: ∀I2,K2,L1,V2,e. L1 ≅[0, e] K2.ⓑ{I2}V2 → 0 < e →
140 ∃∃I1,K1,V1. K1 ≅[0, ⫰e] K2 & L1 = K1.ⓑ{I1}V1.
141 #I2 #K2 #L1 #V2 #e #H #He elim (lcoeq_inv_pair1 … (lcoeq_sym … H)) -H
142 /3 width=5 by lcoeq_sym, ex2_3_intro/
145 lemma lcoeq_inv_succ2: ∀I,K2,L1,V,d,e. L1 ≅[d, e] K2.ⓑ{I}V → 0 < d →
146 ∃∃K1. K1 ≅[⫰d, e] K2 & L1 = K1.ⓑ{I}V.
147 #I #K2 #L1 #V #d #e #H #Hd elim (lcoeq_inv_succ1 … (lcoeq_sym … H)) -H
148 /3 width=3 by lcoeq_sym, ex2_intro/
151 (* Basic forward lemmas *****************************************************)
153 lemma lcoeq_fwd_length: ∀L1,L2,d,e. L1 ≅[d, e] L2 → |L2| ≤ |L1|.
154 #L1 #L2 #d #e #H elim H -L1 -L2 -d -e normalize /2 width=1 by le_S_S/
157 (* Advanced inversionn lemmas ***********************************************)
159 fact lcoeq_inv_O2_aux: ∀L1,L2,d,e. L1 ≅[d, e] L2 → e = 0 → L1 = L2.
160 #L1 #L2 #d #e #H elim H -L1 -L2 -d -e /3 width=1 by eq_f3/
161 #I1 #I2 #L1 #L2 #V1 #V2 #e #_ #_ #H elim (ysucc_inv_O_dx … H)
164 lemma lcoeq_inv_O2: ∀L1,L2,d. L1 ≅[d, 0] L2 → L1 = L2.
165 /2 width=4 by lcoeq_inv_O2_aux/ qed-.