-
Notifications
You must be signed in to change notification settings - Fork 3
/
c_util.v
1136 lines (1007 loc) · 29 KB
/
c_util.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 util stability.
Require Export CRsign.
Require Export CRln.
Require Import CRexp.
Require Import QMinMax.
Require Import Morphisms.
Set Implicit Arguments.
Open Local Scope CR_scope.
Definition deci: Qpos := (1#10)%Qpos.
Definition centi: Qpos := (1#100)%Qpos.
Definition milli: Qpos := (1#1000)%Qpos.
Program Definition overestimate_CRnonNeg eps r: overestimation (CRnonNeg r) :=
if Qle_total (- (2) * QposAsQ eps) (approximate r (Qpos2QposInf eps)) then true else false.
Next Obligation.
intro.
pose proof (H1 eps).
set (ax := approximate r eps) in *.
clear H0. clear H1.
apply (Qlt_not_le (-(2)*eps) (-eps)).
change (-eps)%Q with (- (1)%positive * eps)%Q.
apply Qmult_lt_compat_r.
destruct eps.
assumption.
compute; trivial.
apply Qle_trans with ax; trivial.
Defined.
Definition overestimate_CRle eps x y: overestimation (CRle x y) := overestimate_CRnonNeg eps (y - x).
Lemma CRadd_0_r x: x + 0 == x.
intros.
rewrite (Radd_comm CR_ring_theory).
apply (Radd_0_l CR_ring_theory).
Qed. (* todo: generalize to arbitrary ring. *)
Lemma add_both_sides x y: x == y -> forall z, x+z == y+z.
Proof. intros. rewrite H. reflexivity. Qed.
Lemma diff_zero_eq x y: x - y == 0 -> x == y.
Proof.
intros.
set (add_both_sides H y).
rewrite (Radd_0_l CR_ring_theory) in s.
rewrite <- (Radd_assoc CR_ring_theory) in s.
rewrite (Radd_comm CR_ring_theory (-y)) in s.
rewrite (Ropp_def CR_ring_theory) in s.
rewrite (Radd_comm CR_ring_theory) in s.
rewrite (Radd_0_l CR_ring_theory) in s.
assumption.
Qed.
Lemma CRminus_zero x: x - 0 == x.
Proof with auto.
intros.
rewrite CRopp_Qopp.
replace ((-0)%Q) with 0%Q...
rewrite (Radd_comm CR_ring_theory).
apply (Radd_0_l CR_ring_theory).
Qed.
Lemma inject_Q_le x y: (x <= y)%Q -> 'x <= 'y.
Proof. intros. apply (CRle_Qle x y). assumption. Qed.
Lemma CRlt_trans x y z: x < y -> y < z -> x < z.
Proof. apply (cof_proof CRasCOrdField). Qed.
Lemma positive_CRpos (q: positive): CRpos ('q).
Proof.
unfold CRpos.
exists (QposMake q 1).
apply CRle_refl.
Defined.
Lemma Qpos_CRpos (q: Qpos): CRpos ('q).
unfold CRpos.
exists q. apply CRle_refl.
Defined.
Lemma CRnonNeg_nonPos x: CRnonNeg x -> CRnonPos (-x).
unfold CRnonNeg.
unfold CRnonPos.
intros.
simpl.
rewrite <- (Qopp_opp e).
apply Qopp_le_compat.
apply H.
Qed.
Lemma CRnonNeg_le_zero x: CRnonNeg x <-> 0 <= x.
Proof with auto.
unfold CRle.
split; intro; apply (CRnonNeg_wd (CRminus_zero x))...
Qed.
Lemma CRnonNeg_zero: CRnonNeg 0.
Proof. apply (CRnonNeg_le_zero 0). apply CRle_refl. Qed.
(* a much more direct proof should be possible, but we don't care,
because this is in Prop, anyway. *)
Lemma t3: Setoid_Theory CR (@st_eq _).
unfold Setoid_Theory.
apply (CSetoid_eq_Setoid (csg_crr CRasCField)).
Qed.
Lemma diff_opp x y: x - y == -(y - x).
Proof.
rewrite (@Ropp_add _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory ).
rewrite (@Ropp_opp _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory).
apply (Radd_comm CR_ring_theory).
Qed.
Lemma Qmult_inv (x: Q) (y: positive): (x == y -> x * (1 # y) == 1)%Q.
Proof with auto.
intros. rewrite H.
unfold Qeq. simpl. repeat rewrite Pmult_1_r. ref.
Qed.
Lemma QposAsQ_Qpos_plus x y: QposAsQ (Qpos_plus x y) = (QposAsQ x + QposAsQ y)%Q.
reflexivity.
Qed.
Lemma CRle_le_eq x y: x <= y -> y <= x -> x == y.
Proof with auto.
unfold CRle.
intros.
set (CRnonNeg_nonPos H0).
clearbody c.
assert (CRnonPos (y - x)).
rewrite diff_opp.
assumption.
clear c. clear H0.
symmetry.
apply diff_zero_eq.
unfold st_eq.
simpl.
apply regFunEq_e.
unfold CRnonNeg in H. unfold CRnonPos in H1.
intros.
simpl approximate at 2.
unfold ball.
unfold Qmetric.Q_as_MetricSpace at 1.
unfold Qmetric.Qball.
unfold Qminus.
replace ((-0)%Q) with 0%Q...
rewrite (Radd_comm Qsrt).
rewrite (Radd_0_l Qsrt).
set (H e). set (H1 e). clearbody q q0. clear H H1.
unfold AbsSmall.
set (@approximate Qmetric.Q_as_MetricSpace (y - x)%CR e) in *.
clearbody s.
simpl.
assert ((e <= (e + e)%Qpos)%Q).
rewrite QposAsQ_Qpos_plus.
apply Qle_trans with ((e + 0)%Q).
rewrite (Radd_comm Qsrt).
rewrite (Radd_0_l Qsrt).
apply Qle_refl.
apply Qplus_le_compat.
apply Qle_refl.
apply Qpos_nonneg.
split.
apply Qle_trans with ((-e)%Q)...
apply Qopp_le_compat.
assumption.
apply Qle_trans with e...
Qed.
Lemma CRlt_le x y: x < y -> x <= y.
Proof.
intros.
destruct (def_leEq _ _ _ _ _ CRisCOrdField x y).
apply H1.
intro.
destruct (ax_less_strorder _ _ _ _ _ CRisCOrdField).
apply (so_asym x y); assumption.
Qed.
Lemma t1 (x y z: CR): x < y -> x+z < y+z.
Proof.
set (ax_plus_resp_less _ _ _ _ _ CRisCOrdField).
simpl in c.
intros.
apply c.
assumption.
Qed.
Lemma CRlt_wd (x y: CR): x < y ->
forall x' y', x==x'->y==y'->x'<y'.
Proof.
intros [q H] x' y' A B.
exists q.
rewrite <- A, <- B.
assumption.
Qed.
Lemma t1_rev (x y z: CR): x < y -> z+x < z+y.
Proof with auto.
intros.
cut (x + z < y + z).
intro A.
apply (CRlt_wd A); apply CRplus_comm.
apply t1...
Qed.
Lemma t4 (q: Qpos): 0 <= 'q.
Proof.
intros.
destruct (CRle_Qle 0 q).
apply H0.
apply Qpos_nonneg.
Qed.
Lemma Qadd_both_sides x y: (x == y -> forall z, x+z == y+z)%Q.
Proof. intros. rewrite H. reflexivity. Qed.
Lemma Qbla (x y: Q): (-(x * y) == -x * y)%Q.
intros.
symmetry.
rewrite <- (Qplus_0_l (-(x * y))).
rewrite <- (Qplus_0_l (-x * y)).
rewrite <- (Qplus_opp_r (x * y)) at 1.
rewrite <- Qplus_assoc.
rewrite (Qplus_comm (-(x*y))).
rewrite Qplus_assoc.
apply Qadd_both_sides.
rewrite <- Qmult_plus_distr_l.
rewrite Qplus_opp_r.
apply Qmult_0_l.
Qed.
Lemma Qpositive_ne_0 (x: positive): ~(x == 0)%Q.
Proof.
intro A.
inversion A.
Qed.
Lemma Qbla4 (x: positive): (x # x == 1)%Q.
intros.
rewrite Qmake_Qdiv.
apply Qmult_inv_r.
apply Qpositive_ne_0.
Qed.
Lemma Qhalves_add_to_1: ((1#2) + (1#2) == 1)%Q.
Proof. compute. reflexivity. Qed.
Lemma t10 (x y: CR): CRnonNeg x -> CRnonNeg y -> CRnonNeg (x + y).
Proof with auto.
unfold CRnonNeg.
intros.
simpl.
unfold Cap_raw.
simpl.
apply Qle_trans with ((-((1#2)*e)%Qpos + -((1#2)*e)%Qpos)%Q).
rewrite Q_Qpos_mult.
rewrite Qbla.
rewrite <- Qmult_plus_distr_l.
rewrite <- Qopp_plus.
rewrite Qhalves_add_to_1.
rewrite <- Qbla.
rewrite Qmult_1_l.
apply Qle_refl.
apply Qplus_le_compat...
Qed.
Lemma Zero_CRasIR: [0] [=] CRasIR 0.
cut ([0] [=] CRasIR (IRasCR [0])).
intro.
rewrite H.
apply CRasIR_wd, IR_Zero_as_CR.
symmetry. apply IRasCRasIR_id.
Qed.
Lemma CRnonNeg_mult x y: CRnonNeg x -> CRnonNeg y -> CRnonNeg (x * y).
Proof with auto.
intros.
apply <- CRnonNeg_le_zero.
rewrite <- IR_Zero_as_CR.
rewrite <- (CRasIRasCR_id x).
rewrite <- (CRasIRasCR_id y).
rewrite <- IR_mult_as_CR.
apply -> IR_leEq_as_CR.
apply mult_resp_nonneg.
rewrite Zero_CRasIR.
apply <- IR_leEq_as_CR.
do 2 rewrite CRasIRasCR_id.
apply -> CRnonNeg_le_zero...
rewrite Zero_CRasIR.
apply <- IR_leEq_as_CR.
do 2 rewrite CRasIRasCR_id.
apply -> CRnonNeg_le_zero...
Qed.
Lemma t11 x y: y == x + (y - x).
intros.
rewrite (Radd_comm CR_ring_theory y).
rewrite (Radd_assoc CR_ring_theory).
rewrite (Ropp_def CR_ring_theory).
symmetry.
apply (Radd_0_l CR_ring_theory).
Qed.
Lemma CRmult_0_l x: 0 * x == 0.
Proof @Rmul_0_l _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory x.
Lemma CRmult_comm x y: x * y == y * x.
Proof Rmul_comm CR_ring_theory x y.
Lemma CRmult_0_r x: x * 0 == 0.
Proof. rewrite CRmult_comm. apply CRmult_0_l. Qed.
Lemma t9 (x y x' y': CR): x <= x' -> y <= y' -> x+y <= x'+y'.
Proof with auto.
unfold CRle.
intros.
rewrite <- (Radd_assoc CR_ring_theory x').
rewrite (@Ropp_add _ _ _ _ _ _ _ _ t3
CR_ring_eq_ext CR_ring_theory ).
rewrite (Radd_assoc CR_ring_theory y').
rewrite (Radd_comm CR_ring_theory y').
rewrite <- (Radd_assoc CR_ring_theory (-x)).
rewrite (Radd_assoc CR_ring_theory x').
apply t10...
Qed.
Lemma t2 (x y z: CR): x <= y -> x+z <= y+z.
Proof.
unfold CRle.
intros.
set (@Ropp_add CR 0 1 CRplus CRmult
(fun x y : CR => x - y) CRopp (@st_eq CR) t3
CR_ring_eq_ext CR_ring_theory).
rewrite <- (Radd_assoc CR_ring_theory y).
rewrite (Radd_comm CR_ring_theory x).
rewrite s.
rewrite (Radd_assoc CR_ring_theory z).
rewrite (Ropp_def CR_ring_theory).
rewrite (Radd_0_l CR_ring_theory).
assumption.
Qed.
Lemma t8 x y: x <= y -> -y <= -x.
Proof.
unfold CRle.
intros.
set (s := @Ropp_opp _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory).
rewrite s.
rewrite (Radd_comm CR_ring_theory).
assumption.
Qed.
Lemma CRlt_opp_compat x y: x < y -> -y < -x.
unfold CRlt.
unfold CRpos.
intros.
destruct H.
exists x0.
rewrite (@Ropp_opp _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory).
rewrite (Radd_comm CR_ring_theory).
assumption.
Qed.
Lemma CRopp_mult_l x y: -(x * y) == -x * y.
Proof Ropp_mul_l t3 CR_ring_eq_ext CR_ring_theory x y.
Lemma CRmult_lt_0 x y: 0 < x -> 0 < y -> 0 < x * y.
Proof ax_mult_resp_pos _ _ _ _ _ (cof_proof CRasCOrdField) x y.
Lemma CRopp_0: -0 == 0.
rewrite CRopp_Qopp.
reflexivity.
Qed.
Lemma CRpos_lt_0 x: 0 < x -> CRpos x.
unfold CRlt.
intros.
apply CRpos_wd with (x - 0).
rewrite CRopp_0.
apply CRadd_0_r.
assumption.
Qed.
Lemma CRneg_opp x: CRpos (-x) -> CRneg x.
Proof.
intros.
destruct H.
exists x0.
unfold CRle in *.
apply (@CRnonNeg_wd _ (-x - 'x0)).
rewrite CRopp_Qopp.
apply (Radd_comm CR_ring_theory).
assumption.
Defined.
Lemma CRpos_le_trans: forall x, CRpos x -> forall y, x <= y -> CRpos y.
Proof. intros x [e H] y E. exists e. apply (CRle_trans H E). Defined.
Lemma CRneg_le_trans: forall x, CRneg x -> forall y, y <= x -> CRneg y.
Proof. intros x [e H] y E. exists e. apply (CRle_trans E H). Defined.
Lemma CRpos_lt_0_rev x: CRpos x -> 0 < x.
Proof with auto.
unfold CRlt.
intros.
apply CRpos_wd with x.
rewrite CRopp_0.
symmetry. apply CRadd_0_r.
assumption.
Defined.
Lemma CRpos_mult x y: CRpos x -> CRpos y -> CRpos (x * y).
Proof.
intros.
apply CRpos_lt_0.
apply CRmult_lt_0; apply CRpos_lt_0_rev; assumption.
Qed.
Lemma CRmult_lt_pos_r x y: x < y -> forall z, CRpos z -> z * x < z * y.
Proof.
intros.
unfold CRlt in *.
apply CRpos_wd with (z * y + z * -x).
rewrite (Rmul_comm CR_ring_theory z (-x)).
rewrite <- (CRopp_mult_l x z).
rewrite (Rmul_comm CR_ring_theory x z).
reflexivity.
apply CRpos_wd with (z * (y + - x)).
rewrite (Rmul_comm CR_ring_theory z).
rewrite (Rdistr_l CR_ring_theory).
rewrite (Rmul_comm CR_ring_theory y).
rewrite (Rmul_comm CR_ring_theory (-x)).
reflexivity.
apply CRpos_mult; assumption.
Qed.
Lemma t12 x y: -x <= y -> -y <= x.
Proof.
intros.
set (s := @Ropp_opp _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory x).
rewrite <- s.
apply t8.
assumption.
Qed.
Lemma CRpos_opp x: CRneg x -> CRpos (-x).
Proof with auto.
unfold CRpos, CRneg, CRle.
intros.
destruct H.
exists x0.
rewrite CRopp_Qopp.
rewrite (Radd_comm CR_ring_theory)...
Qed.
Lemma CRpos_opp' x: CRneg (-x) -> CRpos x.
Proof with auto.
intros.
apply (@CRpos_wd (--x)).
apply (Ropp_opp t3 CR_ring_eq_ext CR_ring_theory).
apply CRpos_opp...
Qed.
Lemma t6 x y: CRneg (x - y) -> CRpos (y - x).
Proof with auto.
intros.
apply CRpos_opp'.
apply CRneg_wd with (x - y)...
apply diff_opp.
Qed.
Import PowerSeries.
Import Exponential.
Lemma exp_sum a b: exp (a + b) == exp a * exp b.
intros.
rewrite <- (CRasIRasCR_id a).
rewrite <- (CRasIRasCR_id b).
rewrite <- IR_plus_as_CR.
do 3 rewrite <- exp_correct.
rewrite <- IR_mult_as_CR.
apply IRasCR_wd.
apply Exp_plus.
Qed.
Lemma blo x y: x < y -> x < IRasCR (CRasIR y).
intros.
apply CRlt_wd with x y.
assumption.
reflexivity.
symmetry.
apply CRasIRasCR_id.
Qed.
Lemma CRln_expand a p: CRln a p == CRln (IRasCR (CRasIR a)) (blo p).
Proof. intros. apply CRln_wd. symmetry. apply CRasIRasCR_id. Qed.
Lemma CR_mult_as_IR (x y: CR): CRasIR (x * y) [=] CRasIR x [*] CRasIR y.
Proof with auto.
intros.
transitivity (CRasIR (IRasCR (CRasIR x) * IRasCR (CRasIR y))).
apply CRasIR_wd.
repeat rewrite CRasIRasCR_id.
reflexivity.
transitivity (CRasIR (IRasCR (CRasIR x [*] CRasIR y))).
apply CRasIR_wd.
rewrite <- IR_mult_as_CR.
reflexivity.
apply IRasCRasIR_id.
Qed. (* this is an extra-awful proof *)
Lemma CRln_mult a b p q r: CRln (a * b) r == CRln a p + CRln b q.
Proof with auto.
intros.
assert ([0] [<] CRasIR a).
apply CR_less_as_IR.
apply CRlt_wd with 0 a...
symmetry. apply IR_Zero_as_CR.
symmetry. apply CRasIRasCR_id.
assert ([0] [<] CRasIR b).
apply CR_less_as_IR.
apply CRlt_wd with 0 b...
symmetry. apply IR_Zero_as_CR.
symmetry. apply CRasIRasCR_id.
assert ([0] [<] CRasIR (a * b)).
apply CR_less_as_IR.
apply CRlt_wd with 0 (a * b)...
symmetry. apply IR_Zero_as_CR.
symmetry. apply CRasIRasCR_id.
rewrite (CRln_expand p).
rewrite (CRln_expand q).
rewrite CRln_expand at 1.
rewrite <- (CRln_correct (CRasIR (a * b)) X1).
rewrite <- (CRln_correct (CRasIR a) X).
rewrite <- (CRln_correct (CRasIR b) X0).
rewrite <- IR_plus_as_CR.
apply IRasCR_wd.
assert ([0] [<] CRasIR a [*] CRasIR b).
apply CR_less_as_IR.
apply CRlt_wd with 0 (a * b)...
symmetry. apply IR_Zero_as_CR.
transitivity (IRasCR (CRasIR (a * b))).
symmetry. apply CRasIRasCR_id.
apply IRasCR_wd.
apply CR_mult_as_IR.
rewrite <- (Log_mult (CRasIR a) (CRasIR b) X X0 X2).
apply Log_wd.
apply CR_mult_as_IR.
Qed.
Lemma exp_0: exp 0 == 1.
rewrite <- IR_One_as_CR.
rewrite <- IR_Zero_as_CR.
rewrite <- exp_correct.
apply IRasCR_wd.
apply Exp_zero.
Qed.
Lemma exp_le_inv x y: exp x <= exp y -> x <= y.
rewrite <- (CRasIRasCR_id x).
rewrite <- (CRasIRasCR_id y).
do 2 rewrite <- exp_correct.
intros.
apply (IR_leEq_as_CR (CRasIR x) (CRasIR y)).
apply Exp_cancel_leEq.
apply <- IR_leEq_as_CR.
assumption.
Qed.
Lemma CRln_exp x p: CRln (exp x) p == x.
Proof with auto.
intros.
assert (0 < exp (IRasCR (CRasIR x))).
apply CRlt_wd with 0 (exp x)...
reflexivity.
rewrite (CRasIRasCR_id x).
reflexivity.
assert (exp x == IRasCR (Exp (CRasIR x))).
rewrite exp_correct.
apply exp_wd.
symmetry.
apply CRasIRasCR_id.
assert (0 < IRasCR (Exp (CRasIR x))).
apply CRlt_wd with 0 (exp x)...
reflexivity.
rewrite (CRln_wd p H).
rewrite (CRln_wd H H1).
assert ([0] [<] Exp (CRasIR x)).
apply CR_less_as_IR.
apply CRlt_wd with 0 (exp x)...
rewrite IR_Zero_as_CR. reflexivity.
rewrite <- (CRln_correct (Exp (CRasIR x)) X).
rewrite <- (CRasIRasCR_id x) at 2.
apply IRasCR_wd.
apply Log_Exp.
rewrite <- exp_correct.
reflexivity.
apply exp_wd.
symmetry.
apply CRasIRasCR_id.
Qed.
Lemma exp_ln x p: exp (CRln x p) == x.
Proof with auto.
intros.
assert (0 < IRasCR (CRasIR x)).
apply CRlt_wd with 0 x...
reflexivity.
symmetry. apply CRasIRasCR_id.
assert (CRln x p == CRln _ H).
apply CRln_wd. symmetry. apply CRasIRasCR_id.
rewrite (exp_wd H0).
assert ([0] [<] CRasIR x).
apply CR_less_as_IR.
apply CRlt_wd with 0 x...
rewrite IR_Zero_as_CR. reflexivity.
symmetry. apply CRasIRasCR_id.
rewrite <- (CRln_correct (CRasIR x) X).
rewrite <- exp_correct.
rewrite <- (CRasIRasCR_id x) at 2.
apply IRasCR_wd.
apply Exp_Log.
Qed.
Lemma CRpos_plus x y: CRpos x -> CRnonNeg y -> CRpos (x + y).
Proof with auto.
intros.
unfold CRpos.
destruct H.
exists x0.
unfold CRle in *.
rewrite (Radd_comm CR_ring_theory x).
rewrite <- (Radd_assoc CR_ring_theory).
apply t10...
Qed.
Lemma CRlt_le_trans: forall x y, x < y -> forall z, y <= z -> x < z.
Proof with auto.
intros x y A z B.
unfold CRltT in *.
unfold CRle in *.
apply CRpos_wd with (y - x + (z - y)).
rewrite <- (Radd_assoc CR_ring_theory).
rewrite (Radd_assoc CR_ring_theory (-x)).
rewrite <- t11.
apply (Radd_comm CR_ring_theory).
apply CRpos_plus...
Qed.
(*
Definition Qpos_div (a b: Qpos): Qpos :=
match a, b with
| QposMake aNum aDen, QposMake bNum bDen =>
QposMake (aNum * bDen) (aDen * bNum)
end.
*)
Lemma CRln_le x y p q: x <= y -> CRln x p <= CRln y q.
Proof with auto.
intros.
set (CRasIRasCR_id x). symmetry in s.
set (CRasIRasCR_id y). symmetry in s0.
assert (0 < IRasCR (CRasIR x)).
apply CRlt_wd with (0) x... reflexivity.
assert (0 < IRasCR (CRasIR y)).
apply CRlt_wd with (0) y... reflexivity.
rewrite (CRln_wd p H0 s).
rewrite (CRln_wd q H1 s0).
assert ([0] [<] CRasIR x).
apply CR_less_as_IR.
apply CRlt_wd with (0) x...
symmetry. apply IR_Zero_as_CR.
assert ([0] [<] CRasIR y).
apply CR_less_as_IR.
apply CRlt_wd with (0) y...
symmetry. apply IR_Zero_as_CR.
rewrite <- (CRln_correct _ X H0).
rewrite <- (CRln_correct _ X0 H1).
apply -> IR_leEq_as_CR.
apply Log_resp_leEq.
apply <- IR_leEq_as_CR.
do 2 rewrite CRasIRasCR_id.
assumption.
Qed.
Lemma CRle_mult x: 0 <= x -> forall a b, a <= b -> x * a <= x * b.
Proof with auto.
intros.
unfold CRle in *.
rewrite (Rmul_comm CR_ring_theory x a).
rewrite CRopp_mult_l.
rewrite (Rmul_comm CR_ring_theory x b).
rewrite <- (Rdistr_l CR_ring_theory).
apply CRnonNeg_mult...
rewrite <- (CRminus_zero x)...
Qed.
Lemma CRle_mult_both_sides x y: 0 <= x -> x <= y ->
forall a b, 0 <= a -> a <= b -> x * a <= y * b.
Proof with auto.
intros.
apply CRle_trans with (x * b).
apply CRle_mult...
rewrite (Rmul_comm CR_ring_theory x b).
rewrite (Rmul_comm CR_ring_theory y b).
apply CRle_mult...
apply CRle_trans with a...
Qed.
(*
Lemma bah: forall x y, 0 < x * y -> 0 < x -> 0 < y.
Proof with auto.
intros.
apply (mult_cancel_less CRasCOrdField (0) y x).
assumption.
simpl.
apply CRlt_wd with ('0) (x * y)...
apply (@Rmul_0_l _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory x).
apply (Rmul_comm CR_ring_theory).
Defined.
*)
Lemma CRle_opp_inv: forall x y, -x <= -y -> y <= x.
unfold CRle.
intros.
rewrite (@Ropp_opp _ _ _ _ _ _ _ _ t3 CR_ring_eq_ext CR_ring_theory) in H.
rewrite (Radd_comm CR_ring_theory).
assumption.
Defined.
Lemma CRlt_irrefl: forall x: CR, Not (x < x).
Proof less_irreflexive_unfolded CRasCOrdField.
Lemma CRlt_asym: forall x y: CR, x < y -> Not (y < x).
Proof less_antisymmetric_unfolded CRasCOrdField.
Definition st_eq_refl X x: @st_eq X x x. reflexivity. Qed.
Hint Immediate st_eq_refl.
Hint Resolve CRlt_le.
Lemma CRlt_le_asym x y: x < y -> y <= x -> False.
Proof with auto.
repeat intro.
apply CRlt_irrefl with y, CRlt_wd with x y...
apply <- CRle_def...
Qed.
Lemma CRln_opp_mult x y P Q R (S: 0 < -x * y):
CRln (- (x * y)) P == CRln (-x) Q + CRln y R.
Proof.
intros.
rewrite <- (@CRln_mult (-x) y Q R S).
apply CRln_wd, CRopp_mult_l.
Qed.
Definition CR_sign_dec (e: Qpos) (x: CR): option (CRpos x + CRneg x) :=
let a := approximate x e in
match Qle_total a (2 * e), Qle_total (- (2) * e) a with
| right q, _ => Some (inl (CRpos_char e x q))
| _, right q => Some (inr (CRneg_char e x q ))
| left _, left _ => None
end.
Lemma CRdiv_Qdiv (a b: Qpos):
'(a / b)%Qpos == 'a * CRinvT (' b) (inr (CRpos_lt_0_rev (Qpos_CRpos b))).
Proof with auto.
intros.
rewrite <- (CRmult_Qmult a (Qpos_inv b)).
apply CRmult_wd...
symmetry.
apply CRinv_Qinv.
Qed.
Lemma CRinvT_le (x y: CR) xH yH: CRpos x -> x <= y -> CRinvT y yH <= CRinvT x xH.
Proof with auto.
simpl.
intros.
assert (IRasCR (CRasIR x) >< 0).
apply CRapartT_wd with x (0)...
symmetry. apply CRasIRasCR_id.
assert (IRasCR (CRasIR y) >< 0).
apply CRapartT_wd with y (0)...
symmetry. apply CRasIRasCR_id.
rewrite (@CRinvT_wd x (IRasCR (CRasIR x)) _ H1).
rewrite (@CRinvT_wd y (IRasCR (CRasIR y)) _ H2).
do 2 rewrite <- IR_recip_as_CR_2.
apply -> IR_leEq_as_CR.
apply recip_resp_leEq.
apply CR_less_as_IR.
apply CRlt_wd with (0) (IRasCR (CRasIR x))...
apply CRlt_wd with (0) x...
apply CRpos_lt_0_rev...
symmetry. apply CRasIRasCR_id.
symmetry. apply IR_Zero_as_CR.
apply <- IR_leEq_as_CR...
apply <- (CRle_wd (CRasIRasCR_id x) (CRasIRasCR_id y))...
symmetry. apply CRasIRasCR_id.
symmetry. apply CRasIRasCR_id.
Qed.
Lemma CRinv_le: forall (x y: canonical_names.ApartZero CR), CRpos (` x) -> `x <= `y -> CRinv y <= CRinv x.
Proof with auto.
intros [x xH] [y yH].
unfold CRinv.
apply CRinvT_le.
Qed.
Lemma CRinvT_mult x xH: x * CRinvT x xH == 1.
Proof with auto.
assert (IRasCR (CRasIR x) >< 0).
apply CRapartT_wd with x 0...
symmetry. apply CRasIRasCR_id.
rewrite <- (@CRinvT_wd (IRasCR (CRasIR x)) x H).
rewrite <- IR_recip_as_CR_2.
rewrite <- (CRasIRasCR_id x) at 1.
rewrite <- IR_mult_as_CR.
rewrite <- IR_One_as_CR.
apply -> IR_eq_as_CR.
unfold cf_div.
rewrite (ax_mult_assoc _ _ _ (cr_proof IR)).
rewrite (runit _ _ (ax_mult_mon _ _ _ (cr_proof IR)) (CRasIR x)).
apply x_div_x.
apply CRasIRasCR_id.
Qed.
Lemma CRinv_mult (x: canonical_names.ApartZero CR): `x * CRinv x == 1.
Proof. apply CRinvT_mult. Qed.
Instance: Proper (@canonical_names.sig_equiv _ _ _ ==> @st_eq _) CRinv.
Proof.
intros [??] [??] ?.
unfold CRinv.
apply CRinvT_wd.
assumption.
Qed.
Lemma fold_CRinvT (x: CR) (p: x >< 0): CRinvT x p == CRinv (exist _ x (snd (CR_apart_apartT x 0) p)).
Proof.
unfold CRinv.
simpl proj1_sig.
apply CRinvT_wd.
reflexivity.
Qed.
Lemma CRinvT_pos: forall x p, CRpos x -> CRpos (CRinvT x p).
Proof with auto.
intros.
exists (Qpos_inv (CR_b (1#1) x)).
rewrite Q_Qpos_inv.
assert ('(CR_b (1#1) x) >< 0).
right. apply CRpos_lt_0_rev. apply Qpos_CRpos.
rewrite <- (CRinv_Qinv _ H0).
rewrite fold_CRinvT.
unfold CRinv.
apply CRinvT_le...
apply CR_b_upperBound.
Qed.
Lemma CRinv_pos: forall x, CRpos (`x) -> CRpos (CRinv x).
Proof with auto.
intros.
unfold CRinv.
apply CRinvT_pos...
Qed.
(* todo: *)
Axiom exp_pos: forall x: CR, 0 < exp x.
Axiom exp_opp_ln: forall x xp, x * exp (- CRln x xp) == 1.
Axiom CRmult_le_compat_r: forall x y, x <= y -> forall z, CRnonNeg z -> z * x <= z * y.
Axiom CRmult_le_inv: forall x, CRnonNeg x -> forall a b, x * a <= x * b -> a <= b.
Lemma CRpos_mult_inv: forall y, CRpos y -> forall x, CRpos (x * y) -> CRpos x.
Proof with try assumption.
intros.
set (yu := CR_b ((1#1)%Qpos) y).
destruct H0 as [mq H0].
exists ((mq / yu)%Qpos).
rewrite CRdiv_Qdiv.
apply CRle_trans with (x * y * CRinvT y (inr (CRpos_lt_0_rev H))).
apply CRle_mult_both_sides...
apply t4.
rewrite CRinv_Qinv.
apply <- CRle_Qle.
apply Qinv_le_0_compat.
apply Qpos_nonneg.
apply CRinvT_le...
apply CR_b_upperBound.
rewrite <- (Rmul_assoc CR_ring_theory).
rewrite CRinvT_mult.
rewrite (Rmul_comm CR_ring_theory).
rewrite (Rmul_1_l CR_ring_theory).
apply CRle_refl.
Qed.
Lemma exp_pos' x: CRpos (exp x).
intros. apply CRpos_lt_0, exp_pos.
Defined.
Definition weak_CRlt_decision (f: (CR -> CR -> Set) -> Set): Set :=
option (sum (f CRlt) (f (fun x y => y < x))).
Definition weak_CRle_decision (f: (CR -> CR -> Prop) -> Prop): Set :=
option ({f CRle}+{f (fun x y => y <= x)}).
Definition NonNegCR: Type := sig CRnonNeg.
Program Definition NonNegCR_plus (n n': NonNegCR): NonNegCR := n + n'.
Next Obligation.
destruct n. destruct n'.
simpl. apply t10; assumption.
Qed.
Definition NonNegCR_zero: NonNegCR := exist _ _ CRnonNeg_zero.
Lemma CRnonPos_nonNeg x: CRnonPos x -> CRnonNeg (-x).
unfold CRnonPos, CRnonNeg.
intros. simpl. apply Qopp_le_compat. auto.
Qed.
Lemma CRnonNeg_nonPos_mult_inv: forall x (p: CRnonNeg x) y,
CRnonPos (x * y) -> CRnonPos y.
Proof with auto.
Admitted.
Lemma CRnonPos_le_0 x: CRnonPos x -> x <= 0.
Proof with auto.
intros.
apply (@CRnonNeg_wd (0 - x) (-x)).
apply (Radd_0_l CR_ring_theory).
apply CRnonPos_nonNeg...
Qed.
Lemma CRnonPos_not_pos x: CRnonPos x -> CRpos x -> False.
Proof with auto.
intros.
apply CRlt_le_asym with (0) x.
apply CRpos_lt_0_rev...
apply CRnonPos_le_0...
Qed.
Lemma CRnonNeg_not_neg x: CRnonNeg x -> CRneg x -> False.
Proof with auto.
intros.
apply CRnonPos_not_pos with (-x).
apply CRnonNeg_nonPos...
apply CRpos_opp...
Qed.
Lemma CRneg_pos_excl x: CRpos x -> CRneg x -> False.
Proof with auto.
intros.
apply CRnonPos_not_pos with x...
apply CRneg_nonPos...
Qed.
Lemma CRneg_lt_0 x: x < 0 -> CRneg x.
unfold CRlt.
intros.
apply CRneg_opp.
apply CRpos_wd with (0 - x).
rewrite (Radd_comm CR_ring_theory).
apply CRadd_0_r.
assumption.
Qed.
Definition CRle_lt_dec: forall x y, DN ((x <= y) + (y < x)).
Proof with auto.
intros.
apply (DN_fmap (@DN_decisionT (y < x))).
intros [A | B]...
left.
apply (leEq_def CRasCOrdField x y)...
Qed.
Implicit Arguments CRle_lt_dec [].
Definition CRnonNeg_or_pos: forall x, DN (CRnonNeg x + CRneg x).
Proof with auto.
intros.
apply (DN_fmap (CRle_lt_dec 0 x)).
intro.
destruct H; [left | right].
apply <- CRnonNeg_le_zero...
apply CRneg_lt_0...
Qed.
Definition CRle_cases: forall x y: CR, x <= y -> DN ((x < y) + (x == y))
:= leEq_less_or_equal CRasCOrdField.
Definition CRle_dec: forall (x y: CR), DN ((x<=y) + (y<=x)).
Proof. intros. apply (DN_fmap (CRle_lt_dec x y)). intros [A | B]; auto. Qed.
Implicit Arguments CRle_dec [].
Lemma CR_trichotomy x y: DN ((x == y) + ((x < y) + (y < x))).