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