]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/assembly/string/string.ma
- setters for data structures now support "commuting conversion"-like
[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 eq_to_eqstr : ∀s,s'.s = s' → eqStr_str s s' = true.
53  do 2 intro;
54  intro;
55  rewrite < H;
56  elim s;
57  [ 1: reflexivity
58  | 2: simplify;
59       rewrite > (eq_to_eqasciimin a a (refl_eq ??));
60       rewrite > H1;
61       reflexivity
62  ].
63 qed.
64
65 lemma eqstr_to_eq : ∀s,s'.eqStr_str s s' = true → s = s'.
66  intros 1;
67  elim s 0;
68  intros;
69  [ simplify in H:(%);
70    cases s' in H;
71    simplify;
72    intros;
73    [ reflexivity
74    | destruct H
75    ]
76  | elim s' in H1;
77    [ simplify in H1;
78      destruct H1
79    | simplify in H2;
80      lapply (andb_true_true ?? H2);
81      lapply (andb_true_true_r ?? H2);
82      rewrite > (H ? Hletin1);
83      rewrite > (eqasciimin_to_eq ?? Hletin);
84      reflexivity
85    ]
86  ].
87 qed.
88
89 (* strcat *)
90 definition strCat_str ≝
91 λstr,str':aux_str_type.str@str'.
92
93 (* strlen *)
94 definition strLen_str ≝ λstr:aux_str_type.len_list ? str.
95
96 (* ************ *)
97 (* STRINGA + ID *)
98 (* ************ *)
99
100 (* tipo pubblico *)
101 inductive aux_strId_type : Type ≝
102  STR_ID: aux_str_type → nat → aux_strId_type.
103
104 (* getter *)
105 definition get_name_strId ≝ λsid:aux_strId_type.match sid with [ STR_ID n _ ⇒ n ].
106 definition get_id_strId ≝ λsid:aux_strId_type.match sid with [ STR_ID _ d ⇒ d ].
107
108 (* confronto *)
109 definition eqStrId_str ≝
110 λsid,sid':aux_strId_type.(eqStr_str (get_name_strId sid) (get_name_strId sid'))⊗(eqb (get_id_strId sid) (get_id_strId sid')).
111
112 lemma eq_to_eqstrid : ∀s,s'.s = s' → eqStrId_str s s' = true.
113  intros 3;
114  rewrite < H;
115  elim s;
116  simplify;
117  rewrite > (eq_to_eqstr a a (refl_eq ??));
118  rewrite > (eq_to_eqb_true n n (refl_eq ??));
119  reflexivity.
120 qed.
121
122 lemma eqstrid_to_eq : ∀s,s'.eqStrId_str s s' = true → s = s'.
123  intros 2;
124  elim s 0;
125  elim s' 0;
126  intros 4;
127  simplify;
128  intro;
129  rewrite > (eqstr_to_eq a1 a (andb_true_true ?? H));
130  rewrite > (eqb_true_to_eq n1 n (andb_true_true_r ?? H));
131  reflexivity.
132 qed.