-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrational_intervals.v
2167 lines (1990 loc) · 57.4 KB
/
rational_intervals.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import QArith.
Require Import Qminmax.
Require Import Setoid.
Require Import Lia.
Lemma Q_dense (q1 q2:Q) :
q1 < q2 -> exists q', q1 < q' /\ q' < q2.
Proof.
intros.
exists ((q1+q2) / (2#1)).
split.
rewrite <- (Qmult_lt_r _ _ (2#1)). 2: reflexivity.
field_simplify.
apply Qle_lt_trans with (q1 + q1)%Q.
field_simplify. apply Qle_refl.
apply Qlt_le_trans with (q1 + q2)%Q.
apply Qplus_lt_r; auto.
field_simplify.
field_simplify.
apply Qle_refl.
rewrite <- (Qmult_lt_r _ _ (2#1)). 2: reflexivity.
field_simplify.
apply Qlt_le_trans with (q2 + q2)%Q.
apply Qle_lt_trans with (q1 + q2)%Q.
field_simplify.
field_simplify.
apply Qle_refl.
apply Qplus_lt_l; auto.
field_simplify.
apply Qle_refl.
Qed.
Record rational_interval
:= RatInt
{ rint_start : Q
; rint_end : Q
; rint_proper : rint_start <= rint_end
}.
Definition in_interval (q:Q) (ri:rational_interval) :=
rint_start ri <= q <= rint_end ri.
Definition in_interior (q:Q) (ri:rational_interval) :=
rint_start ri < q /\ q < rint_end ri.
Definition rint_ord (i1 i2:rational_interval) :=
forall q, in_interval q i2 -> in_interval q i1.
Lemma rint_ord_test (i1 i2:rational_interval) :
rint_ord i1 i2 <->
(rint_start i1 <= rint_start i2 /\
rint_end i2 <= rint_end i1).
Proof.
split; intros.
split.
destruct (H (rint_start i2)).
hnf.
split; auto.
apply Qle_refl.
apply rint_proper.
auto.
destruct (H (rint_end i2)).
hnf.
split; auto.
apply rint_proper.
apply Qle_refl.
auto.
hnf; intros.
destruct H.
destruct H0.
split.
apply Qle_trans with (rint_start i2); auto.
apply Qle_trans with (rint_end i2); auto.
Qed.
Definition way_inside (x y:rational_interval) :=
rint_start y < rint_start x /\
rint_end x < rint_end y.
Lemma way_inside_alt r s :
(forall x, in_interval x r -> in_interior x s) <->
way_inside r s .
Proof.
split; intros.
red.
split.
destruct (H (rint_start r)); auto.
split; intuition. apply rint_proper.
destruct (H (rint_end r)); auto.
split; intuition. apply rint_proper.
destruct H. destruct H0.
split.
apply Qlt_le_trans with (rint_start r); auto.
apply Qle_lt_trans with (rint_end r); auto.
Qed.
Definition in_interval_dec (q:Q) (r:rational_interval) :
{ in_interval q r } + { ~in_interval q r }.
Proof.
destruct (Qlt_le_dec q (rint_start r)).
right; intros [??].
assert (q < q).
apply Qlt_le_trans with (rint_start r); auto.
red in H1. abstract lia.
destruct (Qlt_le_dec (rint_end r) q).
right; intros [??].
assert (rint_end r < rint_end r).
apply Qlt_le_trans with q; auto.
red in H1. abstract lia.
left. split; auto.
Defined.
Definition in_interior_dec (q:Q) (r:rational_interval) :
{ in_interior q r } + { ~in_interior q r }.
Proof.
destruct (Qlt_le_dec (rint_start r) q).
destruct (Qlt_le_dec q (rint_end r)).
left; split; auto.
right; intros [??].
assert (q < q).
apply Qlt_le_trans with (rint_end r); auto.
red in H1. abstract lia.
right; intros [??].
assert (rint_start r < rint_start r).
apply Qlt_le_trans with q; auto.
red in H1. abstract lia.
Defined.
Lemma way_inside_dec x y : { way_inside x y } + { ~way_inside x y }.
Proof.
destruct (Qlt_le_dec (rint_start y) (rint_start x)).
destruct (Qlt_le_dec (rint_end x) (rint_end y)).
left. split; auto.
right; intros [??].
assert (rint_end x < rint_end x).
eapply Qlt_le_trans; eauto.
red in H1; lia.
right; intros [??].
assert (rint_start y < rint_start y).
eapply Qlt_le_trans; eauto.
red in H1; lia.
Qed.
Program Definition rint_opp (r:rational_interval) : rational_interval
:= RatInt (Qopp (rint_end r)) (Qopp (rint_start r)) _.
Next Obligation.
intros. apply Qopp_le_compat. apply rint_proper.
Qed.
Program Definition rint_plus (r1 r2:rational_interval) : rational_interval
:= RatInt (rint_start r1 + rint_start r2) (rint_end r1 + rint_end r2) _.
Next Obligation.
intros; apply Qplus_le_compat; apply rint_proper.
Qed.
Lemma Qmin_Qmax_le : forall x1 x2 y1 y2,
x1 <= x2 -> y1 <= y2 ->
Qmin x1 y1 <= Qmax x2 y2.
Proof.
intros. apply Q.min_case.
intros. rewrite <- H1. auto.
apply Qle_trans with x2; auto.
apply Q.le_max_l.
apply Qle_trans with y2; auto.
apply Q.le_max_r.
Qed.
Lemma Qmult_lt_compat a b x y :
0 < a /\ a <= x ->
0 <= b /\ b < y ->
a * b < x * y.
Proof.
intuition.
apply Qlt_le_trans with (a * y).
do 2 rewrite (Qmult_comm a).
apply Qmult_lt_compat_r; auto.
apply Qmult_le_compat_r; auto.
apply Qle_trans with b; intuition.
Qed.
Lemma mult_opp_simpl (p q:Q) :
(-p) * (-q) == p * q.
Proof.
ring.
Qed.
Lemma Qopp_le_compat': forall p q : Q, -p <= -q -> q <= p.
Proof.
intros.
rewrite <- (Qopp_involutive p).
rewrite <- (Qopp_involutive q).
apply Qopp_le_compat. auto.
Qed.
Lemma min_unicity_le:
forall n m p : Q, n <= m /\ p == n \/ m <= n /\ p == m -> p == Qmin n m.
Proof.
intros.
destruct (Q.min_spec_le n m).
destruct H0.
rewrite H1.
intuition. rewrite H3.
apply Qle_antisym; auto.
destruct H0. rewrite H1.
intuition. rewrite H3.
apply Qle_antisym; auto.
Qed.
Lemma max_unicity_le:
forall n m p : Q, n <= m /\ p == m \/ m <= n /\ p == n -> p == Qmax n m.
Proof.
intuition.
apply Qle_lteq in H. destruct H.
apply Q.max_unicity; auto.
apply Q.max_unicity. right.
split.
rewrite H. apply Qle_refl. rewrite H. auto.
apply Q.max_unicity; auto.
Qed.
Lemma Qopp_lt_compat (a b:Q) :
a < b ->
-b < -a.
Proof.
intros.
destruct (Qlt_le_dec (-b) (-a)); auto.
apply Qopp_le_compat in q.
rewrite (Qopp_involutive b) in q.
rewrite (Qopp_involutive a) in q.
assert (a < a). apply Qlt_le_trans with b; auto.
exfalso. red in H0. lia.
Qed.
Lemma Qmult_lt_compat' a b x y :
0 < a /\ a <= x ->
y < b /\ b <= 0 ->
x * y < a * b.
Proof.
intuition.
rewrite <- (Qopp_involutive (x*y)).
rewrite <- (Qopp_involutive (a*b)).
apply Qopp_lt_compat.
apply Qle_lt_trans with (a * (-b)).
ring_simplify. apply Qle_refl.
apply Qlt_le_trans with (x * (-y)).
apply Qmult_lt_compat.
split; auto.
split.
apply Qle_trans with (-0).
compute. discriminate.
apply Qopp_le_compat; auto.
apply Qopp_lt_compat; auto.
ring_simplify. apply Qle_refl.
Qed.
Lemma Qmult_lt_compat'' a b x y :
x <= a /\ a < 0 ->
y < b /\ b <= 0 ->
a * b < x * y.
Proof.
intuition.
rewrite <- (Qopp_involutive (x*y)).
rewrite <- (Qopp_involutive (a*b)).
apply Qopp_lt_compat.
apply Qle_lt_trans with ((-x) * y).
ring_simplify. apply Qle_refl.
apply Qlt_le_trans with ((-a) * b).
apply Qmult_lt_compat'; auto.
split.
apply Qle_lt_trans with (-0).
compute. discriminate.
apply Qopp_lt_compat; auto.
apply Qopp_le_compat; auto.
ring_simplify. apply Qle_refl.
Qed.
Lemma Qmult_lt0 : forall (a b:Q),
0 < a -> 0 < b -> 0 < a*b.
Proof.
intros.
apply Qle_lt_trans with (0*b); auto.
ring_simplify; intuition.
apply Qmult_lt_compat_r; auto.
Qed.
Lemma Qmult_lt0' : forall (a b:Q),
a < 0 -> 0 < b -> a*b < 0.
Proof.
intros.
apply Qlt_le_trans with (0*b); auto.
apply Qmult_lt_compat_r; auto.
ring_simplify. intuition.
Qed.
Lemma Qmult_lt0'' : forall (a b:Q),
a < 0 -> b < 0 -> 0 < a*b.
Proof.
intros.
apply Qlt_le_trans with ( (-a) * (-b)); auto.
apply Qmult_lt0.
change 0 with (-0).
apply Qopp_lt_compat. auto.
change 0 with (-0).
apply Qopp_lt_compat. auto.
rewrite mult_opp_simpl.
intuition.
Qed.
Program Definition rint_mult (r1 r2:rational_interval) : rational_interval
:= RatInt (Qmin (rint_start r1 * rint_start r2)
(Qmin (rint_start r1 * rint_end r2)
(Qmin (rint_end r1 * rint_start r2)
(rint_end r1 * rint_end r2))))
(Qmax (rint_start r1 * rint_start r2)
(Qmax (rint_start r1 * rint_end r2)
(Qmax (rint_end r1 * rint_start r2)
(rint_end r1 * rint_end r2))))
_.
Next Obligation.
intros.
apply Qmin_Qmax_le. apply Qle_refl.
apply Qmin_Qmax_le. apply Qle_refl.
apply Qmin_Qmax_le; apply Qle_refl.
Qed.
Lemma rint_opp_correct r q :
in_interval (Qopp q) (rint_opp r) <-> in_interval q r.
Proof.
split; intros [??]; split.
simpl in H0.
rewrite <- (Qopp_involutive (rint_start r)).
rewrite <- (Qopp_involutive q).
apply Qopp_le_compat. auto.
rewrite <- (Qopp_involutive (rint_end r)).
rewrite <- (Qopp_involutive q).
apply Qopp_le_compat. auto.
simpl.
apply Qopp_le_compat. auto.
apply Qopp_le_compat. auto.
Qed.
Lemma rint_plus_correct r1 r2 q:
in_interval q (rint_plus r1 r2) <->
exists q1 q2,
in_interval q1 r1 /\ in_interval q2 r2 /\ q == q1 + q2.
Proof.
split; intros.
destruct H. simpl in *.
destruct (Qlt_le_dec q (rint_end r1 + rint_start r2)).
exists (q - rint_start r2), (rint_start r2).
split; split.
rewrite <- (Qplus_le_l _ _ (rint_start r2)). ring_simplify. auto.
rewrite <- (Qplus_le_r _ _ (rint_start r2)).
ring_simplify. rewrite Qplus_comm. apply Qlt_le_weak. auto.
split. apply Qle_refl. apply rint_proper.
ring_simplify. apply Qeq_refl.
exists (rint_end r1). exists (q - rint_end r1).
repeat split.
apply rint_proper. apply Qle_refl.
rewrite <- (Qplus_le_r _ _ (rint_end r1)). ring_simplify. auto.
rewrite <- (Qplus_le_l _ _ (rint_end r1)). ring_simplify. auto.
ring.
destruct H as [q1 [q2 [?[??]]]].
red. rewrite H1. simpl.
destruct H. destruct H0.
split; apply Qplus_le_compat; auto.
Qed.
Lemma Qmult_le_compat a b x y :
0 <= a <= x ->
0 <= b <= y ->
a * b <= x * y.
Proof.
intuition.
apply Qle_trans with (a * y).
do 2 rewrite (Qmult_comm a).
apply Qmult_le_compat_r; auto.
apply Qmult_le_compat_r; auto.
apply Qle_trans with b; auto.
Qed.
Lemma Qmult_le_compat' a b x y :
0 <= a <= x ->
y <= b <= 0 ->
x * y <= a * b.
Proof.
intuition.
rewrite <- (Qopp_involutive (x*y)).
rewrite <- (Qopp_involutive (a*b)).
apply Qopp_le_compat.
apply Qle_trans with (a * (-b)).
ring_simplify. apply Qle_refl.
apply Qle_trans with (x * (-y)).
apply Qmult_le_compat.
split; auto.
split.
apply Qle_trans with (-0).
compute. discriminate.
apply Qopp_le_compat; auto.
apply Qopp_le_compat; auto.
ring_simplify. apply Qle_refl.
Qed.
Lemma Qmult_le_compat'' a b x y :
x <= a <= 0 ->
y <= b <= 0 ->
a * b <= x * y.
Proof.
intuition.
rewrite <- (Qopp_involutive (x*y)).
rewrite <- (Qopp_involutive (a*b)).
apply Qopp_le_compat.
apply Qle_trans with ((-x) * y).
ring_simplify. apply Qle_refl.
apply Qle_trans with ((-a) * b).
apply Qmult_le_compat'; auto.
split.
apply Qle_trans with (-0).
compute. discriminate.
apply Qopp_le_compat; auto.
apply Qopp_le_compat; auto.
ring_simplify. apply Qle_refl.
Qed.
Lemma Qle_trans' (x y z:Q) : y <= z -> x <= y -> x <= z.
Proof.
intros. apply (Qle_trans _ _ _ H0 H).
Qed.
Lemma Qle_shift_div_l' : forall a b c:Q, c < 0 -> b <= a*c -> a <= b / c.
Proof.
intros.
cut (b / (-c) <= -a ).
intros.
rewrite <- (Qopp_involutive a).
rewrite <- (Qopp_involutive (b/c)).
apply Qopp_le_compat.
revert H1. apply Qle_trans.
cut (- (b/c) == b / -c).
intros. rewrite H1. apply Qle_refl.
field.
intro. apply (Qlt_irrefl 0).
rewrite <- H1 at 1. auto.
apply Qle_shift_div_r.
rewrite <- (Qplus_lt_l _ _ c). ring_simplify. auto.
ring_simplify. auto.
Qed.
Lemma Qle_shift_div_r' : forall a b c : Q, b < 0 -> c * b <= a -> a / b <= c.
Proof.
intros.
cut (-c <= a / (-b)).
intros.
rewrite <- (Qopp_involutive c).
rewrite <- (Qopp_involutive (a/b)).
apply Qopp_le_compat.
revert H1. apply Qle_trans'.
cut (- (a/b) == a / -b).
intros. rewrite H1. apply Qle_refl.
field.
intro. apply (Qlt_irrefl 0).
rewrite <- H1 at 1. auto.
apply Qle_shift_div_l.
rewrite <- (Qplus_lt_l _ _ b). ring_simplify. auto.
ring_simplify. auto.
Qed.
Section solve_simple_quadratic.
Variables t s z:Q.
Hypothesis Hs : 0 <= s.
Hypothesis Hst : s^2 < t.
Hypothesis Htz : t < z^2.
Hypothesis Hsz : s < z.
Let a := (z^2 - s^2) / (z - s).
Let b := s^2 - t - s*a.
Let b' := z^2 - t - z*a.
Let f (x:Q) := a*x + b.
Let fzero := -b / a.
Lemma bb' : b == b'.
Proof.
unfold b, b'.
unfold a. field.
intro.
assert (z == s).
apply (Qplus_inj_r _ _ (-s)). ring_simplify.
ring_simplify in H. auto.
apply (Qlt_irrefl (s^2)).
apply Qlt_trans with t; auto.
rewrite <- H0. auto.
Qed.
Lemma f_s : f s == s^2 - t.
Proof.
unfold f, b, a. ring.
Qed.
Lemma f_z : f z == z^2 - t.
Proof.
unfold f. rewrite bb'.
unfold b', a. ring.
Qed.
Lemma f_0 : f fzero == 0.
Proof.
unfold f, fzero. field.
unfold a. intro.
assert (~(z - s == 0)).
intro.
assert (z == s).
apply (Qplus_inj_r _ _ (-s)). ring_simplify.
ring_simplify in H0; auto.
apply (Qlt_irrefl (s^2)).
apply Qlt_trans with t; auto.
rewrite <- H1. auto.
rewrite <- (Qmult_inj_r _ _ (z-s)) in H; auto.
field_simplify in H. 2: contradiction.
assert (z^2 == s^2).
apply (Qplus_inj_r _ _ (-(s^2))). ring_simplify.
field_simplify. auto.
apply (Qlt_irrefl (s^2)).
apply Qlt_trans with t; auto.
rewrite <- H1. auto.
Qed.
Lemma fa_lt0 : 0 < a.
Proof.
unfold a.
apply Qlt_shift_div_l; auto.
apply (Qplus_lt_l _ _ s). ring_simplify.
auto.
apply (Qplus_lt_l _ _ (s^2)). ring_simplify.
apply Qlt_trans with t; auto.
Qed.
Lemma s_fzero : s < fzero.
Proof.
unfold fzero.
unfold b.
apply Qlt_shift_div_l; auto.
apply fa_lt0.
rewrite <- (Qplus_lt_l _ _ (-s*a)). ring_simplify.
rewrite <- (Qplus_lt_l _ _ (s^2)). ring_simplify.
auto.
Qed.
Lemma fzero_z : fzero < z.
Proof.
unfold fzero.
rewrite bb'.
unfold b'.
apply Qlt_shift_div_r; auto.
apply fa_lt0.
rewrite <- (Qplus_lt_l _ _ (-z*a)). ring_simplify.
rewrite <- (Qplus_lt_l _ _ (z^2)). ring_simplify.
auto.
Qed.
Lemma fsz : forall x, s < x /\ x < z -> x^2 < f x + t.
Proof.
intros. destruct H.
unfold f.
rewrite bb'.
unfold b'.
ring_simplify.
unfold a. field_simplify.
apply Qlt_shift_div_l; auto.
rewrite <- (Qplus_lt_l _ _ s). ring_simplify. auto.
field_simplify.
rewrite <- (Qplus_lt_l _ _ ((z^2)*s)). field_simplify.
rewrite <- (Qplus_lt_l _ _ (-(z*(s^2)))). field_simplify.
apply Qle_lt_trans with ((x^2 + z*s)*(z - s)).
field_simplify. apply Qle_refl.
apply Qlt_le_trans with ((x*(z+s))*(z-s)).
2: field_simplify; apply Qle_refl.
rewrite (Qmult_comm _ (z-s)).
rewrite (Qmult_comm _ (z-s)).
apply Qmult_lt_compat.
split.
rewrite <- (Qplus_lt_l _ _ s). ring_simplify.
auto.
apply Qle_refl.
split.
apply (Qplus_le_compat 0 (x^2) 0 (z*s)).
apply (Qmult_le_compat 0 0 x x); intuition.
apply Qle_trans with s; intuition.
apply Qle_trans with s; intuition.
apply (Qmult_le_compat 0 0 z s); intuition.
apply Qle_trans with s; intuition.
ring_simplify.
rewrite <- (Qplus_lt_l _ _ (- (x^2))). ring_simplify.
rewrite <- (Qplus_lt_l _ _ (- (x*s))). ring_simplify.
apply Qle_lt_trans with
((z-x)*s).
ring_simplify; apply Qle_refl.
apply Qlt_le_trans with
((z-x)*x).
2: ring_simplify; apply Qle_refl.
apply Qmult_lt_compat; intuition.
rewrite <- (Qplus_lt_l _ _ x). ring_simplify. auto.
intro.
apply (Qlt_irrefl s).
apply Qlt_trans with x; auto.
apply Qlt_le_trans with z; auto.
rewrite <- (Qplus_le_l _ _ (-s)). ring_simplify.
rewrite <- H1. ring_simplify. apply Qle_refl.
Qed.
Lemma improve_quadratic_lower_bound : exists s', s < s' /\ s'^2 < t.
Proof.
exists fzero.
split. apply s_fzero.
apply Qlt_le_trans with (f fzero + t).
apply fsz. split.
apply s_fzero. apply fzero_z.
rewrite f_0.
ring_simplify. apply Qle_refl.
Qed.
End solve_simple_quadratic.
Lemma Qsolve_mult_quadratic (q ε:Q) :
1 <= q -> 0 < ε ->
exists γ, 0 < γ /\ γ^2 + (2#1)*q*γ < ε.
Proof.
intros.
assert (0 < q).
apply Qlt_le_trans with 1; auto.
compute. auto.
destruct (improve_quadratic_lower_bound (q^2 + ε) q (q+ε)) as [r [??]]; auto.
intuition.
rewrite <- (Qplus_lt_l _ _ (-q^2)).
ring_simplify. auto.
ring_simplify.
rewrite <- (Qplus_lt_l _ _ (-(q^2))). ring_simplify.
apply Qlt_le_trans with ( (2#1)*ε + ε^2).
apply Qle_lt_trans with ( ε + 0 ).
ring_simplify. apply Qle_refl.
apply (Qplus_lt_le_compat).
rewrite <- (Qplus_lt_l _ _ (-ε)). ring_simplify. auto.
apply Qlt_le_weak.
apply Qmult_lt0; auto.
apply Qplus_le_compat.
apply Qmult_le_compat; intuition.
apply (Qmult_le_compat (2#1) 1 (2#1) q); intuition.
apply Qle_refl.
apply Qle_lt_trans with (0+q).
ring_simplify. apply Qle_refl.
rewrite (Qplus_comm q ε).
apply Qplus_lt_le_compat; intuition.
exists (r - q). split.
rewrite <- (Qplus_lt_l _ _ (q)). ring_simplify. auto.
ring_simplify.
rewrite <- (Qplus_lt_l _ _ (q^2)). ring_simplify.
auto.
Qed.
Section ratint_mult_ind.
Variable (P:rational_interval -> rational_interval -> rational_interval -> Prop).
Hypothesis Hsymm :
forall r1 r2,
P r1 r2 (rint_mult r1 r2) ->
P r2 r1 (rint_mult r2 r1).
Hypothesis Hopp :
forall r1 r2,
P (rint_opp r1) (rint_opp r2) (rint_mult (rint_opp r1) (rint_opp r2)) ->
P r1 r2 (rint_mult r1 r2).
Hypothesis Hcase1 :
forall x1 x2 y1 y2 z1 z2 Hx Hy Hz,
let r1 := RatInt x1 x2 Hx in
let r2 := RatInt y1 y2 Hy in
let r3 := RatInt z1 z2 Hz in
0 < x1 -> 0 < y1 ->
z1 == x1*y1 ->
z2 == x2*y2 ->
P r1 r2 r3.
Hypothesis Hcase2 :
forall x1 x2 y1 y2 z1 z2 Hx Hy Hz,
let r1 := RatInt x1 x2 Hx in
let r2 := RatInt y1 y2 Hy in
let r3 := RatInt z1 z2 Hz in
0 < x1 -> y1 <= 0 <= y2 ->
z1 == y1 * x2 ->
z2 == x2 * y2 ->
P r1 r2 r3.
Hypothesis Hcase3 :
forall x1 x2 y1 y2 z1 z2 Hx Hy Hz,
let r1 := RatInt x1 x2 Hx in
let r2 := RatInt y1 y2 Hy in
let r3 := RatInt z1 z2 Hz in
0 < x1 -> y2 < 0 ->
z1 == y1 * x2 ->
z2 == x1 * y2 ->
P r1 r2 r3.
Hypothesis Hcase4 :
forall x1 x2 y1 y2 z1 z2 Hx Hy Hz,
let r1 := RatInt x1 x2 Hx in
let r2 := RatInt y1 y2 Hy in
let r3 := RatInt z1 z2 Hz in
z1 == Qmin (x1*y2) (x2*y1) ->
z2 == Qmax (x1*y1) (x2*y2) ->
x1 <= 0 <= x2 -> y1 <= 0 <= y2 ->
P r1 r2 r3.
Let rstart x1 x2 y1 y2 :=
(Qmin (x1 * y1)
(Qmin (x1 * y2)
(Qmin (x2 * y1)
(x2 * y2)))).
Let rend x1 x2 y1 y2 :=
(Qmax (x1 * y1)
(Qmax (x1 * y2)
(Qmax (x2 * y1)
(x2 * y2)))).
Lemma case1_start x1 x2 y1 y2 :
0 < x1 -> x1 <= x2 ->
0 < y1 -> y1 <= y2 ->
rstart x1 x2 y1 y2 == x1*y1.
Proof.
intros. unfold rstart.
apply Q.min_l.
apply Q.min_case; auto.
intros. rewrite <- H3; auto.
apply Qmult_le_compat; intuition.
apply Q.min_case; auto.
intros. rewrite <- H3. auto.
apply Qmult_le_compat; intuition.
apply Qmult_le_compat; intuition.
Qed.
Lemma case1_end x1 x2 y1 y2 :
0 < x1 -> x1 <= x2 ->
0 < y1 -> y1 <= y2 ->
rend x1 x2 y1 y2 == x2*y2.
Proof.
intros. unfold rend.
repeat rewrite Q.max_assoc.
apply Q.max_r.
apply Q.max_case; auto.
intros. rewrite <- H3; auto.
apply Q.max_case; auto.
intros. rewrite <- H3; auto.
apply Qmult_le_compat; intuition.
apply Qmult_le_compat; intuition.
apply Qle_trans with y1; intuition.
apply Qmult_le_compat; intuition.
apply Qle_trans with x1; intuition.
Qed.
Lemma case2_start x1 x2 y1 y2 :
0 < x1 -> x1 <= x2 ->
y1 <= 0 <= y2 ->
rstart x1 x2 y1 y2 == x2 * y1.
Proof.
intros. unfold rstart.
rewrite (Q.min_comm (x2*y1) (x2*y2)).
repeat rewrite Q.min_assoc.
apply Q.min_r.
apply Q.min_case.
intros. rewrite <- H2; auto.
apply Q.min_case.
intros. rewrite <- H2; auto.
intros.
apply Qmult_le_compat'; intuition.
intros.
apply Qle_trans with (0*0); auto.
apply Qmult_le_compat'; intuition.
apply Qle_trans with x1; intuition.
apply Qmult_le_compat; intuition.
intros.
apply Qle_trans with (0*0); auto.
apply Qmult_le_compat'; intuition.
apply Qle_trans with x1; intuition.
apply Qmult_le_compat; intuition.
apply Qle_trans with x1; intuition.
Qed.
Lemma case2_end x1 x2 y1 y2 :
0 < x1 -> x1 <= x2 ->
y1 <= 0 <= y2 ->
rend x1 x2 y1 y2 == x2 * y2.
Proof.
intros. unfold rend.
repeat rewrite Q.max_assoc.
apply Q.max_r.
apply Q.max_case.
intros. rewrite <- H2; auto.
apply Q.max_case.
intros. rewrite <- H2; auto.
apply Qle_trans with (0*0); auto.
apply Qmult_le_compat'; intuition.
apply Qmult_le_compat; intuition.
apply Qle_trans with x1; intuition.
apply Qmult_le_compat; intuition.
apply Qle_trans with (0*0); auto.
apply Qmult_le_compat'; intuition.
apply Qle_trans with x1; intuition.
apply Qmult_le_compat; intuition.
apply Qle_trans with x1; intuition.
Qed.
Lemma case3_start x1 x2 y1 y2 :
0 < x1 -> x1 <= x2 ->
y1 <= y2 -> y2 < 0 ->
rstart x1 x2 y1 y2 == x2 * y1.
Proof.
intros. unfold rstart.
rewrite (Q.min_comm (x2*y1) (x2*y2)).
repeat rewrite Q.min_assoc.
apply Q.min_r.
apply Q.min_case.
intros. rewrite <- H3; auto.
apply Q.min_case.
intros. rewrite <- H3; auto.
apply Qmult_le_compat'; intuition.
apply Qle_trans with y2; intuition.
apply Qmult_le_compat'; intuition.
apply Qmult_le_compat'; intuition.
apply Qle_trans with x1; intuition.
Qed.
Lemma case3_end x1 x2 y1 y2 :
0 < x1 -> x1 <= x2 ->
y1 <= y2 -> y2 < 0 ->
rend x1 x2 y1 y2 == x1 * y2.
Proof.
intros. unfold rend.
rewrite Q.max_assoc.
rewrite (Q.max_comm (x1*y1) (x1*y2)).
rewrite <- Q.max_assoc.
apply Q.max_l.
apply Q.max_case.
intros. rewrite <- H3; auto.
apply Qmult_le_compat'; intuition.
apply Q.max_case.
intros. rewrite <- H3; auto.
apply Qmult_le_compat'; intuition.
apply Qmult_le_compat'; intuition.
Qed.
Lemma case4_start x1 x2 y1 y2 z :
x1 <= 0 <= x2 ->
y1 <= 0 <= y2 ->
z == Qmin (x1 * y1) (Qmin (x1 * y2) (Qmin (x2 * y1) (x2 * y2))) ->
z == Qmin (x1 * y2) (x2*y1).
Proof.
intros Hx Hy.
remember (Qmin (x1*y2) (x2*y1)) as q.
apply Q.min_case_strong; intros. apply H0. rewrite H; auto.
generalize H; intro H'.
apply Q.min_glb_l in H.
destruct (Qlt_le_dec x1 0).
rewrite <- (mult_opp_simpl x1 y1) in H.
rewrite <- (mult_opp_simpl x1 y2) in H.
apply (Qmult_le_l) in H.
assert (y1 == y2).
apply Qle_antisym; auto.
apply Qle_trans with 0; intuition.
apply Qopp_le_compat in H.
rewrite Qopp_involutive in H.
rewrite Qopp_involutive in H.
auto.
subst q. rewrite H0.
apply min_unicity_le.
left.
split.
rewrite <- H1.
assert (y1 == 0).
apply Qle_antisym; intuition.
rewrite H1; auto.
rewrite H2.
ring_simplify. apply Qle_refl.
rewrite H1; intuition.
rewrite <- (Qplus_lt_l _ _ x1). ring_simplify. auto.
assert (x1 == 0).
apply Qle_antisym; intuition.
rewrite H0. subst q.
apply min_unicity_le.
right.
split.
rewrite H1. ring_simplify.
apply (Qmult_le_compat' 0 0 x2 y1); intuition.
apply Q.min_glb_r in H'.
apply Q.min_glb_l in H'.
rewrite H1 in H'.
rewrite H1. ring_simplify.
ring_simplify in H'.
apply Qle_antisym; auto.
rewrite Qmult_comm.
apply (Qmult_le_compat' 0 0 x2 y1); intuition.
cut (z <= x1*y1).
2: rewrite H0; auto.
clear H.
revert H0.
apply Q.min_case_strong; intros. apply H0; auto. rewrite H; auto.
rewrite H0.
rewrite Heqq.
apply min_unicity_le.
left; split; auto.
apply Q.min_glb_l in H. auto.
reflexivity.
cut (z <= x1*y2).
2: rewrite H0; auto.
clear H.
revert H0.
apply Q.min_case_strong; intros. apply H0; auto. rewrite H; auto.
subst q.
rewrite H0.
apply min_unicity_le.
right; split; auto.
rewrite H0 in H2. auto.
reflexivity.
subst q.
destruct Hx.
apply Qle_lteq in H4.
destruct H4.
apply (Qmult_le_l) in H; auto.
assert (y1 == y2).
apply Qle_antisym; auto.
apply Qle_trans with 0; intuition.
assert (y1 == 0).
apply Qle_antisym; intuition.
rewrite H5; auto.
apply min_unicity_le.
left. rewrite H0.
rewrite <- H5. rewrite H6.
split. ring_simplify. apply Qle_refl.
ring.
rewrite H0 in H2.
rewrite <- H4 in H2.
ring_simplify in H2.
apply min_unicity_le.
right. split.
rewrite <- H4.
ring_simplify.
rewrite Qmult_comm. auto.
rewrite H0. rewrite <- H4.
ring.
Qed.
Lemma case4_end x1 x2 y1 y2 z :
x1 <= 0 <= x2 ->
y1 <= 0 <= y2 ->
z == Qmax (x1 * y1) (Qmax (x1 * y2) (Qmax (x2 * y1) (x2 * y2))) ->
z == Qmax (x1 * y1) (x2 * y2).
Proof.
intros Hx Hy.
remember (Qmax (x1*y1) (x2*y2)) as q.
apply Q.max_case_strong; auto. intros. apply H0. rewrite H; auto.
intro. subst q. intros.
apply Q.max_lub_r in H.
apply Q.max_lub_r in H.
apply max_unicity_le.
right; split; auto.
intros.
cut (x1*y1 <= z).
2: rewrite H0; auto.
clear H.
revert H0.
apply Q.max_case_strong; intros. apply H0; auto. rewrite H; auto.
rewrite H0 in H1.
apply Q.max_lub_r in H.
destruct (Qlt_le_dec 0 y2).
apply (Qmult_le_r) in H; auto.
assert (x1 == x2).
apply Qle_antisym; auto.
apply Qle_trans with 0; intuition.