]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/utility/string_lemmas.ma
freescale porting, work in progress
[helm.git] / helm / software / matita / contribs / ng_assembly / utility / string_lemmas.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 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Cosimo Oliboni, oliboni@cs.unibo.it                   *)
19 (*     Cosimo Oliboni, oliboni@cs.unibo.it                                *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "utility/string.ma".
24 include "utility/ascii_lemmas2.ma".
25 include "freescale/nat_lemmas.ma".
26
27 (* ************************ *)
28 (* MANIPOLAZIONE DI STRINGA *)
29 (* ************************ *)
30
31 nlemma symmetric_eqstr : symmetricT aux_str_type bool eq_str.
32  #l1;
33  napply (list_ind ascii ??? l1);
34  ##[ ##1: #l2; ncases l2;
35           ##[ ##1: nnormalize; napply (refl_eq ??)
36           ##| ##2: #x; #y; nnormalize; napply (refl_eq ??)
37           ##]
38  ##| ##2: #x1; #x2; #H; #l2; ncases l2;
39           ##[ ##1: nnormalize; napply (refl_eq ??)
40           ##| ##2: #y1; #y2;
41                    nchange with (((eq_ascii x1 y1)⊗(eq_str x2 y2)) = ((eq_ascii y1 x1)⊗(eq_str y2 x2)));
42                    nrewrite > (symmetric_eqascii x1 y1);
43                    nrewrite > (H y2);
44                    napply (refl_eq ??)
45           ##]
46  ##]
47 nqed.
48
49 nlemma eqstr_to_eq : ∀s,s'.eq_str s s' = true → s = s'.
50  #l1;
51  napply (list_ind ascii ??? l1);
52  ##[ ##1: #l2; ncases l2;
53           ##[ ##1: nnormalize; #H; napply (refl_eq ??)
54           ##| ##2: #x1; #x2; nnormalize; #H; napply (bool_destruct ??? H)
55           ##]
56  ##| ##2: #x1; #x2; #H; #l2; ncases l2;
57           ##[ ##1: nnormalize; #H1; napply (bool_destruct ??? H1)
58           ##| ##2: #y1; #y2; #H1;
59                    nchange in H1:(%) with (((eq_ascii x1 y1)⊗(eq_str x2 y2)) = true);
60                    nrewrite > (eqascii_to_eq x1 y1 (andb_true_true_l ?? H1));
61                    nrewrite > (H y2 (andb_true_true_r ?? H1));
62                    napply (refl_eq ??)
63           ##]
64  ##]
65 nqed.
66
67 nlemma eq_to_eqstr : ∀s,s'.s = s' → eq_str s s' = true.
68  #l1;
69  napply (list_ind ascii ??? l1);
70  ##[ ##1: #l2; ncases l2;
71           ##[ ##1: nnormalize; #H; napply (refl_eq ??)
72           ##| ##2: #x1; #x2; nnormalize; #H; nelim (list_destruct_nil_cons ascii ?? H)
73           ##]
74  ##| ##2: #x1; #x2; #H; #l2; ncases l2;
75           ##[ ##1: #H; nelim (list_destruct_cons_nil ascii ?? H)
76           ##| ##2: #y1; #y2; #H1;
77                    nrewrite > (list_destruct_1 ascii ???? H1);
78                    nchange with (((eq_ascii y1 y1)⊗(eq_str x2 y2)) = true);
79                    nrewrite > (H y2 (list_destruct_2 ascii ???? H1));
80                    nrewrite > (eq_to_eqascii y1 y1 (refl_eq ??));
81                    nnormalize;
82                    napply (refl_eq ??)
83           ##]
84  ##]
85 nqed.
86
87 (* ************ *)
88 (* STRINGA + ID *)
89 (* ************ *)
90
91 nlemma strid_destruct_1 : ∀x1,x2,y1,y2.STR_ID x1 y1 = STR_ID x2 y2 → x1 = x2.
92  #x1; #x2; #y1; #y2; #H;
93  nchange with (match STR_ID x2 y2 with [ STR_ID a _ ⇒ x1 = a ]);
94  nrewrite < H;
95  nnormalize;
96  napply (refl_eq ??).
97 nqed.
98
99 nlemma strid_destruct_2 : ∀x1,x2,y1,y2.STR_ID x1 y1 = STR_ID x2 y2 → y1 = y2.
100  #x1; #x2; #y1; #y2; #H;
101  nchange with (match STR_ID x2 y2 with [ STR_ID _ b ⇒ y1 = b ]);
102  nrewrite < H;
103  nnormalize;
104  napply (refl_eq ??).
105 nqed.
106
107 nlemma symmetric_eqstrid : symmetricT aux_strId_type bool eq_strId.
108  #si1; #si2;
109  ncases si1;
110  #l1; #n1;
111  ncases si2;
112  #l2; #n2;
113  nchange with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = ((eq_str l2 l1)⊗(eq_nat n2 n1)));
114  nrewrite > (symmetric_eqstr l1 l2);
115  nrewrite > (symmetric_eqnat n1 n2);
116  napply (refl_eq ??).
117 nqed.
118
119 nlemma eqstrid_to_eq : ∀s,s'.eq_strId s s' = true → s = s'.
120   #si1; #si2;
121  ncases si1;
122  #l1; #n1;
123  ncases si2;
124  #l2; #n2; #H;
125  nchange in H:(%) with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = true);
126  nrewrite > (eqstr_to_eq l1 l2 (andb_true_true_l ?? H));
127  nrewrite > (eqnat_to_eq n1 n2 (andb_true_true_r ?? H));
128  napply (refl_eq ??).
129 nqed.
130
131 nlemma eq_to_eqstrid : ∀s,s'.s = s' → eq_strId s s' = true.
132   #si1; #si2;
133  ncases si1;
134  #l1; #n1;
135  ncases si2;
136  #l2; #n2; #H;
137  nchange with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = true);
138  nrewrite > (strid_destruct_1 ???? H);
139  nrewrite > (strid_destruct_2 ???? H);
140  nrewrite > (eq_to_eqstr l2 l2 (refl_eq ??));
141  nrewrite > (eq_to_eqnat n2 n2 (refl_eq ??));
142  nnormalize;
143  napply (refl_eq ??).
144 nqed.