forked from coq-community/dedekind-reals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinMax.v
342 lines (311 loc) · 8.61 KB
/
MinMax.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
(* The lattice structure of the reals. *)
Require Import Setoid Morphisms.
Require Import QArith.
Require Import Qminmax.
Require Import Cut MiscLemmas Additive Multiplication Order.
Local Open Scope R_scope.
Definition Rmin : R -> R -> R.
Proof.
intros x y.
refine {| lower := (fun q => lower x q /\ lower y q) ;
upper := (fun q => upper x q \/ upper y q) |}.
- intros ? ? E. rewrite E ; tauto.
- intros ? ? E. rewrite E ; tauto.
- destruct (lower_bound x) as [q ?].
destruct (lower_bound y) as [r ?].
exists (Qmin q r).
split.
+ destruct (Q.min_spec q r) as [[G H]|[G H]].
* setoid_rewrite H ; assumption.
* setoid_rewrite H. auto using (lower_le x r q).
+ destruct (Q.min_spec q r) as [[G H]|[G H]].
* setoid_rewrite H. auto using (lower_lower y q r).
* setoid_rewrite H ; assumption.
- destruct (upper_bound y) as [r ?].
exists r.
right.
assumption.
- intros q r H [A B].
assert (C:=(lower_lower x q r H A)).
assert (D:=(lower_lower y q r H B)).
auto.
- intros q [A B].
assert (C:=(lower_open x q A)).
destruct C as [r [T U]].
assert (D:=(lower_open y q B)).
destruct D as [s [M P]].
exists (Qmin s r).
repeat split.
+ destruct (Q.min_spec s r) as [[G H]|[G H]].
* setoid_rewrite H ; assumption.
* setoid_rewrite H ; assumption.
+ destruct (Q.min_spec s r) as [[G H]|[G H]].
* setoid_rewrite H.
assert (C:=(lower_lower x s r G U)).
assumption.
* setoid_rewrite H ; assumption.
+ destruct (Q.min_spec s r) as [[G H]|[G H]].
* setoid_rewrite H ; assumption.
* setoid_rewrite H.
assert (K:=(Qle_lteq r s)).
rewrite K in G.
destruct G as [G1 | G2].
clear K.
assert (C:=(lower_lower y r s G1 P)).
assumption.
clear K.
setoid_rewrite G2.
assumption.
- intros q r H [A | B].
assert (C:=(upper_upper x q r H A)).
left.
assumption.
assert (D:=(upper_upper y q r H B)).
right.
assumption.
- intros r [A | B].
+ assert (C:=(upper_open x r A)).
destruct C as [q [T U]].
exists q.
split.
assumption.
left ; assumption.
+ assert (C:=(upper_open y r B)).
destruct C as [q [T U]].
exists q.
split.
assumption.
right ; assumption.
- intro.
apply neg_false.
split.
+ intros [[lx ly] [ux | uy]].
auto using (disjoint x q).
auto using (disjoint y q).
+ tauto.
- intros q r T.
assert (H:=(located x q r T)).
assert (K:=(located y q r T)).
tauto.
Defined.
Definition Rmax : R -> R -> R.
Proof.
intros x y.
refine {| lower := (fun q => lower x q \/ lower y q) ;
upper := (fun q => upper x q /\ upper y q) |}.
- intros ? ? E. rewrite E ; tauto.
- intros ? ? E. rewrite E ; tauto.
- destruct (lower_bound x) as [q ?].
exists q.
left ; assumption.
- destruct (upper_bound x) as [q ?].
destruct (upper_bound y) as [r ?].
exists (Qmax q r).
split.
+ destruct (Q.max_spec q r) as [[G H]|[G H]].
* setoid_rewrite H. auto using (upper_upper x q r).
* setoid_rewrite H ; assumption.
+ destruct (Q.max_spec q r) as [[G H]|[G H]].
* setoid_rewrite H ; assumption.
* setoid_rewrite H. auto using (upper_le y r q).
- intros q r H [A | B].
+ assert (C:=(lower_lower x q r H A)).
left ; assumption.
+ assert (D:=(lower_lower y q r H B)).
right ; assumption.
- intros q [A | B].
+ assert (C:=(lower_open x q A)).
destruct C as [r0 [T U]].
exists r0.
split.
assumption.
left ; assumption.
+ assert (C:=(lower_open y q B)).
destruct C as [r0 [T U]].
exists r0.
split.
assumption.
right ; assumption.
- intros q r H [A B].
assert (C:=(upper_upper x q r H A)).
assert (D:=(upper_upper y q r H B)).
auto.
- intros r [A B].
assert (C:=(upper_open x r A)).
destruct C as [q [T U]].
assert (D:=(upper_open y r B)).
destruct D as [s [M P]].
exists (Qmax s q).
repeat split.
+ destruct (Q.max_spec s q) as [[G H]|[G H]].
* setoid_rewrite H ; assumption.
* setoid_rewrite H ; assumption.
+ destruct (Q.max_spec s q) as [[G H]|[G H]].
* setoid_rewrite H ; assumption.
* setoid_rewrite H.
auto using (upper_le x q s U G).
+ destruct (Q.max_spec s q) as [[G H]|[G H]].
* setoid_rewrite H.
auto using (upper_upper y s q G P).
* setoid_rewrite H ; assumption.
- intro.
apply neg_false.
split.
+ intros [[lx | ly] [ux uy]].
auto using (disjoint x q).
auto using (disjoint y q).
+ tauto.
- intros q r T.
assert (H:=(located x q r T)).
assert (K:=(located y q r T)).
tauto.
Qed.
(** The lattice structure of [R] with respect to [Rmin] and [Rmax]. *)
Theorem Rmin_spec (x y z : R) : z <= Rmin x y <-> z <= x /\ z <= y.
Proof.
unfold Rle.
split.
- intro.
split.
+ intros q A.
assert (C:=(H q A)).
destruct C.
assumption.
+ intros q A.
assert (C:=(H q A)).
destruct C.
assumption.
- intros [H1 H2].
intros q A.
assert (C1:=(H1 q A)).
assert (C2:=(H2 q A)).
firstorder.
Qed.
Theorem Rmin_lower_l (x y : R) : Rmin x y <= x.
Proof.
destruct (proj1 (Rmin_spec x y (Rmin x y)) (Rle_refl _)) ; assumption.
Qed.
Theorem Rmin_lower_r (x y : R) : Rmin x y <= y.
Proof.
destruct (proj1 (Rmin_spec x y (Rmin x y)) (Rle_refl _)) ; assumption.
Qed.
Theorem Rmin_idempotent (x : R) : Rmin x x == x.
Proof.
split.
- apply Rmin_lower_l.
- apply Rmin_spec ; split ; apply Rle_refl.
Qed.
Theorem Rmin_comm (x y : R) : Rmin x y == Rmin y x.
Proof.
split ; apply Rmin_spec ; auto using Rmin_lower_l, Rmin_lower_r.
Qed.
Theorem Rmin_assoc (x y z : R) : Rmin x (Rmin y z) == Rmin (Rmin x y) z.
Proof.
firstorder.
Qed.
Theorem Rmax_spec (x y z : R) : Rmax x y <= z <-> x <= z /\ y <= z.
Proof.
unfold Rle.
split.
- intro.
split.
+ intros q A.
assert (C:=(H q)).
admit.
+ intros q A.
assert (C:=(H q)).
admit.
- intros [H1 H2].
intros q A.
assert (C1:=(H1 q)).
assert (C2:=(H2 q)).
admit.
Qed.
Theorem Rmax_upper_l (x y : R) : x <= Rmax x y.
Proof.
apply (Rmax_spec x y (Rmax x y)), Rle_refl.
Qed.
Theorem Rmax_upper_r (x y : R) : y <= Rmax x y.
Proof.
apply (Rmax_spec x y (Rmax x y)), Rle_refl.
Qed.
Theorem Rmax_idempotent (x : R) : Rmax x x == x.
Proof.
split.
- apply (Rmax_spec x x x) ; split ; apply Rle_refl.
- apply Rmax_upper_l.
Qed.
Theorem Rmax_comm (x y : R) : Rmax x y == Rmax y x.
Proof.
split ; apply Rmax_spec ; auto using Rmax_upper_l, Rmax_upper_r.
Qed.
Theorem Rmax_assoc (x y z : R) : Rmax x (Rmax y z) == Rmax (Rmax x y) z.
Proof.
split.
- apply Rmax_spec.
split.
+ assert(A:=(Rmax_upper_l x y)).
assert(B:=(Rmax_upper_l (Rmax x y) z)).
assert(C:=(Rle_trans x (Rmax x y) (Rmax (Rmax x y) z) A B)).
assumption.
+ apply Rmax_spec ; split.
* assert(A:=(Rmax_upper_r x y)).
assert(B:=(Rmax_upper_l (Rmax x y) z)).
assert(C:=(Rle_trans y (Rmax x y) (Rmax (Rmax x y) z) A B)).
assumption.
* assert(A:=(Rmax_upper_r (Rmax x y) z)) ; assumption.
- apply Rmax_spec ; split.
+ apply Rmax_spec ; split.
* assert(A:=(Rmax_upper_l x (Rmax y z))) ; assumption.
* assert(A:=(Rmax_upper_l y z)).
assert(B:=(Rmax_upper_r x (Rmax y z))).
assert(C:=(Rle_trans y (Rmax y z) (Rmax x (Rmax y z) ) A B)).
assumption.
+ assert(A:=(Rmax_upper_r y z)).
assert(B:=(Rmax_upper_r x (Rmax y z))).
assert(C:=(Rle_trans z (Rmax y z) (Rmax x (Rmax y z)) A B)).
assumption.
Qed.
(* Distributivity of + over min and max. *)
Theorem Rmin_plus_distr_r (x y z : R) : Rmin (x + z) (y + z) == Rmin x y + z.
Proof.
admit.
Qed.
Theorem Rmin_plus_distr_l (x y z : R) : Rmin (x + y) (x + z) == x + Rmin y z.
Proof.
admit.
Qed.
Theorem Rmax_plus_distr_r (x y z : R) : Rmax (x + z) (y + z) == Rmax x y + z.
Proof.
admit.
Qed.
Theorem Rmax_plus_distr_l (x y z : R) : Rmax (x + y) (x + z) == x + Rmax y z.
Proof.
admit.
Qed.
(* Distributivity of * over min and max. *)
Theorem Rmin_mult_distr_r (x y z : R) : 0 < z -> Rmin (x * z) (y * z) == Rmin x y * z.
Proof.
admit.
Qed.
Theorem Rmin_mult_distr_l (x y z : R) : 0 < x -> Rmin (x * y) (x * z) == x * Rmin y z.
Proof.
admit.
Qed.
Theorem Rmax_mult_distr_r (x y z : R) : 0 < z -> Rmax (x * z) (y * z) == Rmax x y * z.
Proof.
admit.
Qed.
Theorem Rmax_mult_distr_l (x y z : R) : 0 < x -> Rmax (x * y) (x * z) == x * Rmax y z.
Proof.
admit.
Qed.
(* Opposite in relation to min and max. *)
Theorem Ropp_min (x y : R) : Rmin (-x) (-y) == - (Rmax x y).
Proof.
admit.
Qed.
Theorem Ropp_max (x y : R) : Rmax (-x) (-y) == - (Rmin x y).
Proof.
admit.
Qed.