]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/static_2/syntax/teqg.ma
46e9c67b6848850ec22fa52de166f06cfe4c8746
[helm.git] / matita / matita / contribs / lambdadelta / static_2 / syntax / teqg.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/xoa/ex_3_2.ma".
16 include "static_2/notation/relations/stareq_3.ma".
17 include "static_2/syntax/term.ma".
18
19 (* GENERIC EQUIVALENCE ON TERMS *********************************************)
20
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)
26 .
27
28 interpretation
29   "context-free generic equivalence (term)"
30   'StarEq S T1 T2 = (teqg S T1 T2).
31
32 (* Basic properties *********************************************************)
33
34 lemma teqg_refl (S):
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/
38 qed.
39
40 lemma teqg_sym (S):
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/
44 qed-.
45
46 alias symbol "subseteq" (instance 3) = "relation inclusion".
47 lemma teqg_co (S1) (S2):
48       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/
52 qed-.
53
54 (* Basic inversion lemmas ***************************************************)
55
56 fact teqg_inv_sort1_aux (S):
57      ∀X,Y. X ≛[S] Y → ∀s1. X = ⋆s1 →
58      ∃∃s2. S s1 s2 & Y = ⋆s2.
59 #S #X #Y * -X -Y
60 [ #s1 #s2 #Hs12 #s #H destruct /2 width=3 by ex2_intro/
61 | #i #s #H destruct
62 | #l #s #H destruct
63 | #I #V1 #V2 #T1 #T2 #_ #_ #s #H destruct
64 ]
65 qed-.
66
67 lemma teqg_inv_sort1 (S):
68       ∀Y,s1. ⋆s1 ≛[S] Y →
69       ∃∃s2. S s1 s2 & Y = ⋆s2.
70 /2 width=4 by teqg_inv_sort1_aux/ qed-.
71
72 fact teqg_inv_lref1_aux (S):
73      ∀X,Y. X ≛[S] Y → ∀i. X = #i → Y = #i.
74 #S #X #Y * -X -Y //
75 [ #s1 #s2 #_ #j #H destruct
76 | #I #V1 #V2 #T1 #T2 #_ #_ #j #H destruct
77 ]
78 qed-.
79
80 lemma teqg_inv_lref1 (S):
81       ∀Y,i. #i ≛[S] Y → Y = #i.
82 /2 width=5 by teqg_inv_lref1_aux/ qed-.
83
84 fact teqg_inv_gref1_aux (S):
85      ∀X,Y. X ≛[S] Y → ∀l. X = §l → Y = §l.
86 #S #X #Y * -X -Y //
87 [ #s1 #s2 #_ #k #H destruct
88 | #I #V1 #V2 #T1 #T2 #_ #_ #k #H destruct
89 ]
90 qed-.
91
92 lemma teqg_inv_gref1 (S):
93       ∀Y,l. §l ≛[S] Y → Y = §l.
94 /2 width=5 by teqg_inv_gref1_aux/ qed-.
95
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.
99 #S #X #Y * -X -Y
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/
104 ]
105 qed-.
106
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-.
111
112 fact teqg_inv_sort2_aux (S):
113      ∀X,Y. X ≛[S] Y → ∀s2. Y = ⋆s2 →
114      ∃∃s1. S s1 s2 & X = ⋆s1.
115 #S #X #Y * -X -Y
116 [ #s1 #s2 #Hs12 #s #H destruct /2 width=3 by ex2_intro/
117 | #i #s #H destruct
118 | #l #s #H destruct
119 | #I #V1 #V2 #T1 #T2 #_ #_ #s #H destruct
120 ]
121 qed-.
122
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-.
127
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.
131 #S #X #Y * -X -Y
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/
136 ]
137 qed-.
138
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-.
143
144 (* Advanced inversion lemmas ************************************************)
145
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/
151 qed-.
152
153 lemma teqg_inv_pair_xy_x (S):
154       ∀I,V,T. ②[I]V.T ≛[S] V → ⊥.
155 #S #I #V elim V -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/
158 ]
159 qed-.
160
161 lemma teqg_inv_pair_xy_y (S):
162       ∀I,T,V. ②[I]V.T ≛[S] T → ⊥.
163 #S #I #T elim T -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/
166 ]
167 qed-.
168
169 (* Basic forward lemmas *****************************************************)
170
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/
175 qed-.
176
177 (* Advanced properties ******************************************************)
178
179 lemma teqg_dec (S):
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
184   @or_intror #H
185   elim (teqg_inv_sort1 … H) -H #x #Hx #H destruct /2 width=1 by/
186 |2,3,13:
187   @or_intror #H
188   elim (teqg_inv_sort1 … H) -H #x #_ #H destruct
189 |4,6,14:
190   @or_intror #H
191   lapply (teqg_inv_lref1 … H) -H #H destruct
192 |5:
193   elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
194   @or_intror #H
195   lapply (teqg_inv_lref1 … H) -H #H destruct /2 width=1 by/
196 |7,8,15:
197   @or_intror #H
198   lapply (teqg_inv_gref1 … H) -H #H destruct
199 |9:
200   elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
201   @or_intror #H
202   lapply (teqg_inv_gref1 … H) -H #H destruct /2 width=1 by/
203 |10,11,12:
204   @or_intror #H
205   elim (teqg_inv_pair1 … H) -H #X1 #X2 #_ #_ #H destruct
206 |16:
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/ ]
211   ]
212   @or_intror #H
213   elim (teqg_inv_pair … H) -H /2 width=1 by/
214 ]
215 qed-.
216
217 (* Negated inversion lemmas *************************************************)
218
219 lemma tneqg_inv_pair (S):
220       (∀s1,s2. Decidable (S s1 s2)) →
221       ∀I1,I2,V1,V2,T1,T2.
222       (②[I1]V1.T1 ≛[S] ②[I2]V2.T2 → ⊥) →
223       ∨∨ I1 = I2 → ⊥
224        | (V1 ≛[S] V2 → ⊥)
225        | (T1 ≛[S] 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/
230 qed-.