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/syntax/lenv_length.ma".
16 include "basic_2/syntax/lveq.ma".
18 (* EQUIVALENCE FOR LOCAL ENVIRONMENTS UP TO EXCLUSION BINDERS ***************)
20 lemma lveq_eq_ex: ∀L1,L2. |L1| = |L2| → ∃n. L1 ≋ⓧ*[n, n] L2.
22 [ #Y2 #H >(length_inv_zero_sn … H) -Y2 /2 width=3 by lveq_atom, ex_intro/
23 | #K1 * [ * | #I1 #V1 ] #IH #Y2 #H
24 elim (length_inv_succ_sn … H) -H * [1,3: * |*: #I2 #V2 ] #K2 #HK #H destruct
25 elim (IH … HK) -IH -HK #n #HK
26 /4 width=3 by lveq_pair_sn, lveq_pair_dx, lveq_void_sn, lveq_void_dx, ex_intro/
30 (* Forward lemmas with length for local environments ************************)
32 lemma lveq_fwd_length_le_sn: ∀L1,L2,n1,n2. L1 ≋ⓧ*[n1, n2] L2 → n1 ≤ |L1|.
33 #L1 #L2 #n1 #n2 #H elim H -L1 -L2 -n1 -n2 normalize
37 lemma lveq_fwd_length_le_dx: ∀L1,L2,n1,n2. L1 ≋ⓧ*[n1, n2] L2 → n2 ≤ |L2|.
38 #L1 #L2 #n1 #n2 #H elim H -L1 -L2 -n1 -n2 normalize
42 lemma lveq_fwd_length: ∀L1,L2,n1,n2. L1 ≋ⓧ*[n1, n2] L2 →
43 |L1| + n2 = |L2| + n1.
44 #L1 #L2 #n1 #n2 #H elim H -L1 -L2 -n1 -n2 normalize
45 /2 width=2 by injective_plus_r/
48 lemma lveq_fwd_length_eq: ∀L1,L2,n. L1 ≋ⓧ*[n, n] L2 → |L1| = |L2|.
49 /3 width=2 by lveq_fwd_length, injective_plus_l/ qed-.
51 lemma lveq_fwd_length_minus: ∀L1,L2,n1,n2. L1 ≋ⓧ*[n1, n2] L2 →
52 |L1| - n1 = |L2| - n2.
53 /3 width=3 by lveq_fwd_length, lveq_fwd_length_le_dx, lveq_fwd_length_le_sn, plus_to_minus_2/ qed-.
55 lemma lveq_inj_length: ∀L1,L2,n1,n2. L1 ≋ⓧ*[n1, n2] L2 →
56 |L1| = |L2| → n1 = n2.
57 #L1 #L2 #n1 #n2 #H #HL12
58 lapply (lveq_fwd_length … H) -H #H
59 /2 width=2 by injective_plus_l/
62 (* Inversion lemmas with length for local environments **********************)
64 lemma lveq_inv_void_dx_length: ∀L1,L2,n1,n2. L1 ≋ⓧ*[n1, n2] L2.ⓧ → |L1| ≤ |L2| →
65 ∃∃m2. L1 ≋ ⓧ*[n1, m2] L2 & n2 = ⫯m2 & n1 ≤ m2.
66 #L1 #L2 #n1 #n2 #H #HL12
67 lapply (lveq_fwd_length … H) normalize >plus_n_Sm #H0
68 lapply (plus2_inv_le_sn … H0 HL12) -H0 -HL12 #H0
69 elim (le_inv_S1 … H0) -H0 #m2 #Hm2 #H0 destruct
70 /3 width=4 by lveq_inv_void_dx, ex3_intro/