]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/freescale/theory.ma
3e108e7bebb4620ae15957f7cd2979aabf134516
[helm.git] / helm / software / matita / contribs / ng_assembly / freescale / theory.ma
1 (**************************************************************************)
2 (*       ___                                                                *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Cosimo Oliboni, oliboni@cs.unibo.it                   *)
19 (*     Cosimo Oliboni, oliboni@cs.unibo.it                                *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "freescale/pts.ma".
24
25 (* ********************************** *)
26 (* SOTTOINSIEME MINIMALE DELLA TEORIA *)
27 (* ********************************** *)
28
29 (* logic/connectives.ma *)
30
31 ninductive True: Prop ≝
32  I : True.
33
34 (*ndefinition True_ind_xx : ΠP:Prop.P → True → P ≝
35 λP:Prop.λp:P.λH:True.
36  match H with [ I ⇒ p ].
37
38 ndefinition True_rec_xx : ΠP:Set.P → True → P ≝
39 λP:Set.λp:P.λH:True.
40  match H with [ I ⇒ p ].
41
42 ndefinition True_rect_xx : ΠP:Type.P → True → P ≝
43 λP:Type.λp:P.λH:True.
44  match H with [ I ⇒ p ].*)
45
46 ninductive False: Prop ≝.
47
48 (*ndefinition False_ind_xx : ΠP:Prop.False → P ≝
49 λP:Prop.λH:False.
50  match H in False return λH1:False.P with [].
51
52 ndefinition False_rec_xx : ΠP:Set.False → P ≝
53 λP:Set.λH:False.
54  match H in False return λH1:False.P with [].
55
56 ndefinition False_rect_xx : ΠP:Type.False → P ≝
57 λP:Type.λH:False.
58  match H in False return λH1:False.P with [].*)
59
60 ndefinition Not: Prop → Prop ≝
61 λA.(A → False).
62
63 interpretation "logical not" 'not x = (Not x).
64
65 nlemma absurd : ∀A,C:Prop.A → ¬A → C.
66  #A; #C; #H;
67  nnormalize;
68  #H1;
69  nelim (H1 H);
70 nqed.
71
72 nlemma not_to_not : ∀A,B:Prop. (A → B) → ¬B →¬A.
73  #A; #B; #H;
74  nnormalize;
75  #H1; #H2;
76  nelim (H1 (H H2)).
77 nqed.
78
79 ninductive And (A,B:Prop) : Prop ≝
80  conj : A → B → (And A B).
81
82 (*ndefinition And_ind_xx : ΠA,B:Prop.ΠP:Prop.(A → B → P) → And A B → P ≝
83 λA,B:Prop.λP:Prop.λf:A → B → P.λH:And A B.
84  match H with [conj H1 H2 ⇒ f H1 H2 ].
85
86 ndefinition And_rec_xx : ΠA,B:Prop.ΠP:Set.(A → B → P) → And A B → P ≝
87 λA,B:Prop.λP:Set.λf:A → B → P.λH:And A B.
88  match H with [conj H1 H2 ⇒ f H1 H2 ].
89
90 ndefinition And_rect_xx : ΠA,B:Prop.ΠP:Type.(A → B → P) → And A B → P ≝
91 λA,B:Prop.λP:Type.λf:A → B → P.λH:And A B.
92  match H with [conj H1 H2 ⇒ f H1 H2 ].*)
93
94 interpretation "logical and" 'and x y = (And x y).
95
96 nlemma proj1: ∀A,B:Prop.A ∧ B → A.
97  #A; #B; #H;
98  napply (And_ind A B ?? H);
99  #H1; #H2;
100  napply H1.
101 nqed.
102
103 nlemma proj2: ∀A,B:Prop.A ∧ B → B.
104  #A; #B; #H;
105  napply (And_ind A B ?? H);
106  #H1; #H2;
107  napply H2.
108 nqed.
109
110 ninductive Or (A,B:Prop) : Prop ≝
111   or_introl : A → (Or A B)
112 | or_intror : B → (Or A B).
113
114 (*ndefinition Or_ind_xx : ΠA,B:Prop.ΠP:Prop.(A → P) → (B → P) → Or A B → P ≝
115 λA,B:Prop.λP:Prop.λf1:A → P.λf2:B → P.λH:Or A B.
116  match H with [ or_introl H1 ⇒ f1 H1 | or_intror H1 ⇒ f2 H1 ].*)
117
118 interpretation "logical or" 'or x y = (Or x y).
119
120 ndefinition decidable : Prop → Prop ≝ λA:Prop.A ∨ ¬A.
121
122 ninductive ex (A:Type) (Q:A → Prop) : Prop ≝
123  ex_intro: ∀x:A.Q x → ex A Q.
124
125 (*ndefinition ex_ind_xx : ΠA:Type.ΠQ:A → Prop.ΠP:Prop.(Πa:A.Q a → P) → ex A Q → P ≝
126 λA:Type.λQ:A → Prop.λP:Prop.λf:(Πa:A.Q a → P).λH:ex A Q.
127  match H with [ ex_intro H1 H2 ⇒ f H1 H2 ].*)
128
129 interpretation "exists" 'exists x = (ex ? x).
130
131 ninductive ex2 (A:Type) (Q,R:A → Prop) : Prop ≝
132  ex_intro2: ∀x:A.Q x → R x → ex2 A Q R.
133
134 (*ndefinition ex2_ind_xx : ΠA:Type.ΠQ,R:A → Prop.ΠP:Prop.(Πa:A.Q a → R a → P) → ex2 A Q R → P ≝
135 λA:Type.λQ,R:A → Prop.λP:Prop.λf:(Πa:A.Q a → R a → P).λH:ex2 A Q R.
136  match H with [ ex_intro2 H1 H2 H3 ⇒ f H1 H2 H3 ].*)
137
138 ndefinition iff ≝
139 λA,B.(A -> B) ∧ (B -> A).
140
141 (* higher_order_defs/relations *)
142
143 ndefinition relation : Type → Type ≝
144 λA:Type.A → A → Prop. 
145
146 ndefinition reflexive : ∀A:Type.∀R:relation A.Prop ≝
147 λA.λR.∀x:A.R x x.
148
149 ndefinition symmetric : ∀A:Type.∀R:relation A.Prop ≝
150 λA.λR.∀x,y:A.R x y → R y x.
151
152 ndefinition transitive : ∀A:Type.∀R:relation A.Prop ≝
153 λA.λR.∀x,y,z:A.R x y → R y z → R x z.
154
155 ndefinition irreflexive : ∀A:Type.∀R:relation A.Prop ≝
156 λA.λR.∀x:A.¬ (R x x).
157
158 ndefinition cotransitive : ∀A:Type.∀R:relation A.Prop ≝
159 λA.λR.∀x,y:A.R x y → ∀z:A. R x z ∨ R z y.
160
161 ndefinition tight_apart : ∀A:Type.∀eq,ap:relation A.Prop ≝
162 λA.λeq,ap.∀x,y:A. (¬ (ap x y) → eq x y) ∧ (eq x y → ¬ (ap x y)).
163
164 ndefinition antisymmetric : ∀A:Type.∀R:relation A.Prop ≝
165 λA.λR.∀x,y:A.R x y → ¬ (R y x).
166
167 (* logic/equality.ma *)
168
169 ninductive eq (A:Type) (x:A) : A → Prop ≝
170  refl_eq : eq A x x.
171
172 (*ndefinition eq_ind_xx : ΠA:Type.Πx:A.ΠP:A → Prop.P x → Πa:A.eq A x a → P a ≝
173 λA:Type.λx:A.λP:A → Prop.λp:P x.λa:A.λH:eq A x a.
174  match H with [refl_eq ⇒ p ].
175
176 ndefinition eq_rec_xx : ΠA:Type.Πx:A.ΠP:A → Set.P x → Πa:A.eq A x a → P a ≝
177 λA:Type.λx:A.λP:A → Set.λp:P x.λa:A.λH:eq A x a.
178  match H with [refl_eq ⇒ p ].
179
180 ndefinition eq_rect_xx : ΠA:Type.Πx:A.ΠP:A → Type.P x → Πa:A.eq A x a → P a ≝
181 λA:Type.λx:A.λP:A → Type.λp:P x.λa:A.λH:eq A x a.
182  match H with [refl_eq ⇒ p ].*)
183
184 interpretation "leibnitz's equality" 'eq t x y = (eq t x y).
185
186 interpretation "leibnitz's non-equality" 'neq t x y = (Not (eq t x y)).
187
188 nlemma symmetric_eq: ∀A:Type. symmetric A (eq A).
189  #A;
190  nnormalize;
191  #x; #y; #H;
192  nrewrite < H;
193  napply (refl_eq ??).
194 nqed.
195
196 nlemma eq_elim_r: ∀A:Type.∀x:A.∀P:A → Prop.P x → ∀y:A.y=x → P y.
197  #A; #x; #P; #H; #y; #H1;
198  nletin H2 ≝ (symmetric_eq ??? H1);
199  nrewrite < H2;
200  nassumption.
201 nqed.
202
203 ndefinition relationT : Type → Type → Type ≝
204 λA,T:Type.A → A → T.
205
206 ndefinition symmetricT: ∀A,T:Type.∀R:relationT A T.Prop ≝
207 λA,T.λR.∀x,y:A.R x y = R y x.
208
209 ndefinition associative : ∀A:Type.∀R:relationT A A.Prop ≝
210 λA.λR.∀x,y,z:A.R (R x y) z = R x (R y z).
211
212 (* list/list.ma *)
213
214 ninductive list (A:Type) : Type ≝
215   nil: list A
216 | cons: A -> list A -> list A.
217
218 nlet rec append A (l1: list A) l2 on l1 ≝
219  match l1 with
220   [ nil => l2
221   | (cons hd tl) => cons A hd (append A tl l2) ].
222
223 notation "hvbox(hd break :: tl)"
224   right associative with precedence 47
225   for @{'cons $hd $tl}.
226
227 notation "[ list0 x sep ; ]"
228   non associative with precedence 90
229   for ${fold right @'nil rec acc @{'cons $x $acc}}.
230
231 notation "hvbox(l1 break @ l2)"
232   right associative with precedence 47
233   for @{'append $l1 $l2 }.
234
235 interpretation "nil" 'nil = (nil ?).
236 interpretation "cons" 'cons hd tl = (cons ? hd tl).
237 interpretation "append" 'append l1 l2 = (append ? l1 l2).
238
239 nlemma list_destruct_1 : ∀T.∀x1,x2:T.∀y1,y2:list T.cons T x1 y1 = cons T x2 y2 → x1 = x2.
240  #T; #x1; #x2; #y1; #y2; #H;
241  nchange with (match cons T x2 y2 with [ nil ⇒ False | cons a _ ⇒ x1 = a ]);
242  nrewrite < H;
243  nnormalize;
244  napply (refl_eq ??).
245 nqed.
246
247 nlemma list_destruct_2 : ∀T.∀x1,x2:T.∀y1,y2:list T.cons T x1 y1 = cons T x2 y2 → y1 = y2.
248  #T; #x1; #x2; #y1; #y2; #H;
249  nchange with (match cons T x2 y2 with [ nil ⇒ False | cons _ b ⇒ y1 = b ]);
250  nrewrite < H;
251  nnormalize;
252  napply (refl_eq ??).
253 nqed.
254
255 nlemma list_destruct_cons_nil : ∀T.∀x:T.∀y:list T.cons T x y = nil T → False.
256  #T; #x; #y; #H;
257  nchange with (match cons T x y with [ nil ⇒ True | cons a b ⇒ False ]);
258  nrewrite > H;
259  nnormalize;
260  napply I.
261 nqed.
262
263 nlemma list_destruct_nil_cons : ∀T.∀x:T.∀y:list T.nil T = cons T x y → False.
264  #T; #x; #y; #H;
265  nchange with (match cons T x y with [ nil ⇒ True | cons a b ⇒ False ]);
266  nrewrite < H;
267  nnormalize;
268  napply I.
269 nqed.
270
271 nlemma append_nil : ∀T:Type.∀l:list T.(l@[]) = l.
272  #T; #l;
273  napply (list_ind T ??? l);
274  nnormalize;
275  ##[ ##1: napply (refl_eq ??)
276  ##| ##2: #x; #y; #H;
277           nrewrite > H;
278           napply (refl_eq ??)
279  ##]
280 nqed.
281
282 nlemma associative_list : ∀T.associative (list T) (append T).
283  #T; #x; #y; #z;
284  napply (list_ind T ??? x);
285  nnormalize;
286  ##[ ##1: napply (refl_eq ??)
287  ##| ##2: #a; #b; #H;
288           nrewrite > H;
289           napply (refl_eq ??)
290  ##]
291 nqed.
292
293 nlemma cons_append_commute : ∀T:Type.∀l1,l2:list T.∀a:T.a :: (l1 @ l2) = (a :: l1) @ l2.
294  #T; #l1; #l2; #a;
295  nnormalize;
296  napply (refl_eq ??).
297 nqed.
298
299 nlemma append_cons_commute : ∀T:Type.∀a:T.∀l,l1:list T.l @ (a::l1) = (l@[a]) @ l1.
300  #T; #a; #l; #l1;
301  nrewrite > (associative_list T l [a] l1);
302  nnormalize;
303  napply (refl_eq ??).
304 nqed.