]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/R/r.ma
demodulate takes an extra argument 'all', if present it attempts to solve
[helm.git] / helm / software / matita / library / R / r.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 include "logic/equality.ma".
16 include "logic/coimplication.ma".
17 include "logic/cprop_connectives.ma".
18 include "datatypes/constructors.ma".
19 include "nat/orders.ma".
20 include "Z/z.ma". 
21
22 axiom choose : ∀A:Type.∀P:A → Prop.(∃x.P x) → exP ? P.
23 alias symbol "plus" = "Disjoint union".
24 axiom decide : ∀A,B.A ∨ B → A + B.
25
26 axiom R : Type.
27
28 axiom R0 : R.
29 axiom R1 : R.
30
31 axiom Rplus : R → R → R.
32 axiom Rtimes : R → R → R.
33 axiom Ropp : R → R.
34 axiom Rinv : R → R.
35 axiom Rlt : R → R → Prop.
36 definition Rle : R → R → Prop ≝ λx,y:R.Rlt x y ∨ x = y.
37
38 interpretation "real numbers" 'R = R.
39
40 interpretation "real numbers plus" 'plus x y = (Rplus x y).
41 interpretation "real numbers times" 'times x y = (Rtimes x y).
42 interpretation "real numbers opposite" 'uminus x = (Ropp x).
43 interpretation "real numbers reciprocal" 'invert x = (Rinv x).
44 interpretation "real numbers less than" 'lt x y = (Rlt x y).
45 interpretation "real numbers less eq" 'leq x y = (Rle x y).
46
47 axiom not_eq_R0_R1 : ¬ R0 = R1.
48
49 (* commutative ring with unity *)
50
51 axiom sym_Rplus : ∀x,y:R. x + y = y + x.
52 axiom assoc_Rplus : ∀x,y,z:R.(x+y)+z = x+(y+z).
53 axiom Rplus_x_R0 : ∀x.x + R0 = x.
54 axiom Rplus_Ropp : ∀x.x + (-x) = R0.
55
56 axiom sym_Rtimes : ∀x,y:R. x * y = y * x.
57 axiom assoc_Rtimes : ∀x,y,z:R.(x*y)*z = x*(y*z).
58 axiom Rtimes_x_R1 : ∀x.x * R1 = x.
59 axiom distr_Rtimes_Rplus_l : ∀x,y,z:R.x*(y+z) = x*y + x*z.
60
61 lemma distr_Rtimes_Rplus_r : ∀x,y,z:R.(x+y)*z = x*z + y*z.
62 intros;autobatch paramodulation;
63 qed.
64
65 (* commutative field *)
66
67 axiom Rinv_Rtimes_l : ∀x. ¬ x = R0 → x * (Rinv x) = R1.
68
69 (* ordered commutative field *)
70
71 axiom irrefl_Rlt : ∀x:R.¬ x < x.
72 axiom asym_Rlt : ∀x,y:R. x < y → ¬ y < x.
73 axiom trans_Rlt : ∀x,y,z:R.x < y → y < z → x < z.
74 axiom trichotomy_Rlt : ∀x,y.x < y ∨ y < x ∨ x = y.
75
76 lemma trans_Rle : ∀x,y,z:R.x ≤ y → y ≤ z → x ≤ z.
77 intros;cases H
78 [cases H1
79  [left;autobatch
80  |rewrite < H3;assumption]
81 |rewrite > H2;assumption]
82 qed.
83
84 axiom Rlt_plus_l : ∀x,y,z:R.x < y → z + x < z + y.
85 axiom Rlt_times_l : ∀x,y,z:R.x < y → R0 < z → z*x < z*y.
86
87 (* FIXME: these should be lemmata *)
88 axiom Rle_plus_l : ∀x,y,z:R.x ≤ y → z + x ≤ z + y.
89 axiom Rle_times_l : ∀x,y,z:R.x ≤ y → R0 < z → z*x ≤ z*y.
90
91 lemma Rle_plus_r : ∀x,y,z:R.x ≤ y → x + z ≤ y + z.
92 intros;
93 rewrite > sym_Rplus;rewrite > sym_Rplus in ⊢ (??%);
94 autobatch;
95 qed.
96
97 lemma Rle_times_r : ∀x,y,z:R.x ≤ y → R0 < z → x*z ≤ y*z.
98 intros;
99 rewrite > sym_Rtimes;rewrite > sym_Rtimes in ⊢ (??%);
100 autobatch;
101 qed.
102
103 (* Dedekind-completeness *)
104
105 definition ub ≝ λS: R → Prop.λx:R.∀y.S y → y ≤ x.
106 definition lub ≝ λS: R → Prop.λx:R.ub S x ∧ ∀y. ub S y → x ≤ y. 
107
108 axiom R_dedekind : ∀S:R → Prop.(∃x.S x) → (∃x.ub S x) → ∃x.lub S x.
109
110 (* coercions *)
111
112 definition R_of_nat : nat → R ≝
113  λn.match n with
114  [ O ⇒ R0
115  | S p ⇒ let rec aux m ≝
116    match m with
117    [ O ⇒ R1
118    | S q ⇒ (aux q) + R1] in aux p].
119
120 definition R_of_Z ≝
121 λz.match z with
122 [ pos n ⇒ R_of_nat (S n)
123 | neg n ⇒ Ropp (R_of_nat (S n))
124 | OZ ⇒ R0 ].
125
126 (* FIXME!!! coercion clash! *)
127 coercion R_of_Z.
128
129 (*coercion R_of_nat.*)
130
131 (* archimedean property *)
132
133 axiom R_archimedean : ∀x,y:R.R0 < x → ∃n:nat.y < n*x.
134
135 (*definition Rminus : R → R → R ≝
136  λx,y.x + (-y).*)
137  
138 interpretation "real numbers minus" 'minus x y = (Rplus x (Ropp y)).
139 interpretation "real numbers divide" 'divide x y = (Rtimes x (Rinv y)).
140
141 (* basic properties *)
142
143 (* equality *)
144
145 (* 
146 lemma Rplus_eq_l : ∀x,y,z.x = y → z + x= z + y.
147 intros;autobatch;
148 qed.
149
150 lemma Rplus_eq_r Rtimes_eq_l Rtimes_eq_r analogamente *)
151
152 lemma eq_Rplus_l_to_r : ∀a,b,c:R.a+b=c → a = c-b.
153 intros;lapply (eq_f ? ? (λx:R.x-b) ? ? H);
154 rewrite > assoc_Rplus in Hletin;rewrite > Rplus_Ropp in Hletin;
155 rewrite > Rplus_x_R0 in Hletin;assumption;
156 qed.
157
158 lemma eq_Rplus_r_to_l : ∀a,b,c:R.a=b+c → a-c = b.
159 intros;symmetry;apply eq_Rplus_l_to_r;symmetry;assumption;
160 qed.
161
162 lemma eq_Rminus_l_to_r : ∀a,b,c:R.a-b=c → a = c+b.
163 intros;lapply (eq_f ? ? (λx:R.x+b) ? ? H);
164 rewrite > assoc_Rplus in Hletin;rewrite > sym_Rplus in Hletin:(??(??%)?);
165 rewrite > Rplus_Ropp in Hletin;rewrite > Rplus_x_R0 in Hletin;assumption;
166 qed.
167
168 lemma eq_Rminus_r_to_l : ∀a,b,c:R.a=b-c → a+c = b.
169 intros;symmetry;apply eq_Rminus_l_to_r;autobatch paramodulation;
170 qed.
171
172 lemma eq_Rtimes_l_to_r : ∀a,b,c:R.b ≠ R0 → a*b=c → a = c/b.
173 intros;lapply (eq_f ? ? (λx:R.x/b) ? ? H1);
174 rewrite > assoc_Rtimes in Hletin;rewrite > Rinv_Rtimes_l in Hletin
175 [rewrite > Rtimes_x_R1 in Hletin;assumption
176 |assumption]
177 qed.
178
179 lemma eq_Rtimes_r_to_l : ∀a,b,c:R.c ≠ R0 → a=b*c → a/c = b.
180 intros;symmetry;apply eq_Rtimes_l_to_r
181 [assumption
182 |symmetry;assumption]
183 qed.
184
185 lemma eq_Rdiv_l_to_r : ∀a,b,c:R.b ≠ R0 → a/b=c → a = c*b.
186 intros;lapply (eq_f ? ? (λx:R.x*b) ? ? H1);
187 rewrite > assoc_Rtimes in Hletin;rewrite > sym_Rtimes in Hletin:(??(??%)?);
188 rewrite > Rinv_Rtimes_l in Hletin
189 [rewrite > Rtimes_x_R1 in Hletin;assumption
190 |assumption]
191 qed.
192
193 lemma eq_Rdiv_r_to_l : ∀a,b,c:R.c ≠ R0 → a=b/c → a*c = b.
194 intros;symmetry;apply eq_Rdiv_l_to_r
195 [assumption
196 |symmetry;assumption]
197 qed.
198
199 (* lemma unique_Ropp : ∀x,y.x + y = R0 → y = -x.
200 intros;autobatch paramodulation;
201 qed. *)
202
203 lemma Rtimes_x_R0 : ∀x.x * R0 = R0.
204 intro;
205 rewrite < Rplus_x_R0 in ⊢ (? ? % ?);
206 rewrite < (Rplus_Ropp (x*R0)) in ⊢ (? ? (? ? %) %);
207 rewrite < assoc_Rplus;
208 apply eq_f2;autobatch paramodulation;
209 qed.
210
211 lemma eq_Rtimes_Ropp_R1_Ropp : ∀x.x*(-R1) = -x.
212 intro.
213 rewrite < Rplus_x_R0 in ⊢ (? ? % ?);
214 rewrite < Rplus_x_R0 in ⊢ (? ? ? %);
215 rewrite < (Rplus_Ropp x) in ⊢ (? ? % ?);
216 rewrite < assoc_Rplus;
217 rewrite < sym_Rplus in ⊢ (? ? % ?);
218 rewrite < sym_Rplus in ⊢ (? ? (? ? %) ?);
219 apply eq_f2 [reflexivity]
220 rewrite < Rtimes_x_R1 in ⊢ (? ? (? % ?) ?);
221 rewrite < distr_Rtimes_Rplus_l;autobatch paramodulation;
222 qed.
223
224 lemma Ropp_inv : ∀x.x = Ropp (Ropp x).
225 intro;autobatch;
226 qed.
227
228 lemma Rinv_inv : ∀x.x ≠ R0 → x = Rinv (Rinv x).
229 intros;rewrite < Rtimes_x_R1 in ⊢ (???%);rewrite > sym_Rtimes;
230 apply eq_Rtimes_l_to_r
231 [intro;lapply (eq_f ? ? (λy:R.x*y) ? ? H1);
232  rewrite > Rinv_Rtimes_l in Hletin
233  [rewrite > Rtimes_x_R0 in Hletin;apply not_eq_R0_R1;symmetry;assumption
234  |assumption]
235 |apply Rinv_Rtimes_l;assumption] 
236 qed.
237
238 lemma Ropp_R0 : R0 = - R0.
239 rewrite < eq_Rtimes_Ropp_R1_Ropp;autobatch paramodulation;
240 qed.
241
242 lemma distr_Ropp_Rplus : ∀x,y:R.-(x + y) = -x -y.
243 intros;rewrite < eq_Rtimes_Ropp_R1_Ropp;
244 rewrite > sym_Rtimes;rewrite > distr_Rtimes_Rplus_l;
245 autobatch paramodulation;
246 qed.
247
248 lemma Ropp_Rtimes_l : ∀x,y:R.-(x*y) = -x*y.
249 intros;rewrite < eq_Rtimes_Ropp_R1_Ropp;
250 rewrite > sym_Rtimes;rewrite < assoc_Rtimes;autobatch paramodulation;
251 qed.
252
253 lemma Ropp_Rtimes_r : ∀x,y:R.-(x*y) = x*-y.
254 intros;rewrite > sym_Rtimes;rewrite > sym_Rtimes in ⊢ (???%);
255 autobatch;
256 qed.
257
258 (* less than *)
259
260 lemma Rlt_to_Rlt_Ropp_Ropp : ∀x,y.x < y → -y < -x.
261 intros;rewrite < Rplus_x_R0 in ⊢ (??%);
262 rewrite < (Rplus_Ropp y);rewrite < Rplus_x_R0 in ⊢ (?%?);
263 rewrite < assoc_Rplus;rewrite < sym_Rplus in ⊢ (??%);
264 apply Rlt_plus_l;
265 rewrite < (Rplus_Ropp x);rewrite < sym_Rplus in ⊢ (?%?);autobatch;
266 qed.
267
268 lemma lt_R0_R1 : R0 < R1.
269 elim (trichotomy_Rlt R0 R1) [|elim (not_eq_R0_R1 H)]
270 elim H [assumption]
271 rewrite > Ropp_inv in ⊢ (??%);rewrite < eq_Rtimes_Ropp_R1_Ropp;
272 rewrite < (Rtimes_x_R0 (-R1));
273 apply Rlt_times_l;rewrite < (Rtimes_x_R0 (-R1));
274 rewrite > sym_Rtimes;rewrite > eq_Rtimes_Ropp_R1_Ropp;autobatch;
275 qed.
276
277 lemma pos_z_to_lt_Rtimes_Rtimes_to_lt : ∀x,y,z.R0 < z → z*x < z*y → x < y.
278 intros;elim (trichotomy_Rlt x y)
279 [elim H2 [assumption]
280  elim (asym_Rlt (z*y) (z*x));autobatch
281 |rewrite > H2 in H1;elim (irrefl_Rlt ? H1)]
282 qed.
283
284 lemma pos_z_to_le_Rtimes_Rtimes_to_lt : ∀x,y,z.R0 < z → z*x ≤ z*y → x ≤ y.
285 intros;cases H1
286 [left;autobatch
287 |right;rewrite < Rtimes_x_R1;rewrite < Rtimes_x_R1 in ⊢ (???%);
288  rewrite < sym_Rtimes;rewrite < sym_Rtimes in ⊢ (???%);
289  rewrite < (Rinv_Rtimes_l z)
290  [rewrite < sym_Rtimes in ⊢ (??(?%?)?);rewrite < sym_Rtimes in ⊢ (???(?%?));
291   autobatch paramodulation
292  |intro;rewrite > H3 in H;apply (irrefl_Rlt R0);assumption]] 
293 qed.
294
295 lemma neg_z_to_lt_Rtimes_Rtimes_to_lt : ∀x,y,z.z < R0 → z*x < z*y → y < x.
296 intros;rewrite > Ropp_inv in ⊢ (?%?);
297 rewrite > Ropp_inv in ⊢ (??%);
298 apply Rlt_to_Rlt_Ropp_Ropp;apply (pos_z_to_lt_Rtimes_Rtimes_to_lt ?? (-z))
299 [rewrite > Ropp_R0;autobatch
300 |rewrite < (eq_Rtimes_Ropp_R1_Ropp) in ⊢ (?(??%)?);
301  rewrite < (eq_Rtimes_Ropp_R1_Ropp) in ⊢ (??(??%));
302  do 2 rewrite < assoc_Rtimes;
303  rewrite > eq_Rtimes_Ropp_R1_Ropp;
304  rewrite > eq_Rtimes_Ropp_R1_Ropp in ⊢ (??%);
305  rewrite > sym_Rtimes;rewrite > sym_Rtimes in ⊢ (??%);
306  rewrite < (eq_Rtimes_Ropp_R1_Ropp) in ⊢ (?%?);
307  rewrite < (eq_Rtimes_Ropp_R1_Ropp) in ⊢ (??%);
308  do 2 rewrite > assoc_Rtimes;
309  rewrite > eq_Rtimes_Ropp_R1_Ropp;
310  rewrite < Ropp_inv;
311  rewrite > sym_Rtimes;rewrite > sym_Rtimes in ⊢ (??%);
312  assumption]
313 qed.
314
315 lemma lt_R0_Rinv : ∀x.R0 < x → R0 < Rinv x.
316 intros;apply (pos_z_to_lt_Rtimes_Rtimes_to_lt ?? x H);rewrite > Rinv_Rtimes_l;
317 [rewrite > Rtimes_x_R0;autobatch
318 |intro;apply (irrefl_Rlt x);rewrite < H1 in H;assumption]
319 qed.
320
321 lemma pos_times_pos_pos : ∀x,y.R0 < x → R0 < y → R0 < x*y.
322 intros;rewrite < (Rtimes_x_R0 x);autobatch;
323 qed.
324
325 lemma pos_plus_pos_pos : ∀x,y.R0 < x → R0 < y → R0 < x+y.
326 intros;rewrite < (Rplus_Ropp x);apply Rlt_plus_l;
327 apply (trans_Rlt ???? H1);rewrite > Ropp_R0;
328 apply Rlt_to_Rlt_Ropp_Ropp;assumption;
329 qed.
330
331 lemma Rlt_to_neq : ∀x,y:R.x < y → x ≠ y.
332 intros;intro;rewrite > H1 in H;apply (irrefl_Rlt ? H);
333 qed.
334
335 lemma lt_Rinv : ∀x,y.R0 < x → x < y → Rinv y < Rinv x.
336 intros;
337 lapply (Rlt_times_l ? ? (Rinv x * Rinv y) H1)
338 [rewrite > sym_Rtimes in Hletin;rewrite < assoc_Rtimes in Hletin;
339  rewrite > assoc_Rtimes in Hletin:(??%);
340  rewrite > sym_Rtimes in Hletin:(??(??%));
341  rewrite > Rinv_Rtimes_l in Hletin
342  [rewrite > Rinv_Rtimes_l in Hletin
343   [rewrite > Rtimes_x_R1 in Hletin;rewrite > sym_Rtimes in Hletin;
344    rewrite > Rtimes_x_R1 in Hletin;assumption
345   |intro;rewrite > H2 in H1;apply (asym_Rlt ? ? H H1)]
346  |intro;rewrite > H2 in H;apply (irrefl_Rlt ? H)]
347 |apply pos_times_pos_pos;apply lt_R0_Rinv;autobatch]
348 qed.
349
350 lemma Rlt_plus_l_to_r : ∀a,b,c.a + b < c → a < c - b.
351 intros;rewrite < Rplus_x_R0;rewrite < (Rplus_Ropp b);
352 rewrite < assoc_Rplus;
353 rewrite < sym_Rplus;rewrite < sym_Rplus in ⊢ (??%);
354 apply Rlt_plus_l;assumption;
355 qed.
356
357 lemma Rlt_plus_r_to_l : ∀a,b,c.a < b + c → a - c < b.
358 intros;rewrite > Ropp_inv;rewrite > Ropp_inv in ⊢ (??%);
359 apply Rlt_to_Rlt_Ropp_Ropp;rewrite > distr_Ropp_Rplus;
360 apply Rlt_plus_l_to_r;rewrite < distr_Ropp_Rplus;apply Rlt_to_Rlt_Ropp_Ropp;
361 assumption;
362 qed.
363
364 lemma Rlt_minus_l_to_r : ∀a,b,c.a - b < c → a < c + b.
365 intros;rewrite > (Ropp_inv b);apply Rlt_plus_l_to_r;assumption;
366 qed.
367
368 lemma Rlt_minus_r_to_l : ∀a,b,c.a < b - c → a + c < b.
369 intros;rewrite > (Ropp_inv c);apply Rlt_plus_r_to_l;assumption;
370 qed.
371
372 lemma Rlt_div_r_to_l : ∀a,b,c.R0 < c → a < b/c → a*c < b.
373 intros;rewrite < sym_Rtimes;
374 rewrite < Rtimes_x_R1 in ⊢ (??%);rewrite < sym_Rtimes in ⊢ (??%);
375 rewrite < (Rinv_Rtimes_l c)
376 [rewrite > assoc_Rtimes;apply Rlt_times_l
377  [rewrite > sym_Rtimes;assumption
378  |autobatch]
379 |intro;elim (Rlt_to_neq ?? H);symmetry;assumption]
380 qed.
381
382 lemma Rlt_times_l_to_r : ∀a,b,c.R0 < b → a*b < c → a < c/b.
383 intros;rewrite < sym_Rtimes;
384 rewrite < Rtimes_x_R1;rewrite < sym_Rtimes;
385 rewrite < (Rinv_Rtimes_l b)
386 [rewrite < sym_Rtimes in ⊢ (? (? % ?) ?);
387  rewrite > assoc_Rtimes;apply Rlt_times_l
388  [rewrite > sym_Rtimes;assumption
389  |autobatch]
390 |intro;elim (Rlt_to_neq ?? H);symmetry;assumption]
391 qed.
392
393 lemma Rle_plus_l_to_r : ∀a,b,c.a + b ≤ c → a ≤ c - b.
394 intros;cases H
395 [left;autobatch
396 |right;autobatch]
397 qed.
398
399 lemma Rle_plus_r_to_l : ∀a,b,c.a ≤ b + c → a - c ≤ b.
400 intros;cases H
401 [left;autobatch
402 |right;autobatch]
403 qed.
404
405 lemma Rle_minus_l_to_r : ∀a,b,c.a - b ≤ c → a ≤ c + b.
406 intros;cases H
407 [left;autobatch
408 |right;autobatch]
409 qed.
410
411 lemma Rle_minus_r_to_l : ∀a,b,c.a ≤ b - c → a + c ≤ b.
412 intros;cases H
413 [left;autobatch
414 |right;autobatch]
415 qed.
416
417 lemma R_OF_nat_S : ∀n.R_OF_nat (S n) = R_OF_nat n + R1.
418 intros;elim n;simplify
419 [autobatch paramodulation
420 |reflexivity]
421 qed.
422
423 lemma nat_lt_to_R_lt : ∀m,n:nat.m < n → R_OF_nat m < R_OF_nat n.
424 intros;elim H
425 [cases m;simplify
426  [autobatch
427  |rewrite < Rplus_x_R0 in ⊢ (?%?);apply Rlt_plus_l;autobatch]
428 |apply (trans_Rlt ??? H2);cases n1;simplify
429  [autobatch
430  |rewrite < Rplus_x_R0 in ⊢ (?%?);apply Rlt_plus_l;autobatch]]
431 qed.