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/xoa/ex_3_2.ma".
16 include "static_2/notation/relations/stareq_3.ma".
17 include "static_2/syntax/term.ma".
19 (* GENERIC EQUIVALENCE ON TERMS *********************************************)
21 inductive teqg (S:relation …): relation term ≝
22 | teqg_sort: ∀s1,s2. S s1 s2 → teqg S (⋆s1) (⋆s2)
23 | teqg_lref: ∀i. teqg S (#i) (#i)
24 | teqg_gref: ∀l. teqg S (§l) (§l)
25 | teqg_pair: ∀I,V1,V2,T1,T2. teqg S V1 V2 → teqg S T1 T2 → teqg S (②[I]V1.T1) (②[I]V2.T2)
29 "context-free generic equivalence (term)"
30 'StarEq S T1 T2 = (teqg S T1 T2).
32 (* Basic properties *********************************************************)
35 reflexive … S → reflexive … (teqg S).
36 #S #HS #T elim T -T /2 width=1 by teqg_pair/
37 * /2 width=1 by teqg_sort, teqg_lref, teqg_gref/
41 symmetric … S → symmetric … (teqg S).
42 #S #HS #T1 #T2 #H elim H -T1 -T2
43 /3 width=3 by teqg_sort, teqg_lref, teqg_gref, teqg_pair/
46 alias symbol "subseteq" (instance 3) = "relation inclusion".
47 lemma teqg_co (S1) (S2):
49 ∀T1,T2. T1 ≛[S1] T2 → T1 ≛[S2] T2.
50 #S1 #S2 #HS #T1 #T2 #H elim H -T1 -T2
51 /3 width=1 by teqg_pair, teqg_sort/
54 (* Basic inversion lemmas ***************************************************)
56 fact teqg_inv_sort1_aux (S):
57 ∀X,Y. X ≛[S] Y → ∀s1. X = ⋆s1 →
58 ∃∃s2. S s1 s2 & Y = ⋆s2.
60 [ #s1 #s2 #Hs12 #s #H destruct /2 width=3 by ex2_intro/
63 | #I #V1 #V2 #T1 #T2 #_ #_ #s #H destruct
67 lemma teqg_inv_sort1 (S):
69 ∃∃s2. S s1 s2 & Y = ⋆s2.
70 /2 width=4 by teqg_inv_sort1_aux/ qed-.
72 fact teqg_inv_lref1_aux (S):
73 ∀X,Y. X ≛[S] Y → ∀i. X = #i → Y = #i.
75 [ #s1 #s2 #_ #j #H destruct
76 | #I #V1 #V2 #T1 #T2 #_ #_ #j #H destruct
80 lemma teqg_inv_lref1 (S):
81 ∀Y,i. #i ≛[S] Y → Y = #i.
82 /2 width=5 by teqg_inv_lref1_aux/ qed-.
84 fact teqg_inv_gref1_aux (S):
85 ∀X,Y. X ≛[S] Y → ∀l. X = §l → Y = §l.
87 [ #s1 #s2 #_ #k #H destruct
88 | #I #V1 #V2 #T1 #T2 #_ #_ #k #H destruct
92 lemma teqg_inv_gref1 (S):
93 ∀Y,l. §l ≛[S] Y → Y = §l.
94 /2 width=5 by teqg_inv_gref1_aux/ qed-.
96 fact teqg_inv_pair1_aux (S):
97 ∀X,Y. X ≛[S] Y → ∀I,V1,T1. X = ②[I]V1.T1 →
98 ∃∃V2,T2. V1 ≛[S] V2 & T1 ≛[S] T2 & Y = ②[I]V2.T2.
100 [ #s1 #s2 #_ #J #W1 #U1 #H destruct
101 | #i #J #W1 #U1 #H destruct
102 | #l #J #W1 #U1 #H destruct
103 | #I #V1 #V2 #T1 #T2 #HV #HT #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
107 lemma teqg_inv_pair1 (S):
108 ∀I,V1,T1,Y. ②[I]V1.T1 ≛[S] Y →
109 ∃∃V2,T2. V1 ≛[S] V2 & T1 ≛[S] T2 & Y = ②[I]V2.T2.
110 /2 width=3 by teqg_inv_pair1_aux/ qed-.
112 fact teqg_inv_sort2_aux (S):
113 ∀X,Y. X ≛[S] Y → ∀s2. Y = ⋆s2 →
114 ∃∃s1. S s1 s2 & X = ⋆s1.
116 [ #s1 #s2 #Hs12 #s #H destruct /2 width=3 by ex2_intro/
119 | #I #V1 #V2 #T1 #T2 #_ #_ #s #H destruct
123 lemma teqg_inv_sort2 (S):
124 ∀X1,s2. X1 ≛[S] ⋆s2 →
125 ∃∃s1. S s1 s2 & X1 = ⋆s1.
126 /2 width=3 by teqg_inv_sort2_aux/ qed-.
128 fact teqg_inv_pair2_aux (S):
129 ∀X,Y. X ≛[S] Y → ∀I,V2,T2. Y = ②[I]V2.T2 →
130 ∃∃V1,T1. V1 ≛[S] V2 & T1 ≛[S] T2 & X = ②[I]V1.T1.
132 [ #s1 #s2 #_ #J #W2 #U2 #H destruct
133 | #i #J #W2 #U2 #H destruct
134 | #l #J #W2 #U2 #H destruct
135 | #I #V1 #V2 #T1 #T2 #HV #HT #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
139 lemma teqg_inv_pair2 (S):
140 ∀I,X1,V2,T2. X1 ≛[S] ②[I]V2.T2 →
141 ∃∃V1,T1. V1 ≛[S] V2 & T1 ≛[S] T2 & X1 = ②[I]V1.T1.
142 /2 width=3 by teqg_inv_pair2_aux/ qed-.
144 (* Advanced inversion lemmas ************************************************)
146 lemma teqg_inv_pair (S):
147 ∀I1,I2,V1,V2,T1,T2. ②[I1]V1.T1 ≛[S] ②[I2]V2.T2 →
148 ∧∧ I1 = I2 & V1 ≛[S] V2 & T1 ≛[S] T2.
149 #S #I1 #I2 #V1 #V2 #T1 #T2 #H elim (teqg_inv_pair1 … H) -H
150 #V0 #T0 #HV #HT #H destruct /2 width=1 by and3_intro/
153 lemma teqg_inv_pair_xy_x (S):
154 ∀I,V,T. ②[I]V.T ≛[S] V → ⊥.
156 [ #J #T #H elim (teqg_inv_pair1 … H) -H #X #Y #_ #_ #H destruct
157 | #J #X #Y #IHX #_ #T #H elim (teqg_inv_pair … H) -H #H #HY #_ destruct /2 width=2 by/
161 lemma teqg_inv_pair_xy_y (S):
162 ∀I,T,V. ②[I]V.T ≛[S] T → ⊥.
164 [ #J #V #H elim (teqg_inv_pair1 … H) -H #X #Y #_ #_ #H destruct
165 | #J #X #Y #_ #IHY #V #H elim (teqg_inv_pair … H) -H #H #_ #HY destruct /2 width=2 by/
169 (* Basic forward lemmas *****************************************************)
171 lemma teqg_fwd_atom1 (S):
172 ∀I,Y. ⓪[I] ≛[S] Y → ∃J. Y = ⓪[J].
173 #S * #x #Y #H [ elim (teqg_inv_sort1 … H) -H ]
174 /3 width=4 by teqg_inv_gref1, teqg_inv_lref1, ex_intro/
177 (* Advanced properties ******************************************************)
180 (∀s1,s2. Decidable (S s1 s2)) →
181 ∀T1,T2. Decidable (T1 ≛[S] T2).
182 #S #HS #T1 elim T1 -T1 [ * #s1 | #I1 #V1 #T1 #IHV #IHT ] * [1,3,5,7: * #s2 |*: #I2 #V2 #T2 ]
183 [ elim (HS s1 s2) -HS [ /3 width=1 by or_introl, teqg_sort/ ] #HS
185 elim (teqg_inv_sort1 … H) -H #x #Hx #H destruct /2 width=1 by/
188 elim (teqg_inv_sort1 … H) -H #x #_ #H destruct
191 lapply (teqg_inv_lref1 … H) -H #H destruct
193 elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
195 lapply (teqg_inv_lref1 … H) -H #H destruct /2 width=1 by/
198 lapply (teqg_inv_gref1 … H) -H #H destruct
200 elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
202 lapply (teqg_inv_gref1 … H) -H #H destruct /2 width=1 by/
205 elim (teqg_inv_pair1 … H) -H #X1 #X2 #_ #_ #H destruct
207 elim (eq_item2_dec I1 I2) #HI12 destruct
208 [ elim (IHV V2) -IHV #HV12
209 elim (IHT T2) -IHT #HT12
210 [ /3 width=1 by teqg_pair, or_introl/ ]
213 elim (teqg_inv_pair … H) -H /2 width=1 by/
217 (* Negated inversion lemmas *************************************************)
219 lemma tneqg_inv_pair (S):
220 (∀s1,s2. Decidable (S s1 s2)) →
222 (②[I1]V1.T1 ≛[S] ②[I2]V2.T2 → ⊥) →
226 #S #HS #I1 #I2 #V1 #V2 #T1 #T2 #H12
227 elim (eq_item2_dec I1 I2) /3 width=1 by or3_intro0/ #H destruct
228 elim (teqg_dec S … V1 V2) /3 width=1 by or3_intro1/
229 elim (teqg_dec S … T1 T2) /4 width=1 by teqg_pair, or3_intro2/