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 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
18 (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Ultima modifica: 05/08/2009 *)
21 (* ********************************************************************** *)
23 include "common/string.ma".
24 include "common/ascii_lemmas2.ma".
25 include "common/ascii_lemmas3.ma".
26 include "common/ascii_lemmas4.ma".
27 include "common/ascii_lemmas5.ma".
28 include "common/list_utility_lemmas.ma".
30 (* ************************ *)
31 (* MANIPOLAZIONE DI STRINGA *)
32 (* ************************ *)
34 nlemma symmetric_eqstr : symmetricT (list ascii) bool eq_str.
36 napply (symmetric_bfoldrightlist2 ascii eq_ascii s1 s2 symmetric_eqascii).
39 nlemma eqstr_to_eq : ∀s,s'.eq_str s s' = true → s = s'.
41 napply (bfoldrightlist2_to_eq ascii eq_ascii s1 s2 eqascii_to_eq).
44 nlemma eq_to_eqstr : ∀s,s'.s = s' → eq_str s s' = true.
46 napply (eq_to_bfoldrightlist2 ascii eq_ascii s1 s2 eq_to_eqascii).
49 nlemma decidable_str : ∀x,y:list ascii.decidable (x = y).
50 napply (decidable_list ascii …);
51 napply decidable_ascii.
54 nlemma neqstr_to_neq : ∀s,s'.eq_str s s' = false → s ≠ s'.
56 napply (nbfoldrightlist2_to_neq ascii eq_ascii s1 s2 …);
57 napply neqascii_to_neq.
60 nlemma neq_to_neqstr : ∀s,s'.s ≠ s' → eq_str s s' = false.
62 napply (neq_to_nbfoldrightlist2 ascii eq_ascii s1 s2 …);
63 ##[ ##1: napply decidable_ascii
64 ##| ##2: napply neq_to_neqascii
72 nlemma strid_destruct_1 : ∀x1,x2,y1,y2.mk_strId x1 y1 = mk_strId x2 y2 → x1 = x2.
73 #x1; #x2; #y1; #y2; #H;
74 nchange with (match mk_strId x2 y2 with [ mk_strId a _ ⇒ x1 = a ]);
80 nlemma strid_destruct_2 : ∀x1,x2,y1,y2.mk_strId x1 y1 = mk_strId x2 y2 → y1 = y2.
81 #x1; #x2; #y1; #y2; #H;
82 nchange with (match mk_strId x2 y2 with [ mk_strId _ b ⇒ y1 = b ]);
88 nlemma symmetric_eqstrid : symmetricT strId bool eq_strId.
91 ((eq_str (str_elem si1) (str_elem si2))⊗(eq_nat (id_elem si1) (id_elem si2))) =
92 ((eq_str (str_elem si2) (str_elem si1))⊗(eq_nat (id_elem si2) (id_elem si1))));
93 nrewrite > (symmetric_eqstr (str_elem si1) (str_elem si2));
94 nrewrite > (symmetric_eqnat (id_elem si1) (id_elem si2));
98 nlemma eqstrid_to_eq : ∀s,s'.eq_strId s s' = true → s = s'.
104 nchange in H:(%) with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = true);
105 nrewrite > (eqstr_to_eq l1 l2 (andb_true_true_l … H));
106 nrewrite > (eqnat_to_eq n1 n2 (andb_true_true_r … H));
110 nlemma eq_to_eqstrid : ∀s,s'.s = s' → eq_strId s s' = true.
116 nchange with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = true);
117 nrewrite > (strid_destruct_1 … H);
118 nrewrite > (strid_destruct_2 … H);
119 nrewrite > (eq_to_eqstr l2 l2 (refl_eq …));
120 nrewrite > (eq_to_eqnat n2 n2 (refl_eq …));
125 nlemma decidable_strid_aux1 : ∀s1,n1,s2,n2.s1 ≠ s2 → (mk_strId s1 n1) ≠ (mk_strId s2 n2).
128 napply (H (strid_destruct_1 … H1)).
131 nlemma decidable_strid_aux2 : ∀s1,n1,s2,n2.n1 ≠ n2 → (mk_strId s1 n1) ≠ (mk_strId s2 n2).
134 napply (H (strid_destruct_2 … H1)).
137 nlemma decidable_strid : ∀x,y:strId.decidable (x = y).
138 #x; nelim x; #s1; #n1;
139 #y; nelim y; #s2; #n2;
141 napply (or2_elim (s1 = s2) (s1 ≠ s2) ? (decidable_str s1 s2) …);
142 ##[ ##2: #H; napply (or2_intro2 … (decidable_strid_aux1 … H))
143 ##| ##1: #H; napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_nat n1 n2) …);
144 ##[ ##2: #H1; napply (or2_intro2 … (decidable_strid_aux2 … H1))
145 ##| ##1: #H1; nrewrite > H; nrewrite > H1;
146 napply (or2_intro1 … (refl_eq ? (mk_strId s2 n2)))
151 nlemma neqstrid_to_neq : ∀sid1,sid2:strId.(eq_strId sid1 sid2 = false) → (sid1 ≠ sid2).
152 #sid1; nelim sid1; #s1; #n1;
153 #sid2; nelim sid2; #s2; #n2;
154 nchange with ((((eq_str s1 s2) ⊗ (eq_nat n1 n2)) = false) → ?);
156 napply (or2_elim ((eq_str s1 s2) = false) ((eq_nat n1 n2) = false) ? (andb_false … H) …);
157 ##[ ##1: #H1; napply (decidable_strid_aux1 … (neqstr_to_neq … H1))
158 ##| ##2: #H1; napply (decidable_strid_aux2 … (neqnat_to_neq … H1))
162 nlemma strid_destruct : ∀s1,s2,n1,n2.(mk_strId s1 n1) ≠ (mk_strId s2 n2) → s1 ≠ s2 ∨ n1 ≠ n2.
165 napply (or2_elim (s1 = s2) (s1 ≠ s2) ? (decidable_str s1 s2) …);
166 ##[ ##2: #H1; napply (or2_intro1 … H1)
167 ##| ##1: #H1; napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_nat n1 n2) …);
168 ##[ ##2: #H2; napply (or2_intro2 … H2)
169 ##| ##1: #H2; nrewrite > H1 in H:(%);
171 #H; nelim (H (refl_eq …))
176 nlemma neq_to_neqstrid : ∀sid1,sid2.sid1 ≠ sid2 → eq_strId sid1 sid2 = false.
177 #sid1; nelim sid1; #s1; #n1;
178 #sid2; nelim sid2; #s2; #n2;
179 #H; nchange with (((eq_str s1 s2) ⊗ (eq_nat n1 n2)) = false);
180 napply (or2_elim (s1 ≠ s2) (n1 ≠ n2) ? (strid_destruct … H) …);
181 ##[ ##1: #H1; nrewrite > (neq_to_neqstr … H1); nnormalize; napply refl_eq
182 ##| ##2: #H1; nrewrite > (neq_to_neqnat … H1);
183 nrewrite > (symmetric_andbool (eq_str s1 s2) false);
184 nnormalize; napply refl_eq