1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* Questo materiale fa parte della tesi: *)
22 (* "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale" *)
24 (* data ultima modifica 15/11/2007 *)
25 (* ********************************************************************** *)
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".
35 (* ridefinizione degli operatori booleani, per evitare l'overloading di quelli normali *)
37 λb:bool.match b with [ true ⇒ false | false ⇒ true ].
40 λb1,b2:bool.match b1 with
41 [ true ⇒ b2 | false ⇒ false ].
44 λb1,b2:bool.match b1 with
45 [ true ⇒ true | false ⇒ b2 ].
48 λb1,b2:bool.match b1 with
53 λb1,b2:bool.match b1 with
55 | false ⇒ not_bool b2 ].
57 lemma eqbool_switch : ∀b1,b2.eq_bool b1 b2 = eq_bool b2 b1.
63 lemma andbool_switch : ∀b1,b2.and_bool b1 b2 = and_bool b2 b1.
69 lemma orbool_switch : ∀b1,b2.or_bool b1 b2 = or_bool b2 b1.
75 lemma xorbool_switch : ∀b1,b2.xor_bool b1 b2 = xor_bool b2 b1.
81 lemma eqbool_to_eq : ∀b1,b2:bool.(eq_bool b1 b2 = true) → (b1 = b2).
91 lemma eq_to_eqbool : ∀b1,b2.b1 = b2 → eq_bool b1 b2 = true.
102 notation "hvbox(⊖ a)" non associative with precedence 36
103 for @{ 'not_bool $a }.
104 interpretation "not_bool" 'not_bool x = (not_bool x).
107 notation "hvbox(a break ⊗ b)" left associative with precedence 35
108 for @{ 'and_bool $a $b }.
109 interpretation "and_bool" 'and_bool x y = (and_bool x y).
112 notation "hvbox(a break ⊕ b)" left associative with precedence 34
113 for @{ 'or_bool $a $b }.
114 interpretation "or_bool" 'or_bool x y = (or_bool x y).
117 notation "hvbox(a break ⊙ b)" left associative with precedence 33
118 for @{ 'xor_bool $a $b }.
119 interpretation "xor_bool" 'xor_bool x y = (xor_bool x y).
121 (* ProdT e' gia' definito, aggiungo Prod3T e Prod4T e Prod5T *)
123 inductive Prod3T (T1:Type) (T2:Type) (T3:Type) : Type ≝
124 tripleT : T1 → T2 → T3 → Prod3T T1 T2 T3.
127 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT x _ _ ⇒ x ].
130 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT _ x _ ⇒ x ].
133 λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ tripleT _ _ x ⇒ x ].
135 inductive Prod4T (T1:Type) (T2:Type) (T3:Type) (T4:Type) : Type ≝
136 quadrupleT : T1 → T2 → T3 → T4 → Prod4T T1 T2 T3 T4.
139 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT x _ _ _ ⇒ x ].
142 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ x _ _ ⇒ x ].
145 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ _ x _ ⇒ x ].
148 λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadrupleT _ _ _ x ⇒ x ].
150 inductive Prod5T (T1:Type) (T2:Type) (T3:Type) (T4:Type) (T5:Type) : Type ≝
151 quintupleT : T1 → T2 → T3 → T4 → T5 → Prod5T T1 T2 T3 T4 T5.
154 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT x _ _ _ _ ⇒ x ].
157 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ x _ _ _ ⇒ x ].
160 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ x _ _ ⇒ x ].
163 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ _ x _ ⇒ x ].
166 λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintupleT _ _ _ _ x ⇒ x ].
170 (* option map = match ... with [ None ⇒ None ? | Some .. ⇒ .. ] *)
172 λT1,T2:Type.λt:option T1.λf:T1 → option T2.
173 match t with [ None ⇒ None ? | Some x ⇒ (f x) ].
175 (* ********************** *)
176 (* TEOREMI/LEMMMI/ASSIOMI *)
177 (* ********************** *)
179 axiom mod_plus: ∀a,b,m. (a + b) \mod m = (a \mod m + b \mod m) \mod m.
180 axiom mod_mod: ∀a,n,m. n∣m → a \mod n = a \mod n \mod m.
181 axiom eq_mod_times_n_m_m_O: ∀n,m. O < m → n * m \mod m = O.
182 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.
183 axiom eq_mod_times_times_mod: ∀a,b,n,m. m = a*n → (a*b) \mod m = a * (b \mod n).
184 axiom divides_to_eq_mod_mod_mod: ∀a,n,m. n∣m → a \mod m \mod n = a \mod n.
185 axiom le_to_le_plus_to_le : ∀a,b,c,d.b\leq d\rarr a+b\leq c+d\rarr a\leq c.
186 axiom or_lt_le : ∀n,m. n < m ∨ m ≤ n.
188 lemma le_to_lt: ∀n,m. n ≤ m → n < S m.
193 alias num (instance 0) = "natural number".
194 definition nat_of_bool ≝
195 λb:bool.match b return λ_.nat with [ true ⇒ 1 | false ⇒ 0 ].
197 theorem lt_trans: ∀x,y,z. x < y → y < z → x < z.
203 lemma leq_m_n_to_eq_div_n_m_S: ∀n,m:nat. 0 < m → m ≤ n → ∃z. n/m = S z.
206 apply (ex_intro ? ? (div_aux (pred n) (n-m) (pred m)));
211 clear Hcut; clear H2; clear H;
213 unfold in ⊢ (? ? % ?);
215 [ elim Hcut; clear Hcut;
217 rewrite > H; clear m;
218 change in ⊢ (? ? % ?) with
219 (match leb (S a1) a with
221 | false ⇒ S (div_aux a1 ((S a1) - S a) a)]);
223 [ apply (leb_elim (S a1) a);