]> matita.cs.unibo.it Git - helm.git/blob - matita/contribs/assembly/freescale/extra.ma
tagged 0.5.0-rc1
[helm.git] / 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 (* \ominus *)
58 notation "hvbox(⊖ a)" non associative with precedence 36
59  for @{ 'not_bool $a }.
60 interpretation "not_bool" 'not_bool x = 
61  (cic:/matita/freescale/extra/not_bool.con x).
62
63 (* \otimes *)
64 notation "hvbox(a break ⊗ b)" left associative with precedence 35
65  for @{ 'and_bool $a $b }.
66 interpretation "and_bool" 'and_bool x y = 
67  (cic:/matita/freescale/extra/and_bool.con x y).
68
69 (* \oplus *)
70 notation "hvbox(a break ⊕ b)" left associative with precedence 34
71  for @{ 'or_bool $a $b }.
72 interpretation "or_bool" 'or_bool x y = 
73  (cic:/matita/freescale/extra/or_bool.con x y).
74
75 (* \odot *)
76 notation "hvbox(a break ⊙ b)" left associative with precedence 33
77  for @{ 'xor_bool $a $b }.
78 interpretation "xor_bool" 'xor_bool x y = 
79  (cic:/matita/freescale/extra/xor_bool.con x y).
80
81 (* ProdT e' gia' definito, aggiungo Prod3T e Prod4T e Prod5T *)
82
83 inductive Prod3T (T1:Type) (T2:Type) (T3:Type) : Type ≝
84 tripleT : T1 → T2 → T3 → Prod3T T1 T2 T3.
85
86 definition fst3T ≝
87 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT x _ _ ⇒ x ].
88
89 definition snd3T ≝
90 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT _ x _ ⇒ x ].
91
92 definition thd3T ≝
93 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT _ _ x ⇒ x ].
94
95 inductive Prod4T (T1:Type) (T2:Type) (T3:Type) (T4:Type) : Type ≝
96 quadrupleT : T1 → T2 → T3 → T4 → Prod4T T1 T2 T3 T4.
97
98 definition fst4T ≝
99 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT x _ _ _ ⇒ x ].
100
101 definition snd4T ≝
102 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ x _ _ ⇒ x ].
103
104 definition thd4T ≝
105 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ _ x _ ⇒ x ].
106
107 definition fth4T ≝
108 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ _ _ x ⇒ x ].
109
110 inductive Prod5T (T1:Type) (T2:Type) (T3:Type) (T4:Type) (T5:Type) : Type ≝
111 quintupleT : T1 → T2 → T3 → T4 → T5 → Prod5T T1 T2 T3 T4 T5.
112
113 definition fst5T ≝
114 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT x _ _ _ _ ⇒ x ].
115
116 definition snd5T ≝
117 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ x _ _ _ ⇒ x ].
118
119 definition thd5T ≝
120 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ x _ _ ⇒ x ].
121
122 definition frth5T ≝
123 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ _ x _ ⇒ x ].
124
125 definition ffth5T ≝
126 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ _ _ x ⇒ x ].
127
128 (* OPTIOTN MAP *)
129
130 (* option map = match ... with [ None ⇒ None ? | Some .. ⇒ .. ] *)
131 definition opt_map ≝
132 λT1,T2:Type.λt:option T1.λf:T1 → option T2.
133  match t with [ None ⇒ None ? | Some x ⇒ (f x) ].
134
135 (* ********************** *)
136 (* TEOREMI/LEMMMI/ASSIOMI *)
137 (* ********************** *)
138
139 axiom mod_plus: ∀a,b,m. (a + b) \mod m = (a \mod m + b \mod m) \mod m.
140 axiom mod_mod: ∀a,n,m. n∣m → a \mod n = a \mod n \mod m.
141 axiom eq_mod_times_n_m_m_O: ∀n,m. O < m → n * m \mod m = O.
142 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.
143 axiom eq_mod_times_times_mod: ∀a,b,n,m. m = a*n → (a*b) \mod m = a * (b \mod n).
144 axiom divides_to_eq_mod_mod_mod: ∀a,n,m. n∣m → a \mod m \mod n = a \mod n.
145 axiom le_to_le_plus_to_le : ∀a,b,c,d.b\leq d\rarr a+b\leq c+d\rarr a\leq c.
146 axiom or_lt_le : ∀n,m. n < m ∨ m ≤ n.
147
148 lemma le_to_lt: ∀n,m. n ≤ m → n < S m.
149  intros;
150  autobatch.
151 qed.
152
153 alias num (instance 0) = "natural number".
154 definition nat_of_bool ≝
155  λb:bool.match b return λ_.nat with [ true ⇒ 1 | false ⇒ 0 ].
156
157 theorem lt_trans: ∀x,y,z. x < y → y < z → x < z.
158  unfold lt;
159  intros;
160  autobatch.
161 qed.
162
163 lemma leq_m_n_to_eq_div_n_m_S: ∀n,m:nat. 0 < m → m ≤ n → ∃z. n/m = S z.
164  intros;
165  unfold div;
166  apply (ex_intro ? ? (div_aux (pred n) (n-m) (pred m)));
167  cut (∃w.m = S w);
168   [ elim Hcut;
169     rewrite > H2;
170     rewrite > H2 in H1;
171     clear Hcut; clear H2; clear H;
172     simplify;
173     unfold in ⊢ (? ? % ?);
174     cut (∃z.n = S z);
175      [ elim Hcut; clear Hcut;
176        rewrite > H in H1;
177        rewrite > H; clear m;
178        change in ⊢ (? ? % ?)  with
179         (match leb (S a1) a with
180          [ true ⇒ O
181          | false ⇒ S (div_aux a1 ((S a1) - S a) a)]);
182        cut (S a1 ≰ a);
183         [ apply (leb_elim (S a1) a);
184            [ intro;
185              elim (Hcut H2)
186            | intro;
187              simplify;
188              reflexivity
189            ]
190         | intro;
191           autobatch
192         ]
193      | elim H1; autobatch
194      ]
195   | autobatch
196   ].
197 qed.
198
199 axiom daemon: False.