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 "basic_2/notation/relations/stareq_4.ma".
16 include "basic_2/syntax/item_sd.ma".
17 include "basic_2/syntax/term.ma".
19 (* DEGREE-BASED EQUIVALENCE ON TERMS ****************************************)
21 inductive tdeq (h) (o): relation term ≝
22 | tdeq_sort: ∀s1,s2,d. deg h o s1 d → deg h o s2 d → tdeq h o (⋆s1) (⋆s2)
23 | tdeq_lref: ∀i. tdeq h o (#i) (#i)
24 | tdeq_gref: ∀l. tdeq h o (§l) (§l)
25 | tdeq_pair: ∀I,V1,V2,T1,T2. tdeq h o V1 V2 → tdeq h o T1 T2 → tdeq h o (②{I}V1.T1) (②{I}V2.T2)
29 "context-free degree-based equivalence (term)"
30 'StarEq h o T1 T2 = (tdeq h o T1 T2).
32 (* Basic inversion lemmas ***************************************************)
34 fact tdeq_inv_sort1_aux: ∀h,o,X,Y. X ≛[h, o] Y → ∀s1. X = ⋆s1 →
35 ∃∃s2,d. deg h o s1 d & deg h o s2 d & Y = ⋆s2.
37 [ #s1 #s2 #d #Hs1 #Hs2 #s #H destruct /2 width=5 by ex3_2_intro/
40 | #I #V1 #V2 #T1 #T2 #_ #_ #s #H destruct
44 lemma tdeq_inv_sort1: ∀h,o,Y,s1. ⋆s1 ≛[h, o] Y →
45 ∃∃s2,d. deg h o s1 d & deg h o s2 d & Y = ⋆s2.
46 /2 width=3 by tdeq_inv_sort1_aux/ qed-.
48 fact tdeq_inv_lref1_aux: ∀h,o,X,Y. X ≛[h, o] Y → ∀i. X = #i → Y = #i.
49 #h #o #X #Y * -X -Y //
50 [ #s1 #s2 #d #_ #_ #j #H destruct
51 | #I #V1 #V2 #T1 #T2 #_ #_ #j #H destruct
55 lemma tdeq_inv_lref1: ∀h,o,Y,i. #i ≛[h, o] Y → Y = #i.
56 /2 width=5 by tdeq_inv_lref1_aux/ qed-.
58 fact tdeq_inv_gref1_aux: ∀h,o,X,Y. X ≛[h, o] Y → ∀l. X = §l → Y = §l.
59 #h #o #X #Y * -X -Y //
60 [ #s1 #s2 #d #_ #_ #k #H destruct
61 | #I #V1 #V2 #T1 #T2 #_ #_ #k #H destruct
65 lemma tdeq_inv_gref1: ∀h,o,Y,l. §l ≛[h, o] Y → Y = §l.
66 /2 width=5 by tdeq_inv_gref1_aux/ qed-.
68 fact tdeq_inv_pair1_aux: ∀h,o,X,Y. X ≛[h, o] Y → ∀I,V1,T1. X = ②{I}V1.T1 →
69 ∃∃V2,T2. V1 ≛[h, o] V2 & T1 ≛[h, o] T2 & Y = ②{I}V2.T2.
71 [ #s1 #s2 #d #_ #_ #J #W1 #U1 #H destruct
72 | #i #J #W1 #U1 #H destruct
73 | #l #J #W1 #U1 #H destruct
74 | #I #V1 #V2 #T1 #T2 #HV #HT #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
78 lemma tdeq_inv_pair1: ∀h,o,I,V1,T1,Y. ②{I}V1.T1 ≛[h, o] Y →
79 ∃∃V2,T2. V1 ≛[h, o] V2 & T1 ≛[h, o] T2 & Y = ②{I}V2.T2.
80 /2 width=3 by tdeq_inv_pair1_aux/ qed-.
82 (* Advanced inversion lemmas ************************************************)
84 lemma tdeq_inv_sort1_deg: ∀h,o,Y,s1. ⋆s1 ≛[h, o] Y → ∀d. deg h o s1 d →
85 ∃∃s2. deg h o s2 d & Y = ⋆s2.
86 #h #o #Y #s1 #H #d #Hs1 elim (tdeq_inv_sort1 … H) -H
87 #s2 #x #Hx <(deg_mono h o … Hx … Hs1) -s1 -d /2 width=3 by ex2_intro/
90 lemma tdeq_inv_sort_deg: ∀h,o,s1,s2. ⋆s1 ≛[h, o] ⋆s2 →
91 ∀d1,d2. deg h o s1 d1 → deg h o s2 d2 →
93 #h #o #s1 #y #H #d1 #d2 #Hs1 #Hy
94 elim (tdeq_inv_sort1_deg … H … Hs1) -s1 #s2 #Hs2 #H destruct
95 <(deg_mono h o … Hy … Hs2) -s2 -d1 //
98 lemma tdeq_inv_pair: ∀h,o,I1,I2,V1,V2,T1,T2. ②{I1}V1.T1 ≛[h, o] ②{I2}V2.T2 →
99 ∧∧ I1 = I2 & V1 ≛[h, o] V2 & T1 ≛[h, o] T2.
100 #h #o #I1 #I2 #V1 #V2 #T1 #T2 #H elim (tdeq_inv_pair1 … H) -H
101 #V0 #T0 #HV #HT #H destruct /2 width=1 by and3_intro/
104 lemma tdeq_inv_pair_xy_y: ∀h,o,I,T,V. ②{I}V.T ≛[h, o] T → ⊥.
105 #h #o #I #T elim T -T
106 [ #J #V #H elim (tdeq_inv_pair1 … H) -H #X #Y #_ #_ #H destruct
107 | #J #X #Y #_ #IHY #V #H elim (tdeq_inv_pair … H) -H #H #_ #HY destruct /2 width=2 by/
111 (* Basic forward lemmas *****************************************************)
113 lemma tdeq_fwd_atom1: ∀h,o,I,Y. ⓪{I} ≛[h, o] Y → ∃J. Y = ⓪{J}.
114 #h #o * #x #Y #H [ elim (tdeq_inv_sort1 … H) -H ]
115 /3 width=4 by tdeq_inv_gref1, tdeq_inv_lref1, ex_intro/
118 (* Basic properties *********************************************************)
120 lemma tdeq_refl: ∀h,o. reflexive … (tdeq h o).
121 #h #o #T elim T -T /2 width=1 by tdeq_pair/
122 * /2 width=1 by tdeq_lref, tdeq_gref/
123 #s elim (deg_total h o s) /2 width=3 by tdeq_sort/
126 lemma tdeq_sym: ∀h,o. symmetric … (tdeq h o).
127 #h #o #T1 #T2 #H elim H -T1 -T2
128 /2 width=3 by tdeq_sort, tdeq_lref, tdeq_gref, tdeq_pair/
131 lemma tdeq_dec: ∀h,o,T1,T2. Decidable (T1 ≛[h, o] T2).
132 #h #o #T1 elim T1 -T1 [ * #s1 | #I1 #V1 #T1 #IHV #IHT ] * [1,3,5,7: * #s2 |*: #I2 #V2 #T2 ]
133 [ elim (deg_total h o s1) #d1 #H1
134 elim (deg_total h o s2) #d2 #H2
135 elim (eq_nat_dec d1 d2) #Hd12 destruct /3 width=3 by tdeq_sort, or_introl/
137 lapply (tdeq_inv_sort_deg … H … H1 H2) -H -H1 -H2 /2 width=1 by/
140 elim (tdeq_inv_sort1 … H) -H #x1 #x2 #_ #_ #H destruct
143 lapply (tdeq_inv_lref1 … H) -H #H destruct
145 elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
147 lapply (tdeq_inv_lref1 … H) -H #H destruct /2 width=1 by/
150 lapply (tdeq_inv_gref1 … H) -H #H destruct
152 elim (eq_nat_dec s1 s2) #Hs12 destruct /2 width=1 by or_introl/
154 lapply (tdeq_inv_gref1 … H) -H #H destruct /2 width=1 by/
157 elim (tdeq_inv_pair1 … H) -H #X1 #X2 #_ #_ #H destruct
159 elim (eq_item2_dec I1 I2) #HI12 destruct
160 [ elim (IHV V2) -IHV #HV12
161 elim (IHT T2) -IHT #HT12
162 [ /3 width=1 by tdeq_pair, or_introl/ ]
165 elim (tdeq_inv_pair … H) -H /2 width=1 by/
169 (* Negated inversion lemmas *************************************************)
171 lemma tdneq_inv_pair: ∀h,o,I1,I2,V1,V2,T1,T2.
172 (②{I1}V1.T1 ≛[h, o] ②{I2}V2.T2 → ⊥) →
174 | (V1 ≛[h, o] V2 → ⊥)
175 | (T1 ≛[h, o] T2 → ⊥).
176 #h #o #I1 #I2 #V1 #V2 #T1 #T2 #H12
177 elim (eq_item2_dec I1 I2) /3 width=1 by or3_intro0/ #H destruct
178 elim (tdeq_dec h o V1 V2) /3 width=1 by or3_intro1/
179 elim (tdeq_dec h o T1 T2) /4 width=1 by tdeq_pair, or3_intro2/