]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/static_2/syntax/tdeq.ma
milestone in basic_2
[helm.git] / matita / matita / contribs / lambdadelta / static_2 / syntax / tdeq.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 "static_2/notation/relations/stareq_2.ma".
16 include "static_2/syntax/term.ma".
17
18 (* SORT-IRRELEVANT EQUIVALENCE ON TERMS *************************************)
19
20 inductive tdeq: relation term ≝
21 | tdeq_sort: ∀s1,s2. tdeq (⋆s1) (⋆s2)
22 | tdeq_lref: ∀i. tdeq (#i) (#i)
23 | tdeq_gref: ∀l. tdeq (§l) (§l)
24 | tdeq_pair: ∀I,V1,V2,T1,T2. tdeq V1 V2 → tdeq T1 T2 → tdeq (②{I}V1.T1) (②{I}V2.T2)
25 .
26
27 interpretation
28    "context-free sort-irrelevant equivalence (term)"
29    'StarEq T1 T2 = (tdeq T1 T2).
30
31 (* Basic properties *********************************************************)
32
33 lemma tdeq_refl: reflexive … tdeq.
34 #T elim T -T /2 width=1 by tdeq_pair/
35 * /2 width=1 by tdeq_lref, tdeq_gref/
36 qed.
37
38 lemma tdeq_sym: symmetric … tdeq.
39 #T1 #T2 #H elim H -T1 -T2
40 /2 width=3 by tdeq_sort, tdeq_lref, tdeq_gref, tdeq_pair/
41 qed-.
42
43 (* Basic inversion lemmas ***************************************************)
44
45 fact tdeq_inv_sort1_aux: ∀X,Y. X ≛ Y → ∀s1. X = ⋆s1 →
46                          ∃s2. Y = ⋆s2.
47 #X #Y * -X -Y
48 [ #s1 #s2 #s #H destruct /2 width=2 by ex_intro/
49 | #i #s #H destruct
50 | #l #s #H destruct
51 | #I #V1 #V2 #T1 #T2 #_ #_ #s #H destruct
52 ]
53 qed-.
54
55 lemma tdeq_inv_sort1: ∀Y,s1. ⋆s1 ≛ Y →
56                       ∃s2. Y = ⋆s2.
57 /2 width=4 by tdeq_inv_sort1_aux/ qed-.
58
59 fact tdeq_inv_lref1_aux: ∀X,Y. X ≛ Y → ∀i. X = #i → Y = #i.
60 #X #Y * -X -Y //
61 [ #s1 #s2 #j #H destruct
62 | #I #V1 #V2 #T1 #T2 #_ #_ #j #H destruct
63 ]
64 qed-.
65
66 lemma tdeq_inv_lref1: ∀Y,i. #i ≛ Y → Y = #i.
67 /2 width=5 by tdeq_inv_lref1_aux/ qed-.
68
69 fact tdeq_inv_gref1_aux: ∀X,Y. X ≛ Y → ∀l. X = §l → Y = §l.
70 #X #Y * -X -Y //
71 [ #s1 #s2 #k #H destruct
72 | #I #V1 #V2 #T1 #T2 #_ #_ #k #H destruct
73 ]
74 qed-.
75
76 lemma tdeq_inv_gref1: ∀Y,l. §l ≛ Y → Y = §l.
77 /2 width=5 by tdeq_inv_gref1_aux/ qed-.
78
79 fact tdeq_inv_pair1_aux: ∀X,Y. X ≛ Y → ∀I,V1,T1. X = ②{I}V1.T1 →
80                          ∃∃V2,T2. V1 ≛ V2 & T1 ≛ T2 & Y = ②{I}V2.T2.
81 #X #Y * -X -Y
82 [ #s1 #s2 #J #W1 #U1 #H destruct
83 | #i #J #W1 #U1 #H destruct
84 | #l #J #W1 #U1 #H destruct
85 | #I #V1 #V2 #T1 #T2 #HV #HT #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
86 ]
87 qed-.
88
89 lemma tdeq_inv_pair1: ∀I,V1,T1,Y. ②{I}V1.T1 ≛ Y →
90                       ∃∃V2,T2. V1 ≛ V2 & T1 ≛ T2 & Y = ②{I}V2.T2.
91 /2 width=3 by tdeq_inv_pair1_aux/ qed-.
92
93 lemma tdeq_inv_sort2: ∀X1,s2. X1 ≛ ⋆s2 →
94                       ∃s1. X1 = ⋆s1.
95 #X1 #s2 #H
96 elim (tdeq_inv_sort1 X1 s2)
97 /2 width=2 by tdeq_sym, ex_intro/
98 qed-.
99
100 lemma tdeq_inv_pair2: ∀I,X1,V2,T2. X1 ≛ ②{I}V2.T2 →
101                       ∃∃V1,T1. V1 ≛ V2 & T1 ≛ T2 & X1 = ②{I}V1.T1.
102 #I #X1 #V2 #T2 #H
103 elim (tdeq_inv_pair1 I V2 T2 X1)
104 [ #V1 #T1 #HV #HT #H destruct ]
105 /3 width=5 by tdeq_sym, ex3_2_intro/
106 qed-.
107
108 (* Advanced inversion lemmas ************************************************)
109
110 lemma tdeq_inv_pair: ∀I1,I2,V1,V2,T1,T2. ②{I1}V1.T1 ≛ ②{I2}V2.T2 →
111                      ∧∧ I1 = I2 & V1 ≛ V2 & T1 ≛ T2.
112 #I1 #I2 #V1 #V2 #T1 #T2 #H elim (tdeq_inv_pair1 … H) -H
113 #V0 #T0 #HV #HT #H destruct /2 width=1 by and3_intro/
114 qed-.
115
116 lemma tdeq_inv_pair_xy_x: ∀I,V,T. ②{I}V.T ≛ V → ⊥.
117 #I #V elim V -V
118 [ #J #T #H elim (tdeq_inv_pair1 … H) -H #X #Y #_ #_ #H destruct
119 | #J #X #Y #IHX #_ #T #H elim (tdeq_inv_pair … H) -H #H #HY #_ destruct /2 width=2 by/
120 ]
121 qed-.
122
123 lemma tdeq_inv_pair_xy_y: ∀I,T,V. ②{I}V.T ≛ T → ⊥.
124 #I #T elim T -T
125 [ #J #V #H elim (tdeq_inv_pair1 … H) -H #X #Y #_ #_ #H destruct
126 | #J #X #Y #_ #IHY #V #H elim (tdeq_inv_pair … H) -H #H #_ #HY destruct /2 width=2 by/
127 ]
128 qed-.
129
130 (* Basic forward lemmas *****************************************************)
131
132 lemma tdeq_fwd_atom1: ∀I,Y. ⓪{I} ≛ Y → ∃J. Y = ⓪{J}.
133 * #x #Y #H [ elim (tdeq_inv_sort1 … H) -H ]
134 /3 width=4 by tdeq_inv_gref1, tdeq_inv_lref1, ex_intro/
135 qed-.
136
137 (* Advanced properties ******************************************************)
138
139 lemma tdeq_dec: ∀T1,T2. Decidable (T1 ≛ T2).
140 #T1 elim T1 -T1 [ * #s1 | #I1 #V1 #T1 #IHV #IHT ] * [1,3,5,7: * #s2 |*: #I2 #V2 #T2 ]
141 [ /3 width=1 by tdeq_sort, or_introl/
142 |2,3,13:
143   @or_intror #H
144   elim (tdeq_inv_sort1 … H) -H #x #H destruct
145 |4,6,14:
146   @or_intror #H
147   lapply (tdeq_inv_lref1 … H) -H #H destruct
148 |5:
149   elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
150   @or_intror #H
151   lapply (tdeq_inv_lref1 … H) -H #H destruct /2 width=1 by/
152 |7,8,15:
153   @or_intror #H
154   lapply (tdeq_inv_gref1 … H) -H #H destruct
155 |9:
156   elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
157   @or_intror #H
158   lapply (tdeq_inv_gref1 … H) -H #H destruct /2 width=1 by/
159 |10,11,12:
160   @or_intror #H
161   elim (tdeq_inv_pair1 … H) -H #X1 #X2 #_ #_ #H destruct
162 |16:
163   elim (eq_item2_dec I1 I2) #HI12 destruct
164   [ elim (IHV V2) -IHV #HV12
165     elim (IHT T2) -IHT #HT12
166     [ /3 width=1 by tdeq_pair, or_introl/ ]
167   ]
168   @or_intror #H
169   elim (tdeq_inv_pair … H) -H /2 width=1 by/
170 ]
171 qed-.
172
173 (* Negated inversion lemmas *************************************************)
174
175 lemma tdneq_inv_pair: ∀I1,I2,V1,V2,T1,T2.
176                       (②{I1}V1.T1 ≛ ②{I2}V2.T2 → ⊥) → 
177                       ∨∨ I1 = I2 → ⊥
178                       |  (V1 ≛ V2 → ⊥)
179                       |  (T1 ≛ T2 → ⊥).
180 #I1 #I2 #V1 #V2 #T1 #T2 #H12
181 elim (eq_item2_dec I1 I2) /3 width=1 by or3_intro0/ #H destruct
182 elim (tdeq_dec V1 V2) /3 width=1 by or3_intro1/
183 elim (tdeq_dec T1 T2) /4 width=1 by tdeq_pair, or3_intro2/
184 qed-.