forked from coq-community/dedekind-reals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Additive.v
267 lines (247 loc) · 9.25 KB
/
Additive.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
(** The additive structure of reals. *)
Require Import Setoid Morphisms SetoidClass.
Require Import MiscLemmas.
Require Import QArith QOrderedType Qminmax Qabs.
Require Import Cut.
Require Import Archimedean.
Local Open Scope Q_scope.
(** Addition. *)
Definition Rplus : R -> R -> R.
Proof.
intros x y.
refine {|
lower := (fun q => exists r s, q < r + s /\ lower x r /\ lower y s) ;
upper := (fun q => exists r s, r + s < q /\ upper x r /\ upper y s)
|}.
- intros u v Euv.
split ; intros [r [s [H1 [H2 H3]]]] ; exists r, s ; split ; auto.
+ setoid_rewrite <- Euv ; assumption.
+ setoid_rewrite Euv ; assumption.
- intros u v Euv.
split ; intros [r [s [H1 [H2 H3]]]] ; exists r, s ; split ; auto.
+ setoid_rewrite <- Euv ; assumption.
+ setoid_rewrite Euv ; assumption.
- destruct (lower_bound x) as [q H].
destruct (lower_bound y) as [r G].
exists (q + r).
destruct (lower_open x q H) as [q' [Lqq' H']].
destruct (lower_open y r G) as [r' [Lrr' G']].
exists q', r' ; split ; auto.
apply Qplus_lt_lt_compat ; assumption.
- destruct (upper_bound x) as [q H].
destruct (upper_bound y) as [r G].
exists (q+r).
destruct (upper_open x q H) as [q' [Lqq' H']].
destruct (upper_open y r G) as [r' [Lrr' G']].
exists q', r';split; auto.
apply Qplus_lt_lt_compat ; assumption.
- intros q r Lqr [r' [s' [H1 [H2 H3]]]].
exists r', s' ; split ; auto.
transitivity r ; assumption.
- intros q [r [s [H1 [H2 H3]]]].
exists ((q + r + s) * (1#2)) ; split.
+ apply (Qle_lt_trans q ((q+q)*(1#2)) ((q + r + s) * (1 # 2))).
ring_simplify; apply Qle_refl.
apply Qmult_lt_compat_r; [reflexivity | idtac].
apply (Qplus_lt_r _ _ (-q)); ring_simplify; assumption.
+ exists r, s ; split ; auto.
setoid_replace (r+s) with ((r+s+r+s)*(1#2)).
apply Qmult_lt_compat_r. reflexivity.
destruct (Qplus_lt_l q (r+s) (r+s)) .
setoid_replace (q+r+s) with (q+(r+s)); [idtac | ring].
setoid_replace (r+s+r+s) with (r+s+(r+s)); [auto | ring].
ring_simplify; ring.
- intros q r Lqr [r' [s' [H1 [H2 H3]]]].
exists r', s'; split; auto.
transitivity q; assumption.
- intros q [r [s [H1 [H2 H3]]]].
exists ((q + r + s) * (1#2)) ; split.
+apply (Qlt_le_trans ((q + r + s) * (1 # 2)) ((q+q)*(1#2)) q).
apply Qmult_lt_compat_r; [reflexivity | idtac].
destruct (Qplus_lt_r (r+s) q q).
setoid_replace (q+r+s) with (q+(r+s)); [apply H0;assumption|idtac].
ring_simplify; apply Qeq_refl.
ring_simplify; apply Qle_refl.
+ exists r, s ; split ; auto.
setoid_replace (r+s) with ((r+s+r+s)*(1#2)); [idtac|ring].
apply Qmult_lt_compat_r; [reflexivity | idtac].
destruct (Qplus_lt_l (r+s) q (r+s)) .
apply (Qplus_lt_r _ _ (-r-s)); ring_simplify; assumption.
- intros q [[r [s [H1 [H2 H3]]]] [r' [s' [G1 [G2 G3]]]]].
apply (Qlt_irrefl q).
transitivity (r + s) ; auto.
transitivity (r' + s') ; auto.
apply Qplus_lt_lt_compat ; [apply (lower_below_upper x) | apply (lower_below_upper y) ] ; auto.
- intros q r H.
assert (G : ((r-q)*(1 # 2) > 0)%Q).
apply (Qmult_lt_r _ _ (2#1)); [reflexivity|ring_simplify].
apply (Qplus_lt_r _ _ q); ring_simplify; assumption.
destruct (archimedean x _ G) as [xL [xU [xA [xB xC]]]].
destruct (archimedean y _ G) as [yL [yU [yA [yB yC]]]].
destruct (Qlt_le_dec (xL+yL) r) as [E1 | E2].
+ destruct (Qlt_le_dec (xU+yU) r) as [F1 | F2].
* right.
exists xU, yU; auto.
* {
left.
exists xL, yL; split; auto.
assert (r-xL-yL<r-q).
-setoid_replace (r-q) with ((r-q)*(1#2) + (r-q)*(1#2));[idtac|ring].
apply (Qlt_trans (r-xL-yL) ((r-q)*(1#2)+yU-yL) ((r-q)*(1#2)+(r-q)*(1#2))).
+ apply (Qle_lt_trans (r-xL-yL) (xU-xL+yU-yL) ((r-q)*(1#2)+yU-yL)).
* apply (Qplus_le_r _ _ (xL+yL)%Q) ; ring_simplify ; auto.
* apply (Qplus_lt_r _ _ (-yU+yL)%Q) ; ring_simplify.
setoid_replace ((1 # 2) * r + (-1 # 2) * q) with ((r - q) * (1 # 2)).
auto. ring_simplify; reflexivity.
+ setoid_replace ((r-q)*(1#2)+yU-yL) with ((r-q)*(1#2)+(yU-yL)).
apply Qplus_lt_r; auto.
ring_simplify; reflexivity.
-apply (Qplus_lt_l _ _ (r-xL-yL-q)); ring_simplify.
setoid_replace ((-1#1)*q+r) with (r-q);[auto|apply (Qplus_comm ((-1#1)*q)r)].
}
+left.
exists xL, yL; split; auto.
apply (Qlt_le_trans q r (xL+yL)); auto.
Defined.
(** Opposite value. *)
Definition Ropp : R -> R.
Proof.
intro x.
refine {| lower := (fun q => upper x (-q)); upper := (fun r => lower x (-r)) |}.
- intros ? ? H. rewrite H; tauto.
- intros ? ? H. rewrite H; tauto.
- destruct (upper_bound x) as [r H].
exists (- r).
rewrite (Qopp_involutive r); assumption.
- destruct (lower_bound x) as [q H].
exists (- q).
rewrite (Qopp_involutive q); assumption.
- intros q r H G.
apply (upper_upper _ (- r) _); [idtac | assumption].
apply Qopp_lt_compat.
rewrite 2 Qopp_involutive; assumption.
- intros q H.
destruct (upper_open x (-q)) as [s [G1 G2]]; [assumption | idtac].
exists (-s); split.
apply Qopp_lt_shift_r; assumption.
rewrite Qopp_involutive; assumption.
- intros q r H G.
apply (lower_lower _ _ (- q)) ; [idtac | assumption].
apply Qopp_lt_compat.
rewrite 2 Qopp_involutive; assumption.
- intros q H.
destruct (lower_open x (-q)) as [s [G1 G2]]; [assumption | idtac].
exists (-s); split.
apply Qopp_lt_shift_l; assumption.
rewrite Qopp_involutive; assumption.
- intros.
pose (H := disjoint x (- q)).
tauto.
- intros q r H.
destruct (located x (-r) (-q)).
+ apply Qopp_lt_compat; rewrite 2 Qopp_involutive; assumption.
+ right; assumption.
+ left; assumption.
Defined.
Definition Rminus x y := Rplus x (Ropp y).
(** Notation for the ring structure. *)
Infix "+" := Rplus : R_scope.
Notation "- x" := (Ropp x) : R_scope.
Infix "-" := Rminus : R_scope.
(** The arithmetical operations are proper with respect to equality. *)
Instance Rplus_comp : Proper (Req ==> Req ==> Req) Rplus.
Proof.
intros x y Exy u v Euv.
split ; intros q [s [r ?]].
- exists s, r. setoid_rewrite <- Exy ; setoid_rewrite <- Euv ; auto.
- exists s, r. setoid_rewrite -> Exy ; setoid_rewrite -> Euv ; auto.
Qed.
Instance Ropp_comp : Proper (Req ==> Req) Ropp.
Proof.
intros x y E.
split ; intro q ; simpl ; rewrite E ; auto.
Qed.
Local Open Scope R_scope.
(** Properties of addition. *)
Lemma Rplus_assoc (x y z : R) : (x + y) + z == x + (y + z).
Proof.
split.
- intros q [s [r [G1 [[s' [r' [K1 [K2 K3]]]] G3]]]].
exists s', (r + r')%Q ; split.
+ rewrite (Qplus_comm r r').
rewrite (Qplus_assoc s' r' r).
rewrite G1.
apply Qplus_lt_l.
assumption.
+ split ; auto.
destruct (lower_open z r) as [t [H1 H2]]. assumption.
exists r', t; split; auto.
rewrite (Qplus_comm r r').
apply Qplus_lt_r; auto.
- intros q [x' [yz' [H [Hx [y' [z' [H1 [Hy Hz]]]]]]]].
exists (x' + y')%Q, z' ; split.
+ transitivity (x' + yz')%Q ; auto.
apply (Qplus_lt_r _ _ (-x')); ring_simplify; assumption.
+ split ; auto.
destruct (lower_open x x') as [t [G1 G2]] ; auto.
exists t, y'; split; auto.
apply Qplus_lt_l; auto.
Qed.
Lemma Rplus_comm (x y : R) : x + y == y + x.
Proof.
split ; intros q [r [s [G1 [G2 G3]]]] ; exists s, r ; split ; auto ;
setoid_rewrite (Qplus_comm s r) ; assumption.
Qed.
Lemma Rplus_0_l (x : R) : 0 + x == x.
Proof.
split ; intros q.
- intros [r [s [H1 [H2 H3]]]].
apply (lower_lower x q s) ; auto.
transitivity (r+s)%Q;auto.
apply (Qplus_lt_r _ _ (-s)); ring_simplify.
apply H2.
- intro H.
destruct (lower_open x q H) as [r [G1 G2]].
exists ((q - r) * (1#2))%Q, r ; split.
+ setoid_replace ((q - r) * (1 # 2) + r)%Q with ((q + r) * (1 # 2));[idtac|ring].
apply (Qle_lt_trans q ((q+q)*(1#2))_); [ring_simplify; apply Qle_refl| idtac ].
apply Qmult_lt_compat_r; [reflexivity | idtac].
apply Qplus_lt_r; assumption.
+ split ; auto.
cut ((q - r) * (1#2)<0)%Q;auto.
apply (Qplus_lt_r _ _ (r*(1#2))); ring_simplify.
setoid_replace ((1#2)*q) with (q*(1#2)); [idtac|ring].
setoid_replace ((1#2)*r) with (r*(1#2)); [idtac|ring].
apply Qmult_lt_compat_r; [reflexivity| assumption].
Qed.
Lemma Rplus_0_r (x : R) : x + 0 == x.
Proof.
setoid_rewrite Rplus_comm.
apply Rplus_0_l.
Qed.
(** Properties of opposite. *)
Lemma Ropp_involutive (x : R) : - (- x) == x.
Proof.
split ; intros q H ; simpl in * |- * ;
rewrite Qopp_opp in * |- * ; assumption.
Qed.
Lemma Rpluss_opp_r (x : R) : x + (- x) == 0.
Proof.
split ; intros q H.
- destruct H as [r [s [G1 [G2 G3]]]].
apply (lower_lower 0 q (r + s)); auto.
apply (Qplus_lt_r _ _ (-s)); ring_simplify.
apply (lower_below_upper x); [assumption|auto].
- assert (G : (-q > 0)%Q).
+ apply (Qplus_lt_r _ _ q) ; ring_simplify ; auto.
+ destruct (archimedean x _ G) as [a [b [A [B C]]]].
exists a, (-b)%Q; repeat split; auto.
apply (Qplus_lt_r _ _ (b-a-q)%Q) ; ring_simplify ; auto.
cut (upper x (--b)) ; auto.
rewrite Qopp_involutive; auto.
Qed.
Lemma Rplus_opp_l (x : R) : (- x) + x == 0.
Proof.
rewrite Rplus_comm.
apply Rpluss_opp_r.
Qed.