]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/assembly/string/string.ma
mod change (-x)
[helm.git] / helm / software / matita / contribs / assembly / string / string.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 (*                                                                        *)
17 (* Sviluppato da:                                                         *)
18 (*   Cosimo Oliboni, oliboni@cs.unibo.it                                  *)
19 (*                                                                        *)
20 (* ********************************************************************** *)
21
22 include "string/ascii_min.ma".
23 include "compiler/utility.ma".
24
25 (* ************************ *)
26 (* MANIPOLAZIONE DI STRINGA *)
27 (* ************************ *)
28
29 (* tipo pubblico *)
30 definition aux_str_type ≝ list ascii_min.
31
32 (* empty string *)
33 definition empty_str ≝ nil ascii_min.
34
35 (* is empty ? *)
36 definition isNull_str ≝
37 λstr:aux_str_type.match str with
38  [ nil ⇒ true | cons _ _ ⇒ false ].
39
40 (* strcmp *)
41 let rec eqStr_str (str,str':aux_str_type) ≝
42  match str with
43   [ nil ⇒ match str' with
44    [ nil => true
45    | cons _ _ => false ]
46   | cons h t ⇒ match str' with
47    [ nil ⇒ false
48    | cons h' t' ⇒ (eqAsciiMin h h')⊗(eqStr_str t t')
49    ]
50   ].
51
52 lemma eqex_switch : ∀e1,e2.eq_ex e1 e2 = eq_ex e2 e1.
53  intros;
54  elim e1;
55  elim e2;
56  reflexivity.
57 qed.
58
59 lemma eqb8_switch : ∀b1,b2.eq_b8 b1 b2 = eq_b8 b2 b1.
60  intros;
61  elim b1;
62  elim b2;
63  unfold eq_b8;
64  rewrite > eqex_switch in ⊢ (? ? % ?);
65  rewrite > eqex_switch in ⊢ (? ? (? ? %) ?);
66  reflexivity.
67 qed.
68
69 lemma eqasciimin_switch : ∀a1,a2.eqAsciiMin a1 a2 = eqAsciiMin a2 a1.
70  intros;
71  unfold eqAsciiMin;
72  rewrite > eqb8_switch in ⊢ (? ? % ?);
73  reflexivity.
74 qed.
75
76 lemma eq_to_eqstr : ∀s,s'.s = s' → eqStr_str s s' = true.
77  do 2 intro;
78  intro;
79  rewrite < H;
80  elim s;
81  [ 1: reflexivity
82  | 2: simplify;
83       rewrite > (eq_to_eqasciimin a a (refl_eq ??));
84       rewrite > H1;
85       reflexivity
86  ].
87 qed.
88
89 lemma eqstr_to_eq : ∀s,s'.eqStr_str s s' = true → s = s'.
90  intros 1;
91  elim s 0;
92  intros;
93  [ simplify in H:(%);
94    cases s' in H;
95    simplify;
96    intros;
97    [ reflexivity
98    | destruct H
99    ]
100  | elim s' in H1;
101    [ simplify in H1;
102      destruct H1
103    | simplify in H2;
104      lapply (andb_true_true ?? H2);
105      lapply (andb_true_true_r ?? H2);
106      rewrite > (H ? Hletin1);
107      rewrite > (eqasciimin_to_eq ?? Hletin);
108      reflexivity
109    ]
110  ].
111 qed.
112
113 (* strcat *)
114 definition strCat_str ≝
115 λstr,str':aux_str_type.str@str'.
116
117 (* strlen *)
118 definition strLen_str ≝ λstr:aux_str_type.len_list ? str.
119
120 (* ************ *)
121 (* STRINGA + ID *)
122 (* ************ *)
123
124 (* tipo pubblico *)
125 inductive aux_strId_type : Type ≝
126  STR_ID: aux_str_type → nat → aux_strId_type.
127
128 (* getter *)
129 definition get_name_strId ≝ λsid:aux_strId_type.match sid with [ STR_ID n _ ⇒ n ].
130 definition get_id_strId ≝ λsid:aux_strId_type.match sid with [ STR_ID _ d ⇒ d ].
131
132 (* confronto *)
133 definition eqStrId_str ≝
134 λsid,sid':aux_strId_type.(eqStr_str (get_name_strId sid) (get_name_strId sid'))⊗(eqb (get_id_strId sid) (get_id_strId sid')).
135
136 lemma eq_to_eqstrid : ∀s,s'.s = s' → eqStrId_str s s' = true.
137  intros 3;
138  rewrite < H;
139  elim s;
140  simplify;
141  rewrite > (eq_to_eqstr a a (refl_eq ??));
142  rewrite > (eq_to_eqb_true n n (refl_eq ??));
143  reflexivity.
144 qed.
145
146 lemma eqstrid_to_eq : ∀s,s'.eqStrId_str s s' = true → s = s'.
147  intros 2;
148  elim s 0;
149  elim s' 0;
150  intros 4;
151  simplify;
152  intro;
153  rewrite > (eqstr_to_eq a1 a (andb_true_true ?? H));
154  rewrite > (eqb_true_to_eq n1 n (andb_true_true_r ?? H));
155  reflexivity.
156 qed.