-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrealops.v
3286 lines (3108 loc) · 110 KB
/
realops.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 Setoid.
Require Import Lia.
Require Import basics.
Require Import preord.
Require Import categories.
Require Import sets.
Require Import finsets.
Require Import esets.
Require Import effective.
Require Import directed.
Require Import plotkin.
Require Import joinable.
Require Import approx_rels.
Require Import profinite.
Require Import cusl.
Require Import rational_intervals.
Require Import realdom.
Require Import Qabs.
Require Import Qminmax.
(** The rational numbers inject into RealDom.
*)
Definition injq_rel (q:Q) : erel unitpo PreRealDom :=
esubset_dec (prod_preord unitpo PreRealDom)
(fun x => in_interior q (snd x))
(fun x => in_interior_dec q (snd x))
(eprod (single tt) rint_enum).
Lemma injq_rel_elem (q:Q) (u:unit) (r:rational_interval) :
(u, r) ∈ injq_rel q <-> in_interior q r.
Proof.
destruct u.
unfold injq_rel.
rewrite esubset_dec_elem.
- simpl. intuition.
apply eprod_elem.
split.
+ apply single_axiom; auto.
+ destruct (rint_enum_complete r) as [n [r' [??]]]; auto.
exists n. rewrite H0. auto.
- intros. destruct H.
destruct H. destruct H1.
destruct x. destruct y. simpl in *.
apply rint_ord_test in H3. destruct H3.
destruct H0. split.
+ eapply Qle_lt_trans; eauto.
+ eapply Qlt_le_trans; eauto.
Qed.
Program Definition injq (q:Q) : PLT.unit true → PreRealDom :=
PLT.Hom true _ PreRealDom (injq_rel q) _ _.
Next Obligation.
intros. apply injq_rel_elem in H1. apply injq_rel_elem.
apply rint_ord_test in H0. destruct H0.
destruct H1. split.
- eapply Qle_lt_trans; eauto.
- eapply Qlt_le_trans; eauto.
Qed.
Next Obligation.
intros. intro.
apply prove_directed; simpl; auto.
intros r1 r2 ? ?.
apply erel_image_elem in H.
apply erel_image_elem in H0.
apply injq_rel_elem in H.
apply injq_rel_elem in H0.
destruct H. destruct H0.
assert (Qmax (rint_start r1) (rint_start r2) <= Qmin (rint_end r1) (rint_end r2)).
{ apply Q.max_case; intros.
- rewrite <- H3; auto.
- apply Q.min_case; intros.
+ rewrite <- H3; auto.
+ apply rint_proper.
+ apply Qlt_le_weak.
apply Qlt_trans with q; auto.
- apply Q.min_case; intros.
+ rewrite <- H3; auto.
+ apply Qlt_le_weak.
apply Qlt_trans with q; auto.
+ apply rint_proper.
}
exists (RatInt _ _ H3).
split; simpl.
- apply rint_ord_test; split; simpl.
+ apply Q.le_max_l.
+ apply Q.le_min_l.
- split; simpl.
+ apply rint_ord_test; split; simpl.
* apply Q.le_max_r.
* apply Q.le_min_r.
+ apply erel_image_elem.
apply injq_rel_elem.
split; simpl.
* apply Q.max_case; intros; auto.
rewrite <- H4; auto.
* apply Q.min_case; intros; auto.
rewrite <- H4; auto.
Qed.
Lemma injq_canon A q :
canonical A (injq q ∘ PLT.terminate _ A).
Proof.
red; intros.
apply PLT.compose_hom_rel in H.
destruct H as [[] [??]].
simpl in H0.
apply injq_rel_elem in H0.
destruct H0.
destruct (Q_dense (rint_start x) q) as [y1 [??]]; auto.
destruct (Q_dense q (rint_end x)) as [y2 [??]]; auto.
assert (y1 <= y2).
{ apply Qle_trans with q; intuition. }
exists (RatInt y1 y2 H6).
split.
- apply PLT.compose_hom_rel.
exists tt. split; simpl; auto.
apply injq_rel_elem.
split; simpl; auto.
- split; simpl; auto.
Qed.
Lemma injq_converges A q :
realdom_converges A (injq q ∘ PLT.terminate _ A).
Proof.
red; intros.
set (x1 := q - ε/(2#1)).
set (x2 := (q + ε/(2#1))%Q).
assert (x1 <= x2).
{ unfold x1, x2.
rewrite <- (Qplus_le_l _ _ (ε/(2#1))). ring_simplify.
field_simplify.
field_simplify.
apply Qle_trans with (q + 0)%Q.
- field_simplify. apply Qle_refl.
- apply Qle_trans with (q + ε)%Q.
+ apply Qplus_le_compat; intuition.
+ field_simplify.
field_simplify. intuition.
}
exists (RatInt x1 x2 H0).
simpl. split.
- apply PLT.compose_hom_rel.
exists tt. split.
+ simpl. apply eprod_elem.
split.
* apply eff_complete.
* apply single_axiom; auto.
+ simpl. apply injq_rel_elem.
split; simpl.
* unfold x1.
rewrite <- (Qplus_lt_l _ _ (ε/(2#1))). ring_simplify.
apply Qle_lt_trans with (q + 0)%Q.
** ring_simplify. apply Qle_refl.
** rewrite (Qplus_comm q).
rewrite (Qplus_comm q).
apply Qplus_lt_le_compat.
*** apply Qlt_shift_div_l.
**** compute. auto.
**** ring_simplify. auto.
*** intuition.
* unfold x2.
apply Qle_lt_trans with (q + 0)%Q.
** ring_simplify. apply Qle_refl.
** rewrite (Qplus_comm q).
rewrite (Qplus_comm q).
apply Qplus_lt_le_compat.
*** apply Qlt_shift_div_l.
**** compute. auto.
**** ring_simplify. auto.
*** intuition.
- unfold x2, x1.
ring_simplify.
field_simplify.
field_simplify.
apply Qle_refl.
Qed.
(** The negation operator *)
Definition real_opp_rel : erel rint_preord rint_preord :=
esubset_dec (prod_preord rint_preord rint_preord)
(fun xy => snd xy ≤ rint_opp (fst xy))
(fun xy => rint_dec _ _)
(eprod rint_enum rint_enum).
Lemma real_opp_rel_elem x y :
(x,y) ∈ real_opp_rel <-> y ≤ rint_opp x.
Proof.
unfold real_opp_rel. rewrite esubset_dec_elem.
- simpl; intuition.
apply eprod_elem; split; apply rint_enum_complete'.
- simpl; intros.
destruct x0; destruct y0.
destruct H as [[??][??]]. simpl in *.
rewrite H3. rewrite H0.
apply rint_ord_test.
apply rint_ord_test in H. destruct H.
simpl. split; apply Qopp_le_compat; auto.
Qed.
Program Definition real_opp : PreRealDom → PreRealDom :=
PLT.Hom true PreRealDom PreRealDom real_opp_rel _ _.
Next Obligation.
simpl; intros.
apply real_opp_rel_elem in H1. apply real_opp_rel_elem.
rewrite H0. rewrite H1.
apply rint_ord_test. simpl.
apply rint_ord_test in H. destruct H.
split; apply Qopp_le_compat; auto.
Qed.
Next Obligation.
repeat intro.
exists (rint_opp x).
split.
- red; intros.
apply H in H0. apply erel_image_elem in H0.
apply real_opp_rel_elem in H0. auto.
- apply erel_image_elem.
apply real_opp_rel_elem. auto.
Qed.
Lemma real_opp_canonical A f :
canonical A f ->
canonical A (real_opp ∘ f).
Proof.
repeat intro.
apply PLT.compose_hom_rel in H0.
destruct H0 as [y [??]].
simpl in H1. apply real_opp_rel_elem in H1.
destruct (H a y) as [y' [??]]; auto.
exists (rint_opp y'). split.
- apply PLT.compose_hom_rel.
exists y'. split; auto.
simpl. apply real_opp_rel_elem. auto.
- destruct H3.
apply rint_ord_test in H1.
simpl in H1. destruct H1.
split; simpl.
+ apply Qle_lt_trans with (-rint_end y); auto.
rewrite <- (Qplus_lt_l _ _ (rint_end y')).
rewrite <- (Qplus_lt_l _ _ (rint_end y)).
ring_simplify. auto.
+ apply Qlt_le_trans with (-rint_start y); auto.
rewrite <- (Qplus_lt_l _ _ (rint_start y')).
rewrite <- (Qplus_lt_l _ _ (rint_start y)).
ring_simplify. auto.
Qed.
Lemma real_opp_converges A f :
realdom_converges A f ->
realdom_converges A (real_opp ∘ f).
Proof.
repeat intro.
destruct (H a ε) as [r [??]]; auto.
exists (rint_opp r).
split.
- apply PLT.compose_hom_rel.
exists r. split; auto.
simpl. apply real_opp_rel_elem. auto.
- simpl.
ring_simplify.
ring_simplify in H2.
rewrite Qplus_comm.
auto.
Qed.
Lemma real_opp_inv : real_opp ∘ real_opp ≈ id.
Proof.
split; hnf; simpl; intros [a r] H.
- apply ident_elem.
apply PLT.compose_hom_rel in H.
destruct H as [y [??]].
simpl in *.
apply real_opp_rel_elem in H.
apply real_opp_rel_elem in H0.
hnf; simpl; intros.
apply H0.
cut (in_interval (-q) y).
{ intros.
apply rint_opp_correct in H2.
red in H2. rewrite Qopp_involutive in H2. auto.
}
apply H.
apply rint_opp_correct. auto.
- simpl in H. apply ident_elem in H.
apply PLT.compose_hom_rel.
exists (rint_opp r).
split.
+ simpl. apply real_opp_rel_elem.
hnf; simpl; intros.
cut (in_interval (-q) r).
{ intros.
apply rint_opp_correct in H1.
red in H1. rewrite Qopp_involutive in H1. auto.
}
apply H.
apply rint_opp_correct.
red. rewrite Qopp_involutive. auto.
+ simpl. apply real_opp_rel_elem.
apply rint_ord_test; simpl.
do 2 rewrite Qopp_involutive.
split; apply Qle_refl.
Qed.
Lemma realdom_lt0_opp A (f:A → PreRealDom) :
realdom_lt A f (injq 0 ∘ PLT.terminate _ A) ->
realdom_lt A (injq 0 ∘ PLT.terminate _ A) (real_opp ∘ f).
Proof.
repeat intro.
destruct (H a) as [x [y [?[??]]]].
exists (rint_opp y).
exists (rint_opp x).
repeat split.
- apply PLT.compose_hom_rel in H1.
destruct H1 as [[][??]].
apply PLT.compose_hom_rel. exists tt. split; auto.
simpl in *.
apply injq_rel_elem in H3.
apply injq_rel_elem.
destruct H3; split; simpl.
+ rewrite <- (Qplus_lt_l _ _ (rint_end y)). ring_simplify; auto.
+ rewrite <- (Qplus_lt_l _ _ (rint_start y)). ring_simplify; auto.
- apply PLT.compose_hom_rel.
exists x. split; auto.
simpl. apply real_opp_rel_elem. auto.
- simpl.
apply Qopp_lt_compat. auto.
Qed.
(** The addition operator *)
Definition real_plus_rel : erel (prod_preord rint_preord rint_preord) rint_preord :=
esubset_dec (prod_preord (prod_preord rint_preord rint_preord) rint_preord)
(fun xyz => (snd xyz) ≤ rint_plus (fst (fst xyz)) (snd (fst xyz)))
(fun xyz => rint_dec _ _)
(eprod (eprod rint_enum rint_enum) rint_enum).
Lemma real_plus_rel_elem x y z :
(x,y,z) ∈ real_plus_rel <-> z ≤ rint_plus x y.
Proof.
unfold real_plus_rel.
rewrite esubset_dec_elem.
- simpl.
intuition. apply eprod_elem. split.
+ apply eprod_elem; split; apply rint_enum_complete'.
+ apply rint_enum_complete'.
- simpl. intros.
destruct x0 as [[??]?]. simpl in *.
destruct y0 as [[??]?]. simpl in *.
destruct H as [[[??]?][[??]?]] . simpl in *.
rewrite H5. rewrite H0.
unfold rint_plus.
apply rint_ord_test. simpl.
apply rint_ord_test in H; destruct H.
split; apply Qplus_le_compat; auto.
+ apply rint_ord_test in H1; destruct H1. auto.
+ apply rint_ord_test in H1; destruct H1. auto.
Qed.
Local Obligation Tactic := idtac.
Program Definition real_plus : (PreRealDom ⊗ PreRealDom)%plt → PreRealDom :=
PLT.Hom true (PreRealDom ⊗ PreRealDom)%plt PreRealDom real_plus_rel _ _.
Next Obligation.
intros.
destruct x. destruct x'.
rewrite real_plus_rel_elem in H1. rewrite real_plus_rel_elem.
transitivity y; auto.
rewrite H1.
destruct H. simpl in *.
apply rint_ord_test. simpl.
apply rint_ord_test in H.
apply rint_ord_test in H2.
split; apply Qplus_le_compat; intuition.
Qed.
Next Obligation.
intro. destruct x as [x y]. apply prove_directed; simpl; auto.
intros. apply erel_image_elem in H. apply erel_image_elem in H0.
apply real_plus_rel_elem in H.
apply real_plus_rel_elem in H0.
exists (rint_plus x y). split; auto. split; auto.
apply erel_image_elem.
apply real_plus_rel_elem. auto.
Qed.
Lemma real_plus_canon : forall A (f g:A → PreRealDom),
canonical A f ->
canonical A g ->
canonical A (real_plus ∘ 《 f, g 》)%plt.
Proof.
repeat intro.
apply PLT.compose_hom_rel in H1.
destruct H1 as [[p q] [??]].
apply (PLT.pair_hom_rel _ _ _ _ f g) in H1. destruct H1.
destruct (H a p) as [p' [??]]; auto.
destruct (H0 a q) as [q' [??]]; auto.
simpl in H2.
apply real_plus_rel_elem in H2.
exists (rint_plus p' q'). split.
- apply PLT.compose_hom_rel.
exists (p',q').
split.
+ apply PLT.pair_hom_rel. split; auto.
+ simpl. apply real_plus_rel_elem. auto.
- apply rint_ord_test in H2. simpl in H2.
destruct H2.
destruct H5. destruct H7.
red; simpl; split.
+ eapply Qle_lt_trans; [ apply H2 |].
apply Qplus_lt_le_compat; intuition.
+ eapply Qlt_le_trans; [| apply H8 ].
apply Qplus_lt_le_compat; intuition.
Qed.
Lemma real_plus_converges : forall A (f g:A → PreRealDom),
realdom_converges A f ->
realdom_converges A g ->
realdom_converges A (real_plus ∘ 《 f, g 》)%plt.
Proof.
repeat intro.
destruct (H a (ε/(2#1))) as [p [??]].
- apply Qlt_shift_div_l.
+ compute. auto.
+ ring_simplify. auto.
- destruct (H0 a (ε/(2#1))) as [q [??]].
+ apply Qlt_shift_div_l.
* compute. auto.
* ring_simplify. auto.
+ exists (rint_plus p q).
split.
* apply PLT.compose_hom_rel.
exists (p,q).
split.
** apply PLT.pair_hom_rel; split; auto.
** simpl. apply real_plus_rel_elem; auto.
* simpl.
apply Qle_trans with
((rint_end p - rint_start p) + (rint_end q - rint_start q))%Q.
** ring_simplify. apply Qle_refl.
** apply Qle_trans with ((ε/(2#1)) + (ε/(2#1)))%Q.
*** apply Qplus_le_compat; auto.
*** field_simplify.
field_simplify.
apply Qle_refl.
Qed.
(** The multiplication operator *)
Definition real_mult_rel : erel (prod_preord rint_preord rint_preord) rint_preord :=
esubset_dec (prod_preord (prod_preord rint_preord rint_preord) rint_preord)
(fun xyz => (snd xyz) ≤ rint_mult (fst (fst xyz)) (snd (fst xyz)))
(fun xyz => rint_dec _ _)
(eprod (eprod rint_enum rint_enum) rint_enum).
Lemma real_mult_rel_elem x y z :
(x,y,z) ∈ real_mult_rel <-> z ≤ rint_mult x y.
Proof.
unfold real_mult_rel. rewrite esubset_dec_elem.
- simpl.
intuition. apply eprod_elem. split.
+ apply eprod_elem; split; apply rint_enum_complete'.
+ apply rint_enum_complete'.
- simpl. intros.
destruct x0 as [[??]?]. simpl in *.
destruct y0 as [[??]?]. simpl in *.
destruct H as [[[??]?][[??]?]] . simpl in *.
rewrite H5. rewrite H0.
hnf; simpl; intros.
apply rint_mult_correct in H6.
apply rint_mult_correct.
destruct H6 as [q1 [q2 [?[??]]]].
exists q1. exists q2. intuition.
Qed.
Program Definition real_mult : (PreRealDom ⊗ PreRealDom)%plt → PreRealDom :=
PLT.Hom true (PreRealDom ⊗ PreRealDom)%plt PreRealDom real_mult_rel _ _.
Next Obligation.
intros.
destruct x. destruct x'.
rewrite real_mult_rel_elem in H1. rewrite real_mult_rel_elem.
transitivity y; auto.
rewrite H1.
hnf; intros.
apply rint_mult_correct in H2.
apply rint_mult_correct.
destruct H2 as [q1 [q2 [?[??]]]].
destruct H. simpl in *.
exists q1. exists q2. intuition.
Qed.
Next Obligation.
intro. destruct x as [x y]. apply prove_directed; simpl; auto.
- intros. apply erel_image_elem in H. apply erel_image_elem in H0.
apply real_mult_rel_elem in H.
apply real_mult_rel_elem in H0.
exists (rint_mult x y). split; auto. split; auto.
apply erel_image_elem.
apply real_mult_rel_elem. auto.
Qed.
Lemma real_mult_canon : forall A (f g:A → PreRealDom),
canonical A f ->
canonical A g ->
canonical A (real_mult ∘ 《 f, g 》)%plt.
Proof.
repeat intro.
apply PLT.compose_hom_rel in H1.
destruct H1 as [[p q] [??]].
apply (PLT.pair_hom_rel _ _ _ _ f g) in H1. destruct H1.
destruct (H a p) as [p' [??]]; auto.
destruct (H0 a q) as [q' [??]]; auto.
simpl in H2.
apply real_mult_rel_elem in H2.
exists (rint_mult p' q'). split.
- apply PLT.compose_hom_rel.
exists (p',q').
split.
+ apply PLT.pair_hom_rel. split; auto.
+ simpl. apply real_mult_rel_elem. auto.
- apply way_inside_alt. intros.
cut (in_interior x0 (rint_mult p q)).
{ intros.
apply rint_ord_test in H2.
destruct H2. destruct H9.
split.
- eapply Qle_lt_trans; [ apply H2 | auto ].
- eapply Qlt_le_trans; [ apply H11 | auto ].
}
apply rint_mult_correct in H8.
destruct H8 as [q1 [q2 [?[??]]]].
apply rint_mult_correct_interior with q1 q2.
+ rewrite <- way_inside_alt in H5.
apply H5; auto.
+ rewrite <- way_inside_alt in H7.
apply H7; auto.
+ auto.
Qed.
Lemma real_mult_converges : forall A (f g:A → PreRealDom),
realdom_converges A f ->
realdom_converges A g ->
realdom_converges A (real_mult ∘ 《 f, g 》)%plt.
Proof.
repeat intro.
destruct (H a 1%Q) as [m [??]]; [ compute; auto |].
destruct (H0 a 1%Q) as [n [??]]; [ compute; auto |].
set (q := Qmax 1 (Qmax (Qabs (rint_start m))
(Qmax (Qabs (rint_end m))
(Qmax (Qabs (rint_start n))
(Qabs (rint_end n)))))).
destruct (Qsolve_mult_quadratic q ε) as [γ [??]];
[ unfold q; apply Q.le_max_l | auto |].
destruct (H a γ) as [r [??]]; auto.
destruct (H0 a γ) as [s [??]]; auto.
destruct (plt_hom_directed2 _ _ _ f a m r) as [r' [?[??]]]; auto.
destruct (plt_hom_directed2 _ _ _ g a n s) as [s' [?[??]]]; auto.
assert (Hr' : rint_end r' - rint_start r' <= γ).
{ eapply Qle_trans; [ | apply H9 ].
ring_simplify.
apply rint_ord_test in H14. destruct H14.
apply Qplus_le_compat; auto.
rewrite <- (Qplus_le_l _ _ (rint_start r')).
rewrite <- (Qplus_le_l _ _ (rint_start r)).
ring_simplify. auto.
}
assert (Hs' : rint_end s' - rint_start s' <= γ).
{ eapply Qle_trans; [ | apply H11 ].
ring_simplify.
apply rint_ord_test in H17. destruct H17.
apply Qplus_le_compat; auto.
rewrite <- (Qplus_le_l _ _ (rint_start s')).
rewrite <- (Qplus_le_l _ _ (rint_start s)).
ring_simplify. auto.
}
exists (rint_mult r' s').
split.
- apply PLT.compose_hom_rel.
exists (r',s').
split.
+ apply PLT.pair_hom_rel; split; auto.
+ simpl. apply real_mult_rel_elem. auto.
- apply rint_ord_test in H13.
apply rint_ord_test in H16.
revert Hr' Hs' H13 H16.
cut (forall m1 m2 n1 n2,
let q := Qmax 1
(Qmax (Qabs m1)
(Qmax (Qabs m2)
(Qmax (Qabs n1) (Qabs n2))))
in
rint_end r' - rint_start r' <= γ ->
rint_end s' - rint_start s' <= γ ->
m1 <= rint_start r' /\ rint_end r' <= m2 ->
n1 <= rint_start s' /\ rint_end s' <= n2 ->
rint_end (rint_mult r' s') - rint_start (rint_mult r' s') <=
(((rint_end r'- rint_start r')*(rint_end s'-rint_start s')) + (2#1)*q*γ)).
{ intros.
eapply Qle_trans; [ apply H13; auto; [ apply H16 | apply H18 ] | ].
apply Qle_trans with (γ^2 + (2#1)*q*γ)%Q.
- apply Qplus_le_compat.
+ simpl.
apply Qmult_le_compat.
* split; auto.
apply (Qplus_le_l _ _ (rint_start r')). ring_simplify. apply rint_proper.
* split; auto.
apply (Qplus_le_l _ _ (rint_start s')). ring_simplify. apply rint_proper.
+ apply Qmult_le_compat; [ split |].
* apply (Qmult_le_compat 0 0).
** split.
*** apply Qle_refl.
*** compute. discriminate.
** split; [ apply Qle_refl |].
apply Qle_trans with 1%Q; [ compute; discriminate |].
apply Q.le_max_l.
* apply Qmult_le_compat.
** split; [ compute; discriminate | apply Qle_refl ].
** split.
*** apply Qle_trans with 1%Q; [ compute; discriminate |].
apply Q.le_max_l.
*** apply Qle_refl.
* intuition.
- intuition.
}
clear -H6.
apply rint_mult_ind.
+ intros.
rewrite rint_mult_swap_end.
rewrite rint_mult_swap_start.
rewrite Qmult_comm.
set (q' := Qmax 1 (Qmax (Qabs n1) (Qmax (Qabs n2) (Qmax (Qabs m1) (Qabs m2))))).
assert (q == q').
{ unfold q'.
rewrite (Q.max_assoc (Qabs n1)).
rewrite (Q.max_comm (Qmax (Qabs n1) (Qabs n2))).
rewrite <- Q.max_assoc.
reflexivity.
}
rewrite H4.
apply H; auto.
+ intros.
rewrite rint_mult_opp_end.
rewrite rint_mult_opp_start.
eapply Qle_trans.
* apply (H (-m2) (-m1) (-n2) (-n1)); auto.
** simpl.
ring_simplify.
ring_simplify in H0.
rewrite Qplus_comm. auto.
** simpl.
ring_simplify.
ring_simplify in H1.
rewrite Qplus_comm. auto.
** simpl. split.
*** apply Qopp_le_compat; intuition.
*** apply Qopp_le_compat; intuition.
** simpl. split.
*** apply Qopp_le_compat; intuition.
*** apply Qopp_le_compat; intuition.
* apply Qplus_le_compat.
** simpl.
ring_simplify. apply Qle_refl.
** repeat rewrite Qabs_opp.
rewrite (Q.max_assoc (Qabs m2)).
rewrite (Q.max_comm (Qabs m2)).
rewrite (Q.max_comm (Qabs n2)).
rewrite <- (Q.max_assoc (Qabs m1)).
apply Qle_refl.
+ simpl; intros.
set (q := Qmax 1
(Qmax (Qabs m1)
(Qmax (Qabs m2)
(Qmax (Qabs n1) (Qabs n2))))).
rewrite H1. rewrite H2.
ring_simplify.
rewrite <- (Qplus_le_l _ _ (-(x2*y2))). ring_simplify.
rewrite <- (Qplus_le_l _ _ (-(x1*y1))). ring_simplify.
rewrite <- (Qplus_le_l _ _ ((x1*y2))). ring_simplify.
rewrite <- (Qplus_le_l _ _ ((y1*x2))). ring_simplify.
apply Qle_trans with
((x1*(y2-y1)) + (y1*(x2-x1)))%Q;
[ ring_simplify; apply Qle_refl |].
apply Qle_trans with (q*γ + q*γ)%Q;
[ | ring_simplify; apply Qle_refl ].
apply Qplus_le_compat.
* apply Qmult_le_compat; intuition.
** apply Qle_trans with x2; auto.
apply Qle_trans with m2; auto.
apply Qle_trans with (Qabs m2); auto.
*** rewrite Qabs_pos; intuition.
apply Qle_trans with x2; auto.
apply Qle_trans with x1; intuition.
*** unfold q.
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
apply Q.le_max_l.
** rewrite <- (Qplus_le_l _ _ y1). ring_simplify. auto.
* apply Qmult_le_compat; intuition.
** apply Qle_trans with y2; auto.
apply Qle_trans with n2; auto.
apply Qle_trans with (Qabs n2); auto.
*** rewrite Qabs_pos; intuition.
apply Qle_trans with y2; auto.
apply Qle_trans with y1; intuition.
*** unfold q.
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
apply Q.le_max_r.
** rewrite <- (Qplus_le_l _ _ x1). ring_simplify. auto.
+ simpl; intros.
set (q := Qmax 1
(Qmax (Qabs m1)
(Qmax (Qabs m2)
(Qmax (Qabs n1) (Qabs n2))))).
rewrite H1. rewrite H2.
ring_simplify.
rewrite <- (Qplus_le_l _ _ (-(x2*y2))). ring_simplify.
rewrite <- (Qplus_le_l _ _ ((x2*y1))). ring_simplify.
rewrite <- (Qplus_le_l _ _ (-(x1*y1))). ring_simplify.
rewrite <- (Qplus_le_l _ _ ((x1*y2))). ring_simplify.
apply Qle_trans with ((x1*(y2-y1)))%Q;
[ ring_simplify; apply Qle_refl |].
apply Qle_trans with (q*γ + q*γ)%Q;
[| ring_simplify; apply Qle_refl ].
apply Qle_trans with (0 + (x1*(y2-y1)))%Q.
* ring_simplify. ring_simplify.
apply Qle_refl.
* apply Qplus_le_compat.
** apply (Qmult_le_compat 0 0); intuition.
apply Qle_trans with 1%Q; [ compute; discriminate |].
unfold q. apply Q.le_max_l.
** apply Qmult_le_compat.
*** split; intuition.
apply Qle_trans with (Qabs m2).
**** apply Qle_trans with x2; auto.
rewrite Qabs_pos; auto.
apply Qle_trans with x2; auto.
apply Qle_trans with x1; intuition.
**** unfold q.
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
apply Q.le_max_l.
*** split; auto.
rewrite <- (Qplus_le_l _ _ y1). ring_simplify. auto.
+ simpl; intros.
set (q := Qmax 1
(Qmax (Qabs m1)
(Qmax (Qabs m2)
(Qmax (Qabs n1) (Qabs n2))))).
rewrite H1. rewrite H2.
ring_simplify.
rewrite <- (Qplus_le_l _ _ ((x1*y2))). ring_simplify.
rewrite <- (Qplus_le_l _ _ ((x2*y1))). ring_simplify.
rewrite <- (Qplus_le_l _ _ (-(x2*y2))). ring_simplify.
rewrite <- (Qplus_le_l _ _ (-(x1*y1))). ring_simplify.
apply Qle_trans with
((x1*(y2-y1)) + ((-y2)*(x2-x1)))%Q;
[ ring_simplify; apply Qle_refl |].
apply Qle_trans with (q*γ + q*γ)%Q;
[ | ring_simplify; apply Qle_refl ].
apply Qplus_le_compat.
* apply Qmult_le_compat; intuition.
** apply Qle_trans with (Qabs m2).
*** apply Qle_trans with x2; auto.
rewrite Qabs_pos; auto.
apply Qle_trans with x2; auto.
apply Qle_trans with x1; intuition.
*** unfold q.
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
apply Q.le_max_l.
** rewrite <- (Qplus_le_l _ _ y1). ring_simplify. auto.
* apply Qmult_le_compat; intuition.
** rewrite <- (Qplus_le_l _ _ y2). ring_simplify. intuition.
** apply Qle_trans with (Qabs n1).
*** rewrite Qabs_neg.
**** rewrite <- (Qplus_le_l _ _ y2).
rewrite <- (Qplus_le_l _ _ n1).
ring_simplify.
apply Qle_trans with y1; auto.
**** apply Qle_trans with y1; auto.
apply Qle_trans with y2; intuition.
*** unfold q.
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
eapply Qle_trans; [| apply Q.le_max_r ].
apply Q.le_max_l.
** rewrite <- (Qplus_le_l _ _ x1). ring_simplify. auto.
+ simpl; intros.
set (q := Qmax 1
(Qmax (Qabs m1)
(Qmax (Qabs m2)
(Qmax (Qabs n1) (Qabs n2))))).
rewrite H. rewrite H0.
apply Q.max_case_strong; intros.
* rewrite <- H8; auto.
* apply Q.min_case_strong; intros.
** rewrite <- H9; auto.
** rewrite <- (Qplus_le_l _ _ (-(x1*y1))).
rewrite <- (Qplus_le_l _ _ ((x1*y2))). ring_simplify.
apply Qle_trans with (0+0+0)%Q;
[ compute; discriminate |].
apply Qplus_le_compat.
*** apply Qplus_le_compat.
**** apply (Qmult_le_compat 0 0).
***** split; intuition.
rewrite <- (Qplus_le_l _ _ y1). ring_simplify. auto.
***** split; [ apply Qle_refl |].
intuition.
**** apply (Qmult_le_compat 0 0); intuition.
*** apply (Qmult_le_compat 0 0).
**** split; [ apply Qle_refl |].
apply (Qmult_le_compat 0 0).
***** split; compute; discriminate.
***** split; auto.
****** compute; discriminate.
****** apply Qle_trans with 1%Q.
******* compute. discriminate.
******* unfold q. apply Q.le_max_l.
**** split; [ apply Qle_refl |].
intuition.
** rewrite <- (Qplus_le_l _ _ (-(x1*y1))).
rewrite <- (Qplus_le_l _ _ ((x2*y1))). ring_simplify.
apply Qle_trans with (0+0+0)%Q; [ compute; discriminate |].
apply Qplus_le_compat.
*** apply Qplus_le_compat.
**** apply (Qmult_le_compat 0 0).
***** split; intuition.
rewrite <- (Qplus_le_l _ _ x1). ring_simplify. auto.
***** split; [ apply Qle_refl |].
intuition.
**** apply (Qmult_le_compat 0 0); intuition.
*** apply (Qmult_le_compat 0 0).
**** split; [ apply Qle_refl |].
apply (Qmult_le_compat 0 0).
***** split; compute; discriminate.
***** split; [ compute; discriminate |].
apply Qle_trans with 1%Q; [ compute; discriminate |].
unfold q. apply Q.le_max_l.
**** split; [ apply Qle_refl |].
intuition.
* apply Q.min_case_strong; intros.
** rewrite <- H9; auto.
** rewrite <- (Qplus_le_l _ _ (-(x2*y2))).
rewrite <- (Qplus_le_l _ _ ((x1*y2))). ring_simplify.
apply Qle_trans with (0+0+0)%Q; [ compute; discriminate |].
apply Qplus_le_compat.
*** apply Qplus_le_compat.
**** apply (Qmult_le_compat'' 0 0).
***** split; intuition.
rewrite <- (Qplus_le_l _ _ x2). ring_simplify. auto.
***** intuition.
**** apply (Qmult_le_compat'' 0 0); intuition.
*** apply (Qmult_le_compat 0 0).
**** split; [ apply Qle_refl |].
apply (Qmult_le_compat 0 0).
***** split; compute; discriminate.
***** split; [ compute; discriminate |].
apply Qle_trans with 1%Q; [ compute; discriminate |].
unfold q. apply Q.le_max_l.
**** split; [ apply Qle_refl |].
intuition.
** rewrite <- (Qplus_le_l _ _ (-(x2*y2))).
rewrite <- (Qplus_le_l _ _ ((x2*y1))). ring_simplify.
apply Qle_trans with (0+0+0)%Q; [ compute; discriminate |].
apply Qplus_le_compat; [ apply Qplus_le_compat; [ apply (Qmult_le_compat'' 0 0) |] |].
*** split; intuition.
rewrite <- (Qplus_le_l _ _ y2). ring_simplify. auto.
*** intuition.
*** apply (Qmult_le_compat'' 0 0); intuition.
*** apply (Qmult_le_compat 0 0).
**** split; [ apply Qle_refl |].
apply (Qmult_le_compat 0 0).
***** split; compute; discriminate.
***** split; [ compute; discriminate |].
apply Qle_trans with 1%Q; [ compute; discriminate |].
unfold q. apply Q.le_max_l.
**** split; [ apply Qle_refl |].
intuition.
Qed.
(** Recripricol operation *)
Definition real_recip_rel : erel rint_preord rint_preord :=
esubset_dec (prod_preord rint_preord rint_preord)
(fun xy => rint_recip (fst xy) (snd xy))
(fun xy => rint_recip_dec (fst xy) (snd xy))
(eprod rint_enum rint_enum).
Lemma real_recip_rel_elem x y :
(x,y) ∈ real_recip_rel <-> rint_recip x y.
Proof.
unfold real_recip_rel.
rewrite esubset_dec_elem.
- simpl. intuition.
apply eprod_elem.
split.
+ destruct (rint_enum_complete x) as [n [x' [??]]].
exists n. rewrite H0. auto.
+ destruct (rint_enum_complete y) as [n [y' [??]]].
exists n. rewrite H0. auto.
- unfold rint_recip. simpl; intuition.
destruct (H0 a0) as [q [??]]; auto.
+ destruct H as [[??][??]]. simpl in *.
apply H. auto.
+ exists q. split; auto.
destruct H as [[??][??]]. simpl in *.
apply rint_ord_test in H6.
destruct H6.
destruct H2; split.
apply Qle_trans with (rint_start b); auto.
apply Qle_trans with (rint_end b); auto.
Qed.
Program Definition real_recip : PreRealDom → PreRealDom :=
PLT.Hom _ PreRealDom PreRealDom real_recip_rel _ _ .
Next Obligation.
intros.
rewrite real_recip_rel_elem in H1.
rewrite real_recip_rel_elem.
red; intros.
destruct (H1 a) as [q [??]].
- apply H. auto.
- exists q; split; auto.
Qed.
Next Obligation.
red; intro.
apply prove_directed; auto.
intros.
apply erel_image_elem in H.
apply erel_image_elem in H0.
rewrite real_recip_rel_elem in H.
rewrite real_recip_rel_elem in H0.
destruct (H (rint_start x)) as [q1 [??]].
- split; auto.
+ apply Qle_refl.
+ apply rint_proper.
- destruct (H0 (rint_start x)) as [q2 [??]].
+ split; auto.
* apply Qle_refl.
* apply rint_proper.
+ assert (q1 == q2).
{ assert (~ rint_start x == 0).
{ intro.
rewrite H5 in H2.
ring_simplify in H2.
compute in H2. discriminate.
}
apply Qeq_trans with (1 / rint_start x).
- apply Qmult_inj_r with (rint_start x); auto.
field_simplify; auto.
rewrite Qmult_comm in H2.
field_simplify in H2.
field_simplify in H2.
auto.
- apply Qmult_inj_r with (rint_start x); auto.
field_simplify; auto.
field_simplify in H4.
field_simplify in H4.
apply Qeq_sym. auto.
}
assert (Qmax (rint_start x0) (rint_start y) <=
Qmin (rint_end x0) (rint_end y)).
{ apply Qle_trans with q1.
apply Q.max_case.
- intros. rewrite <- H6; auto.
- destruct H1; intuition.
- rewrite H5.
destruct H3; intuition.
- apply Q.min_case.