]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/assembly/freescale/extra.ma
Preparing for 0.5.9 release.
[helm.git] / helm / software / matita / contribs / assembly / freescale / extra.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:                                                         *)
19 (*   Cosimo Oliboni, oliboni@cs.unibo.it                                  *)
20 (*                                                                        *)
21 (* Questo materiale fa parte della tesi:                                  *)
22 (*   "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale"   *)
23 (*                                                                        *)
24 (*                    data ultima modifica 15/11/2007                     *)
25 (* ********************************************************************** *)
26
27 include "nat/div_and_mod.ma".
28 include "nat/primes.ma".
29 include "list/list.ma".
30 include "datatypes/constructors.ma".
31 include "logic/connectives.ma".
32
33 (* BOOLEANI *)
34
35 (* ridefinizione degli operatori booleani, per evitare l'overloading di quelli normali *)
36 definition not_bool ≝
37 λb:bool.match b with [ true ⇒ false | false ⇒ true ].
38
39 definition and_bool ≝
40 λb1,b2:bool.match b1 with
41  [ true ⇒ b2 | false ⇒ false ].
42
43 definition or_bool ≝
44 λb1,b2:bool.match b1 with
45  [ true ⇒ true | false ⇒ b2 ].
46
47 definition xor_bool ≝
48 λb1,b2:bool.match b1 with
49  [ true ⇒ not_bool b2
50  | false ⇒ b2 ].
51
52 definition eq_bool ≝
53 λb1,b2:bool.match b1 with
54  [ true ⇒ b2
55  | false ⇒ not_bool b2 ].
56
57 lemma eqbool_switch : ∀b1,b2.eq_bool b1 b2 = eq_bool b2 b1.
58  do 2 intro;
59  elim b1; elim b2;
60  reflexivity.
61 qed.
62
63 lemma andbool_switch : ∀b1,b2.and_bool b1 b2 = and_bool b2 b1.
64  do 2 intro;
65  elim b1; elim b2;
66  reflexivity.
67 qed.
68
69 lemma orbool_switch : ∀b1,b2.or_bool b1 b2 = or_bool b2 b1.
70  do 2 intro;
71  elim b1; elim b2;
72  reflexivity.
73 qed.
74
75 lemma xorbool_switch : ∀b1,b2.xor_bool b1 b2 = xor_bool b2 b1.
76  do 2 intro;
77  elim b1; elim b2;
78  reflexivity.
79 qed.
80
81
82 lemma orb_false_false :
83  ∀b1,b2:bool.((or_bool b1 b2) = false) → b1 = false.
84  intros 2;
85  elim b1 0;
86  elim b2;
87  simplify in H;
88  try destruct H;
89  reflexivity.
90 qed.
91
92 lemma orb_false_false_r :
93  ∀b1,b2:bool.((or_bool b1 b2) = false) → b2 = false.
94  intros 2;
95  elim b1 0;
96  elim b2;
97  simplify in H;
98  try destruct H;
99  reflexivity.
100 qed.
101
102 lemma eqbool_to_eq : ∀b1,b2:bool.(eq_bool b1 b2 = true) → (b1 = b2).
103  unfold eq_bool;
104  intros;
105  elim b1 in H:(%);
106  elim b2 in H:(%);
107  normalize in H:(%);
108  try reflexivity;
109  destruct H.
110 qed.
111
112 lemma eq_to_eqbool : ∀b1,b2.b1 = b2 → eq_bool b1 b2 = true.
113  do 2 intro;
114  elim b1 0;
115  elim b2 0;
116  intro;
117  normalize in H:(%);
118  try destruct H;
119  reflexivity.
120 qed.
121
122 (* \ominus *)
123 notation "hvbox(⊖ a)" non associative with precedence 36
124  for @{ 'not_bool $a }.
125 interpretation "not_bool" 'not_bool x = (not_bool x).
126
127 (* \otimes *)
128 notation "hvbox(a break ⊗ b)" left associative with precedence 35
129  for @{ 'and_bool $a $b }.
130 interpretation "and_bool" 'and_bool x y = (and_bool x y).
131
132 (* \oplus *)
133 notation "hvbox(a break ⊕ b)" left associative with precedence 34
134  for @{ 'or_bool $a $b }.
135 interpretation "or_bool" 'or_bool x y = (or_bool x y).
136
137 (* \odot *)
138 notation "hvbox(a break ⊙ b)" left associative with precedence 33
139  for @{ 'xor_bool $a $b }.
140 interpretation "xor_bool" 'xor_bool x y = (xor_bool x y).
141
142 (* ProdT e' gia' definito, aggiungo Prod3T e Prod4T e Prod5T *)
143
144 inductive Prod3T (T1:Type) (T2:Type) (T3:Type) : Type ≝
145 tripleT : T1 → T2 → T3 → Prod3T T1 T2 T3.
146
147 definition fst3T ≝
148 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT x _ _ ⇒ x ].
149
150 definition snd3T ≝
151 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT _ x _ ⇒ x ].
152
153 definition thd3T ≝
154 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT _ _ x ⇒ x ].
155
156 inductive Prod4T (T1:Type) (T2:Type) (T3:Type) (T4:Type) : Type ≝
157 quadrupleT : T1 → T2 → T3 → T4 → Prod4T T1 T2 T3 T4.
158
159 definition fst4T ≝
160 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT x _ _ _ ⇒ x ].
161
162 definition snd4T ≝
163 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ x _ _ ⇒ x ].
164
165 definition thd4T ≝
166 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ _ x _ ⇒ x ].
167
168 definition fth4T ≝
169 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ _ _ x ⇒ x ].
170
171 inductive Prod5T (T1:Type) (T2:Type) (T3:Type) (T4:Type) (T5:Type) : Type ≝
172 quintupleT : T1 → T2 → T3 → T4 → T5 → Prod5T T1 T2 T3 T4 T5.
173
174 definition fst5T ≝
175 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT x _ _ _ _ ⇒ x ].
176
177 definition snd5T ≝
178 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ x _ _ _ ⇒ x ].
179
180 definition thd5T ≝
181 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ x _ _ ⇒ x ].
182
183 definition frth5T ≝
184 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ _ x _ ⇒ x ].
185
186 definition ffth5T ≝
187 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ _ _ x ⇒ x ].
188
189 (* OPTIOTN MAP *)
190
191 (* option map = match ... with [ None ⇒ None ? | Some .. ⇒ .. ] *)
192 definition opt_map ≝
193 λT1,T2:Type.λt:option T1.λf:T1 → option T2.
194  match t with [ None ⇒ None ? | Some x ⇒ (f x) ].
195
196 (* ********************** *)
197 (* TEOREMI/LEMMMI/ASSIOMI *)
198 (* ********************** *)
199
200 axiom mod_plus: ∀a,b,m. (a + b) \mod m = (a \mod m + b \mod m) \mod m.
201 axiom mod_mod: ∀a,n,m. n∣m → a \mod n = a \mod n \mod m.
202 axiom eq_mod_times_n_m_m_O: ∀n,m. O < m → n * m \mod m = O.
203 axiom eq_mod_to_eq_plus_mod: ∀a,b,c,m. a \mod m = b \mod m → (a+c) \mod m = (b+c) \mod m.
204 axiom eq_mod_times_times_mod: ∀a,b,n,m. m = a*n → (a*b) \mod m = a * (b \mod n).
205 axiom divides_to_eq_mod_mod_mod: ∀a,n,m. n∣m → a \mod m \mod n = a \mod n.
206 axiom le_to_le_plus_to_le : ∀a,b,c,d.b\leq d\rarr a+b\leq c+d\rarr a\leq c.
207 axiom or_lt_le : ∀n,m. n < m ∨ m ≤ n.
208
209 lemma le_to_lt: ∀n,m. n ≤ m → n < S m.
210  intros;
211  unfold;autobatch.
212 qed.
213
214 alias num (instance 0) = "natural number".
215 definition nat_of_bool ≝
216  λb:bool.match b return λ_.nat with [ true ⇒ 1 | false ⇒ 0 ].
217
218 theorem lt_trans: ∀x,y,z. x < y → y < z → x < z.
219  unfold lt;
220  intros;
221  autobatch.
222 qed.
223
224 lemma leq_m_n_to_eq_div_n_m_S: ∀n,m:nat. 0 < m → m ≤ n → ∃z. n/m = S z.
225  intros;
226  unfold div;
227  apply (ex_intro ? ? (div_aux (pred n) (n-m) (pred m)));
228  cut (∃w.m = S w);
229   [ elim Hcut;
230     rewrite > H2;
231     rewrite > H2 in H1;
232     clear Hcut; clear H2; clear H;
233     simplify;
234     unfold in ⊢ (? ? % ?);
235     cut (∃z.n = S z);
236      [ elim Hcut; clear Hcut;
237        rewrite > H in H1;
238        rewrite > H; clear m;
239        change in ⊢ (? ? % ?)  with
240         (match leb (S a1) a with
241          [ true ⇒ O
242          | false ⇒ S (div_aux a1 ((S a1) - S a) a)]);
243        cut (S a1 ≰ a);
244         [ apply (leb_elim (S a1) a);
245            [ intro;
246              elim (Hcut H2)
247            | intro;
248              simplify;
249              reflexivity
250            ]
251         | intro;
252           autobatch
253         ]
254      | elim H1; autobatch
255      ]
256   | exists;[apply (pred m);]autobatch
257   ].
258 qed.
259
260 axiom daemon: False.