forked from jrh13/hol-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
real.ml
1993 lines (1645 loc) · 69 KB
/
real.ml
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
(* ========================================================================= *)
(* More basic properties of the reals. *)
(* *)
(* John Harrison, University of Cambridge Computer Laboratory *)
(* *)
(* (c) Copyright, University of Cambridge 1998 *)
(* (c) Copyright, John Harrison 1998-2007 *)
(* (c) Copyright, Valentina Bruno 2010 *)
(* ========================================================================= *)
needs "realarith.ml";;
(* ------------------------------------------------------------------------- *)
(* Additional commutativity properties of the inclusion map. *)
(* ------------------------------------------------------------------------- *)
let REAL_OF_NUM_LT = prove
(`!m n. &m < &n <=> m < n`,
REWRITE_TAC[real_lt; GSYM NOT_LE; REAL_OF_NUM_LE]);;
let REAL_OF_NUM_GE = prove
(`!m n. &m >= &n <=> m >= n`,
REWRITE_TAC[GE; real_ge; REAL_OF_NUM_LE]);;
let REAL_OF_NUM_GT = prove
(`!m n. &m > &n <=> m > n`,
REWRITE_TAC[GT; real_gt; REAL_OF_NUM_LT]);;
let REAL_OF_NUM_MAX = prove
(`!m n. max (&m) (&n) = &(MAX m n)`,
REWRITE_TAC[REAL_OF_NUM_LE; MAX; real_max; GSYM COND_RAND]);;
let REAL_OF_NUM_MIN = prove
(`!m n. min (&m) (&n) = &(MIN m n)`,
REWRITE_TAC[REAL_OF_NUM_LE; MIN; real_min; GSYM COND_RAND]);;
let REAL_OF_NUM_SUC = prove
(`!n. &n + &1 = &(SUC n)`,
REWRITE_TAC[ADD1; REAL_OF_NUM_ADD]);;
let REAL_OF_NUM_SUB = prove
(`!m n. m <= n ==> (&n - &m = &(n - m))`,
REPEAT GEN_TAC THEN REWRITE_TAC[LE_EXISTS] THEN
STRIP_TAC THEN ASM_REWRITE_TAC[ADD_SUB2] THEN
REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN
ONCE_REWRITE_TAC[REAL_ADD_SYM] THEN
REWRITE_TAC[real_sub; GSYM REAL_ADD_ASSOC] THEN
MESON_TAC[REAL_ADD_LINV; REAL_ADD_SYM; REAL_ADD_LID]);;
let REAL_OF_NUM_SUB_CASES = prove
(`!m n. &m - &n = if n <= m then &(m - n) else -- &(n - m)`,
REPEAT GEN_TAC THEN COND_CASES_TAC THEN ASM_SIMP_TAC[REAL_OF_NUM_SUB] THEN
GEN_REWRITE_TAC LAND_CONV [GSYM REAL_NEG_SUB] THEN AP_TERM_TAC THEN
MATCH_MP_TAC REAL_OF_NUM_SUB THEN ASM_MESON_TAC[LE_CASES]);;
let REAL_OF_NUM_CLAUSES = prove
(`(!m n. &m:real = &n <=> m = n) /\
(!m n. &m:real >= &n <=> m >= n) /\
(!m n. &m:real > &n <=> m > n) /\
(!m n. &m:real <= &n <=> m <= n) /\
(!m n. &m:real < &n <=> m < n) /\
(!m n. max (&m) (&n):real = &(MAX m n)) /\
(!m n. min (&m) (&n):real = &(MIN m n)) /\
(!m n. &m + &n:real = &(m + n)) /\
(!m n. &m * &n:real = &(m * n)) /\
(!x n. (&x:real) pow n = &(x EXP n))`,
REWRITE_TAC[REAL_OF_NUM_EQ; REAL_OF_NUM_GE; REAL_OF_NUM_GT;
REAL_OF_NUM_LE; REAL_OF_NUM_LT; REAL_OF_NUM_MAX;
REAL_OF_NUM_MIN; REAL_OF_NUM_ADD; REAL_OF_NUM_MUL;
REAL_OF_NUM_POW]);;
(* ------------------------------------------------------------------------- *)
(* A few theorems we need to prove explicitly for later. *)
(* ------------------------------------------------------------------------- *)
let REAL_MUL_AC = prove
(`(m * n = n * m) /\
((m * n) * p = m * (n * p)) /\
(m * (n * p) = n * (m * p))`,
REWRITE_TAC[REAL_MUL_ASSOC; EQT_INTRO(SPEC_ALL REAL_MUL_SYM)] THEN
AP_THM_TAC THEN AP_TERM_TAC THEN MATCH_ACCEPT_TAC REAL_MUL_SYM);;
let REAL_ADD_RDISTRIB = prove
(`!x y z. (x + y) * z = x * z + y * z`,
MESON_TAC[REAL_MUL_SYM; REAL_ADD_LDISTRIB]);;
let REAL_LT_LADD_IMP = prove
(`!x y z. y < z ==> x + y < x + z`,
REPEAT GEN_TAC THEN CONV_TAC CONTRAPOS_CONV THEN
REWRITE_TAC[real_lt] THEN
DISCH_THEN(MP_TAC o MATCH_MP REAL_LE_LADD_IMP) THEN
DISCH_THEN(MP_TAC o SPEC `--x`) THEN
REWRITE_TAC[REAL_ADD_ASSOC; REAL_ADD_LINV; REAL_ADD_LID]);;
let REAL_LT_MUL = prove
(`!x y. &0 < x /\ &0 < y ==> &0 < x * y`,
REPEAT GEN_TAC THEN REWRITE_TAC[REAL_LT_LE] THEN
CONV_TAC(ONCE_DEPTH_CONV SYM_CONV) THEN
STRIP_TAC THEN ASM_REWRITE_TAC[REAL_ENTIRE] THEN
MATCH_MP_TAC REAL_LE_MUL THEN ASM_REWRITE_TAC[]);;
(* ------------------------------------------------------------------------- *)
(* Tactic version of REAL_ARITH. *)
(* ------------------------------------------------------------------------- *)
let REAL_ARITH_TAC = CONV_TAC REAL_ARITH;;
(* ------------------------------------------------------------------------- *)
(* Prove all the linear theorems we can blow away automatically. *)
(* ------------------------------------------------------------------------- *)
let REAL_EQ_ADD_LCANCEL_0 = prove
(`!x y. (x + y = x) <=> (y = &0)`,
REAL_ARITH_TAC);;
let REAL_EQ_ADD_RCANCEL_0 = prove
(`!x y. (x + y = y) <=> (x = &0)`,
REAL_ARITH_TAC);;
let REAL_LNEG_UNIQ = prove
(`!x y. (x + y = &0) <=> (x = --y)`,
REAL_ARITH_TAC);;
let REAL_RNEG_UNIQ = prove
(`!x y. (x + y = &0) <=> (y = --x)`,
REAL_ARITH_TAC);;
let REAL_NEG_LMUL = prove
(`!x y. --(x * y) = (--x) * y`,
REAL_ARITH_TAC);;
let REAL_NEG_RMUL = prove
(`!x y. --(x * y) = x * (--y)`,
REAL_ARITH_TAC);;
let REAL_NEG_MUL2 = prove
(`!x y. (--x) * (--y) = x * y`,
REAL_ARITH_TAC);;
let REAL_LT_LADD = prove
(`!x y z. (x + y) < (x + z) <=> y < z`,
REAL_ARITH_TAC);;
let REAL_LT_RADD = prove
(`!x y z. (x + z) < (y + z) <=> x < y`,
REAL_ARITH_TAC);;
let REAL_LT_ANTISYM = prove
(`!x y. ~(x < y /\ y < x)`,
REAL_ARITH_TAC);;
let REAL_LT_GT = prove
(`!x y. x < y ==> ~(y < x)`,
REAL_ARITH_TAC);;
let REAL_NOT_EQ = prove
(`!x y. ~(x = y) <=> x < y \/ y < x`,
REAL_ARITH_TAC);;
let REAL_NOT_LE = prove
(`!x y. ~(x <= y) <=> y < x`,
REAL_ARITH_TAC);;
let REAL_LET_ANTISYM = prove
(`!x y. ~(x <= y /\ y < x)`,
REAL_ARITH_TAC);;
let REAL_NEG_LT0 = prove
(`!x. (--x) < &0 <=> &0 < x`,
REAL_ARITH_TAC);;
let REAL_NEG_GT0 = prove
(`!x. &0 < (--x) <=> x < &0`,
REAL_ARITH_TAC);;
let REAL_NEG_LE0 = prove
(`!x. (--x) <= &0 <=> &0 <= x`,
REAL_ARITH_TAC);;
let REAL_NEG_GE0 = prove
(`!x. &0 <= (--x) <=> x <= &0`,
REAL_ARITH_TAC);;
let REAL_LT_TOTAL = prove
(`!x y. (x = y) \/ x < y \/ y < x`,
REAL_ARITH_TAC);;
let REAL_LT_NEGTOTAL = prove
(`!x. (x = &0) \/ (&0 < x) \/ (&0 < --x)`,
REAL_ARITH_TAC);;
let REAL_LE_01 = prove
(`&0 <= &1`,
REAL_ARITH_TAC);;
let REAL_LT_01 = prove
(`&0 < &1`,
REAL_ARITH_TAC);;
let REAL_LE_LADD = prove
(`!x y z. (x + y) <= (x + z) <=> y <= z`,
REAL_ARITH_TAC);;
let REAL_LE_RADD = prove
(`!x y z. (x + z) <= (y + z) <=> x <= y`,
REAL_ARITH_TAC);;
let REAL_LT_ADD2 = prove
(`!w x y z. w < x /\ y < z ==> (w + y) < (x + z)`,
REAL_ARITH_TAC);;
let REAL_LE_ADD2 = prove
(`!w x y z. w <= x /\ y <= z ==> (w + y) <= (x + z)`,
REAL_ARITH_TAC);;
let REAL_LT_LNEG = prove
(`!x y. --x < y <=> &0 < x + y`,
REWRITE_TAC[real_lt; REAL_LE_RNEG; REAL_ADD_AC]);;
let REAL_LT_RNEG = prove
(`!x y. x < --y <=> x + y < &0`,
REWRITE_TAC[real_lt; REAL_LE_LNEG; REAL_ADD_AC]);;
let REAL_LT_ADDNEG = prove
(`!x y z. y < (x + (--z)) <=> (y + z) < x`,
REAL_ARITH_TAC);;
let REAL_LT_ADDNEG2 = prove
(`!x y z. (x + (--y)) < z <=> x < (z + y)`,
REAL_ARITH_TAC);;
let REAL_LT_ADD1 = prove
(`!x y. x <= y ==> x < (y + &1)`,
REAL_ARITH_TAC);;
let REAL_SUB_ADD = prove
(`!x y. (x - y) + y = x`,
REAL_ARITH_TAC);;
let REAL_SUB_ADD2 = prove
(`!x y. y + (x - y) = x`,
REAL_ARITH_TAC);;
let REAL_SUB_REFL = prove
(`!x. x - x = &0`,
REAL_ARITH_TAC);;
let REAL_LE_DOUBLE = prove
(`!x. &0 <= x + x <=> &0 <= x`,
REAL_ARITH_TAC);;
let REAL_LE_NEGL = prove
(`!x. (--x <= x) <=> (&0 <= x)`,
REAL_ARITH_TAC);;
let REAL_LE_NEGR = prove
(`!x. (x <= --x) <=> (x <= &0)`,
REAL_ARITH_TAC);;
let REAL_NEG_EQ_0 = prove
(`!x. (--x = &0) <=> (x = &0)`,
REAL_ARITH_TAC);;
let REAL_ADD_SUB = prove
(`!x y. (x + y) - x = y`,
REAL_ARITH_TAC);;
let REAL_NEG_EQ = prove
(`!x y. (--x = y) <=> (x = --y)`,
REAL_ARITH_TAC);;
let REAL_NEG_MINUS1 = prove
(`!x. --x = (--(&1)) * x`,
REAL_ARITH_TAC);;
let REAL_LT_IMP_NE = prove
(`!x y. x < y ==> ~(x = y)`,
REAL_ARITH_TAC);;
let REAL_LE_ADDR = prove
(`!x y. x <= x + y <=> &0 <= y`,
REAL_ARITH_TAC);;
let REAL_LE_ADDL = prove
(`!x y. y <= x + y <=> &0 <= x`,
REAL_ARITH_TAC);;
let REAL_LT_ADDR = prove
(`!x y. x < x + y <=> &0 < y`,
REAL_ARITH_TAC);;
let REAL_LT_ADDL = prove
(`!x y. y < x + y <=> &0 < x`,
REAL_ARITH_TAC);;
let REAL_SUB_SUB = prove
(`!x y. (x - y) - x = --y`,
REAL_ARITH_TAC);;
let REAL_LT_ADD_SUB = prove
(`!x y z. (x + y) < z <=> x < (z - y)`,
REAL_ARITH_TAC);;
let REAL_LT_SUB_RADD = prove
(`!x y z. (x - y) < z <=> x < z + y`,
REAL_ARITH_TAC);;
let REAL_LT_SUB_LADD = prove
(`!x y z. x < (y - z) <=> (x + z) < y`,
REAL_ARITH_TAC);;
let REAL_LE_SUB_LADD = prove
(`!x y z. x <= (y - z) <=> (x + z) <= y`,
REAL_ARITH_TAC);;
let REAL_LE_SUB_RADD = prove
(`!x y z. (x - y) <= z <=> x <= z + y`,
REAL_ARITH_TAC);;
let REAL_ADD2_SUB2 = prove
(`!a b c d. (a + b) - (c + d) = (a - c) + (b - d)`,
REAL_ARITH_TAC);;
let REAL_SUB_LZERO = prove
(`!x. &0 - x = --x`,
REAL_ARITH_TAC);;
let REAL_SUB_RZERO = prove
(`!x. x - &0 = x`,
REAL_ARITH_TAC);;
let REAL_LET_ADD2 = prove
(`!w x y z. w <= x /\ y < z ==> (w + y) < (x + z)`,
REAL_ARITH_TAC);;
let REAL_LTE_ADD2 = prove
(`!w x y z. w < x /\ y <= z ==> w + y < x + z`,
REAL_ARITH_TAC);;
let REAL_SUB_LNEG = prove
(`!x y. (--x) - y = --(x + y)`,
REAL_ARITH_TAC);;
let REAL_SUB_RNEG = prove
(`!x y. x - (--y) = x + y`,
REAL_ARITH_TAC);;
let REAL_SUB_NEG2 = prove
(`!x y. (--x) - (--y) = y - x`,
REAL_ARITH_TAC);;
let REAL_SUB_TRIANGLE = prove
(`!a b c. (a - b) + (b - c) = a - c`,
REAL_ARITH_TAC);;
let REAL_EQ_SUB_LADD = prove
(`!x y z. (x = y - z) <=> (x + z = y)`,
REAL_ARITH_TAC);;
let REAL_EQ_SUB_RADD = prove
(`!x y z. (x - y = z) <=> (x = z + y)`,
REAL_ARITH_TAC);;
let REAL_SUB_SUB2 = prove
(`!x y. x - (x - y) = y`,
REAL_ARITH_TAC);;
let REAL_ADD_SUB2 = prove
(`!x y. x - (x + y) = --y`,
REAL_ARITH_TAC);;
let REAL_EQ_IMP_LE = prove
(`!x y. (x = y) ==> x <= y`,
REAL_ARITH_TAC);;
let REAL_LT_IMP_NZ = prove
(`!x. &0 < x ==> ~(x = &0)`,
REAL_ARITH_TAC);;
let REAL_DIFFSQ = prove
(`!x y. (x + y) * (x - y) = (x * x) - (y * y)`,
REAL_ARITH_TAC);;
let REAL_EQ_NEG2 = prove
(`!x y. (--x = --y) <=> (x = y)`,
REAL_ARITH_TAC);;
let REAL_LT_NEG2 = prove
(`!x y. --x < --y <=> y < x`,
REAL_ARITH_TAC);;
let REAL_SUB_LDISTRIB = prove
(`!x y z. x * (y - z) = x * y - x * z`,
REAL_ARITH_TAC);;
let REAL_SUB_RDISTRIB = prove
(`!x y z. (x - y) * z = x * z - y * z`,
REAL_ARITH_TAC);;
(* ------------------------------------------------------------------------- *)
(* Theorems about "abs". *)
(* ------------------------------------------------------------------------- *)
let REAL_ABS_ZERO = prove
(`!x. (abs(x) = &0) <=> (x = &0)`,
REAL_ARITH_TAC);;
let REAL_ABS_0 = prove
(`abs(&0) = &0`,
REAL_ARITH_TAC);;
let REAL_ABS_1 = prove
(`abs(&1) = &1`,
REAL_ARITH_TAC);;
let REAL_ABS_TRIANGLE = prove
(`!x y. abs(x + y) <= abs(x) + abs(y)`,
REAL_ARITH_TAC);;
let REAL_ABS_TRIANGLE_LE = prove
(`!x y z.abs(x) + abs(y - x) <= z ==> abs(y) <= z`,
REAL_ARITH_TAC);;
let REAL_ABS_TRIANGLE_LT = prove
(`!x y z.abs(x) + abs(y - x) < z ==> abs(y) < z`,
REAL_ARITH_TAC);;
let REAL_ABS_POS = prove
(`!x. &0 <= abs(x)`,
REAL_ARITH_TAC);;
let REAL_ABS_SUB = prove
(`!x y. abs(x - y) = abs(y - x)`,
REAL_ARITH_TAC);;
let REAL_ABS_NZ = prove
(`!x. ~(x = &0) <=> &0 < abs(x)`,
REAL_ARITH_TAC);;
let REAL_ABS_ABS = prove
(`!x. abs(abs(x)) = abs(x)`,
REAL_ARITH_TAC);;
let REAL_ABS_LE = prove
(`!x. x <= abs(x)`,
REAL_ARITH_TAC);;
let REAL_ABS_REFL = prove
(`!x. (abs(x) = x) <=> &0 <= x`,
REAL_ARITH_TAC);;
let REAL_ABS_BETWEEN = prove
(`!x y d. &0 < d /\ ((x - d) < y) /\ (y < (x + d)) <=> abs(y - x) < d`,
REAL_ARITH_TAC);;
let REAL_ABS_BOUND = prove
(`!x y d. abs(x - y) < d ==> y < (x + d)`,
REAL_ARITH_TAC);;
let REAL_ABS_STILLNZ = prove
(`!x y. abs(x - y) < abs(y) ==> ~(x = &0)`,
REAL_ARITH_TAC);;
let REAL_ABS_CASES = prove
(`!x. (x = &0) \/ &0 < abs(x)`,
REAL_ARITH_TAC);;
let REAL_ABS_BETWEEN1 = prove
(`!x y z. x < z /\ (abs(y - x)) < (z - x) ==> y < z`,
REAL_ARITH_TAC);;
let REAL_ABS_SIGN = prove
(`!x y. abs(x - y) < y ==> &0 < x`,
REAL_ARITH_TAC);;
let REAL_ABS_SIGN2 = prove
(`!x y. abs(x - y) < --y ==> x < &0`,
REAL_ARITH_TAC);;
let REAL_ABS_CIRCLE = prove
(`!x y h. abs(h) < (abs(y) - abs(x)) ==> abs(x + h) < abs(y)`,
REAL_ARITH_TAC);;
let REAL_SUB_ABS = prove
(`!x y. (abs(x) - abs(y)) <= abs(x - y)`,
REAL_ARITH_TAC);;
let REAL_ABS_SUB_ABS = prove
(`!x y. abs(abs(x) - abs(y)) <= abs(x - y)`,
REAL_ARITH_TAC);;
let REAL_ABS_BETWEEN2 = prove
(`!x0 x y0 y. x0 < y0 /\ &2 * abs(x - x0) < (y0 - x0) /\
&2 * abs(y - y0) < (y0 - x0)
==> x < y`,
REAL_ARITH_TAC);;
let REAL_ABS_BOUNDS = prove
(`!x k. abs(x) <= k <=> --k <= x /\ x <= k`,
REAL_ARITH_TAC);;
let REAL_BOUNDS_LE = prove
(`!x k. --k <= x /\ x <= k <=> abs(x) <= k`,
REAL_ARITH_TAC);;
let REAL_BOUNDS_LT = prove
(`!x k. --k < x /\ x < k <=> abs(x) < k`,
REAL_ARITH_TAC);;
(* ------------------------------------------------------------------------- *)
(* Theorems about max and min. *)
(* ------------------------------------------------------------------------- *)
let REAL_MIN_MAX = prove
(`!x y. min x y = --(max (--x) (--y))`,
REAL_ARITH_TAC);;
let REAL_MAX_MIN = prove
(`!x y. max x y = --(min (--x) (--y))`,
REAL_ARITH_TAC);;
let REAL_MAX_MAX = prove
(`!x y. x <= max x y /\ y <= max x y`,
REAL_ARITH_TAC);;
let REAL_MIN_MIN = prove
(`!x y. min x y <= x /\ min x y <= y`,
REAL_ARITH_TAC);;
let REAL_MAX_SYM = prove
(`!x y. max x y = max y x`,
REAL_ARITH_TAC);;
let REAL_MIN_SYM = prove
(`!x y. min x y = min y x`,
REAL_ARITH_TAC);;
let REAL_LE_MAX = prove
(`!x y z. z <= max x y <=> z <= x \/ z <= y`,
REAL_ARITH_TAC);;
let REAL_LE_MIN = prove
(`!x y z. z <= min x y <=> z <= x /\ z <= y`,
REAL_ARITH_TAC);;
let REAL_LT_MAX = prove
(`!x y z. z < max x y <=> z < x \/ z < y`,
REAL_ARITH_TAC);;
let REAL_LT_MIN = prove
(`!x y z. z < min x y <=> z < x /\ z < y`,
REAL_ARITH_TAC);;
let REAL_MAX_LE = prove
(`!x y z. max x y <= z <=> x <= z /\ y <= z`,
REAL_ARITH_TAC);;
let REAL_MIN_LE = prove
(`!x y z. min x y <= z <=> x <= z \/ y <= z`,
REAL_ARITH_TAC);;
let REAL_MAX_LT = prove
(`!x y z. max x y < z <=> x < z /\ y < z`,
REAL_ARITH_TAC);;
let REAL_MIN_LT = prove
(`!x y z. min x y < z <=> x < z \/ y < z`,
REAL_ARITH_TAC);;
let REAL_MAX_ASSOC = prove
(`!x y z. max x (max y z) = max (max x y) z`,
REAL_ARITH_TAC);;
let REAL_MIN_ASSOC = prove
(`!x y z. min x (min y z) = min (min x y) z`,
REAL_ARITH_TAC);;
let REAL_MAX_ACI = prove
(`(max x y = max y x) /\
(max (max x y) z = max x (max y z)) /\
(max x (max y z) = max y (max x z)) /\
(max x x = x) /\
(max x (max x y) = max x y)`,
REAL_ARITH_TAC);;
let REAL_MIN_ACI = prove
(`(min x y = min y x) /\
(min (min x y) z = min x (min y z)) /\
(min x (min y z) = min y (min x z)) /\
(min x x = x) /\
(min x (min x y) = min x y)`,
REAL_ARITH_TAC);;
(* ------------------------------------------------------------------------- *)
(* To simplify backchaining, just as in the natural number case. *)
(* ------------------------------------------------------------------------- *)
let REAL_LE_IMP =
let pth = PURE_ONCE_REWRITE_RULE[IMP_CONJ] REAL_LE_TRANS in
fun th -> GEN_ALL(MATCH_MP pth (SPEC_ALL th));;
let REAL_LET_IMP =
let pth = PURE_ONCE_REWRITE_RULE[IMP_CONJ] REAL_LET_TRANS in
fun th -> GEN_ALL(MATCH_MP pth (SPEC_ALL th));;
(* ------------------------------------------------------------------------- *)
(* Now a bit of nonlinear stuff. *)
(* ------------------------------------------------------------------------- *)
let REAL_ABS_MUL = prove
(`!x y. abs(x * y) = abs(x) * abs(y)`,
REPEAT GEN_TAC THEN
DISJ_CASES_TAC (SPEC `x:real` REAL_LE_NEGTOTAL) THENL
[ALL_TAC;
GEN_REWRITE_TAC (RAND_CONV o LAND_CONV) [GSYM REAL_ABS_NEG]] THEN
(DISJ_CASES_TAC (SPEC `y:real` REAL_LE_NEGTOTAL) THENL
[ALL_TAC;
GEN_REWRITE_TAC (RAND_CONV o RAND_CONV) [GSYM REAL_ABS_NEG]]) THEN
ASSUM_LIST(MP_TAC o MATCH_MP REAL_LE_MUL o end_itlist CONJ o rev) THEN
REWRITE_TAC[REAL_MUL_LNEG; REAL_MUL_RNEG; REAL_NEG_NEG] THEN DISCH_TAC THENL
[ALL_TAC;
GEN_REWRITE_TAC LAND_CONV [GSYM REAL_ABS_NEG];
GEN_REWRITE_TAC LAND_CONV [GSYM REAL_ABS_NEG];
ALL_TAC] THEN
ASM_REWRITE_TAC[real_abs; REAL_MUL_LNEG; REAL_MUL_RNEG; REAL_NEG_NEG]);;
let REAL_POW_LE = prove
(`!x n. &0 <= x ==> &0 <= x pow n`,
REPEAT STRIP_TAC THEN SPEC_TAC(`n:num`,`n:num`) THEN
INDUCT_TAC THEN REWRITE_TAC[real_pow; REAL_POS] THEN
MATCH_MP_TAC REAL_LE_MUL THEN ASM_REWRITE_TAC[]);;
let REAL_POW_LT = prove
(`!x n. &0 < x ==> &0 < x pow n`,
REPEAT STRIP_TAC THEN SPEC_TAC(`n:num`,`n:num`) THEN
INDUCT_TAC THEN REWRITE_TAC[real_pow; REAL_LT_01] THEN
MATCH_MP_TAC REAL_LT_MUL THEN ASM_REWRITE_TAC[]);;
let REAL_ABS_POW = prove
(`!x n. abs(x pow n) = abs(x) pow n`,
GEN_TAC THEN INDUCT_TAC THEN
ASM_REWRITE_TAC[real_pow; REAL_ABS_NUM; REAL_ABS_MUL]);;
let REAL_LE_LMUL = prove
(`!x y z. &0 <= x /\ y <= z ==> x * y <= x * z`,
ONCE_REWRITE_TAC[REAL_ARITH `x <= y <=> &0 <= y - x`] THEN
REWRITE_TAC[GSYM REAL_SUB_LDISTRIB; REAL_SUB_RZERO; REAL_LE_MUL]);;
let REAL_LE_RMUL = prove
(`!x y z. x <= y /\ &0 <= z ==> x * z <= y * z`,
MESON_TAC[REAL_MUL_SYM; REAL_LE_LMUL]);;
let REAL_LT_LMUL = prove
(`!x y z. &0 < x /\ y < z ==> x * y < x * z`,
ONCE_REWRITE_TAC[REAL_ARITH `x < y <=> &0 < y - x`] THEN
REWRITE_TAC[GSYM REAL_SUB_LDISTRIB; REAL_SUB_RZERO; REAL_LT_MUL]);;
let REAL_LT_RMUL = prove
(`!x y z. x < y /\ &0 < z ==> x * z < y * z`,
MESON_TAC[REAL_MUL_SYM; REAL_LT_LMUL]);;
let REAL_EQ_MUL_LCANCEL = prove
(`!x y z. (x * y = x * z) <=> (x = &0) \/ (y = z)`,
REPEAT GEN_TAC THEN
ONCE_REWRITE_TAC[REAL_ARITH `(x = y) <=> (x - y = &0)`] THEN
REWRITE_TAC[GSYM REAL_SUB_LDISTRIB; REAL_ENTIRE; REAL_SUB_RZERO]);;
let REAL_EQ_MUL_RCANCEL = prove
(`!x y z. (x * z = y * z) <=> (x = y) \/ (z = &0)`,
ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
REWRITE_TAC[REAL_EQ_MUL_LCANCEL] THEN
MESON_TAC[]);;
let REAL_MUL_LINV_UNIQ = prove
(`!x y. (x * y = &1) ==> (inv(y) = x)`,
REPEAT GEN_TAC THEN
ASM_CASES_TAC `y = &0` THEN
ASM_REWRITE_TAC[REAL_MUL_RZERO; REAL_OF_NUM_EQ; ARITH_EQ] THEN
FIRST_ASSUM(SUBST1_TAC o SYM o MATCH_MP REAL_MUL_LINV) THEN
ASM_REWRITE_TAC[REAL_EQ_MUL_RCANCEL] THEN
DISCH_THEN(ACCEPT_TAC o SYM));;
let REAL_MUL_RINV_UNIQ = prove
(`!x y. (x * y = &1) ==> (inv(x) = y)`,
ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
MATCH_ACCEPT_TAC REAL_MUL_LINV_UNIQ);;
let REAL_INV_INV = prove
(`!x. inv(inv x) = x`,
GEN_TAC THEN ASM_CASES_TAC `x = &0` THEN
ASM_REWRITE_TAC[REAL_INV_0] THEN
MATCH_MP_TAC REAL_MUL_RINV_UNIQ THEN
MATCH_MP_TAC REAL_MUL_LINV THEN
ASM_REWRITE_TAC[]);;
let REAL_EQ_INV2 = prove
(`!x y. inv(x) = inv(y) <=> x = y`,
MESON_TAC[REAL_INV_INV]);;
let REAL_INV_EQ_0 = prove
(`!x. inv(x) = &0 <=> x = &0`,
GEN_TAC THEN EQ_TAC THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_INV_0] THEN
ONCE_REWRITE_TAC[GSYM REAL_INV_INV] THEN ASM_REWRITE_TAC[REAL_INV_0]);;
let REAL_LT_INV = prove
(`!x. &0 < x ==> &0 < inv(x)`,
GEN_TAC THEN
REPEAT_TCL DISJ_CASES_THEN ASSUME_TAC (SPEC `inv(x)` REAL_LT_NEGTOTAL) THEN
ASM_REWRITE_TAC[] THENL
[RULE_ASSUM_TAC(REWRITE_RULE[REAL_INV_EQ_0]) THEN ASM_REWRITE_TAC[];
DISCH_TAC THEN SUBGOAL_THEN `&0 < --(inv x) * x` MP_TAC THENL
[MATCH_MP_TAC REAL_LT_MUL THEN ASM_REWRITE_TAC[];
REWRITE_TAC[REAL_MUL_LNEG]]] THEN
SUBGOAL_THEN `inv(x) * x = &1` SUBST1_TAC THENL
[MATCH_MP_TAC REAL_MUL_LINV THEN
UNDISCH_TAC `&0 < x` THEN REAL_ARITH_TAC;
REWRITE_TAC[REAL_LT_RNEG; REAL_ADD_LID; REAL_OF_NUM_LT; ARITH]]);;
let REAL_LT_INV_EQ = prove
(`!x. &0 < inv x <=> &0 < x`,
GEN_TAC THEN EQ_TAC THEN REWRITE_TAC[REAL_LT_INV] THEN
GEN_REWRITE_TAC (funpow 2 RAND_CONV) [GSYM REAL_INV_INV] THEN
REWRITE_TAC[REAL_LT_INV]);;
let REAL_INV_NEG = prove
(`!x. inv(--x) = --(inv x)`,
GEN_TAC THEN ASM_CASES_TAC `x = &0` THEN
ASM_REWRITE_TAC[REAL_NEG_0; REAL_INV_0] THEN
MATCH_MP_TAC REAL_MUL_LINV_UNIQ THEN
REWRITE_TAC[REAL_MUL_LNEG; REAL_MUL_RNEG; REAL_NEG_NEG] THEN
MATCH_MP_TAC REAL_MUL_LINV THEN ASM_REWRITE_TAC[]);;
let REAL_LE_INV_EQ = prove
(`!x. &0 <= inv x <=> &0 <= x`,
REWRITE_TAC[REAL_LE_LT; REAL_LT_INV_EQ; REAL_INV_EQ_0] THEN
MESON_TAC[REAL_INV_EQ_0]);;
let REAL_LE_INV = prove
(`!x. &0 <= x ==> &0 <= inv(x)`,
REWRITE_TAC[REAL_LE_INV_EQ]);;
let REAL_MUL_RINV = prove
(`!x. ~(x = &0) ==> (x * inv(x) = &1)`,
ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
REWRITE_TAC[REAL_MUL_LINV]);;
let REAL_INV_1 = prove
(`inv(&1) = &1`,
MATCH_MP_TAC REAL_MUL_RINV_UNIQ THEN
REWRITE_TAC[REAL_MUL_LID]);;
let REAL_INV_EQ_1 = prove
(`!x. inv(x) = &1 <=> x = &1`,
MESON_TAC[REAL_INV_INV; REAL_INV_1]);;
let REAL_DIV_1 = prove
(`!x. x / &1 = x`,
REWRITE_TAC[real_div; REAL_INV_1; REAL_MUL_RID]);;
let REAL_DIV_REFL = prove
(`!x. ~(x = &0) ==> (x / x = &1)`,
GEN_TAC THEN REWRITE_TAC[real_div; REAL_MUL_RINV]);;
let REAL_DIV_RMUL = prove
(`!x y. ~(y = &0) ==> ((x / y) * y = x)`,
SIMP_TAC[real_div; GSYM REAL_MUL_ASSOC; REAL_MUL_LINV; REAL_MUL_RID]);;
let REAL_DIV_LMUL = prove
(`!x y. ~(y = &0) ==> (y * (x / y) = x)`,
ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN REWRITE_TAC[REAL_DIV_RMUL]);;
let REAL_DIV_EQ_1 = prove
(`!x y:real. x / y = &1 <=> x = y /\ ~(x = &0) /\ ~(y = &0)`,
REPEAT GEN_TAC THEN REWRITE_TAC[real_div] THEN
ASM_CASES_TAC `x = &0` THEN ASM_REWRITE_TAC[REAL_MUL_LZERO] THEN
ASM_CASES_TAC `y = &0` THEN ASM_REWRITE_TAC[REAL_INV_0; REAL_MUL_RZERO] THEN
REWRITE_TAC[REAL_OF_NUM_EQ; ARITH] THEN
EQ_TAC THEN ASM_SIMP_TAC[GSYM real_div; REAL_DIV_REFL] THEN
DISCH_THEN(MP_TAC o AP_TERM `( * ) (y:real)`) THEN
ASM_SIMP_TAC[REAL_DIV_LMUL; REAL_MUL_RID]);;
let REAL_ABS_INV = prove
(`!x. abs(inv x) = inv(abs x)`,
GEN_TAC THEN CONV_TAC SYM_CONV THEN
ASM_CASES_TAC `x = &0` THEN ASM_REWRITE_TAC[REAL_INV_0; REAL_ABS_0] THEN
MATCH_MP_TAC REAL_MUL_RINV_UNIQ THEN
REWRITE_TAC[GSYM REAL_ABS_MUL] THEN
POP_ASSUM(SUBST1_TAC o MATCH_MP REAL_MUL_RINV) THEN
REWRITE_TAC[REAL_ABS_1]);;
let REAL_ABS_DIV = prove
(`!x y. abs(x / y) = abs(x) / abs(y)`,
REWRITE_TAC[real_div; REAL_ABS_INV; REAL_ABS_MUL]);;
let REAL_INV_MUL = prove
(`!x y. inv(x * y) = inv(x) * inv(y)`,
REPEAT GEN_TAC THEN
MAP_EVERY ASM_CASES_TAC [`x = &0`; `y = &0`] THEN
ASM_REWRITE_TAC[REAL_INV_0; REAL_MUL_LZERO; REAL_MUL_RZERO] THEN
MATCH_MP_TAC REAL_MUL_LINV_UNIQ THEN
ONCE_REWRITE_TAC[AC REAL_MUL_AC `(a * b) * (c * d) = (a * c) * (b * d)`] THEN
EVERY_ASSUM(SUBST1_TAC o MATCH_MP REAL_MUL_LINV) THEN
REWRITE_TAC[REAL_MUL_LID]);;
let REAL_INV_DIV = prove
(`!x y. inv(x / y) = y / x`,
REWRITE_TAC[real_div; REAL_INV_INV; REAL_INV_MUL] THEN
MATCH_ACCEPT_TAC REAL_MUL_SYM);;
let REAL_POW_MUL = prove
(`!x y n. (x * y) pow n = (x pow n) * (y pow n)`,
GEN_TAC THEN GEN_TAC THEN INDUCT_TAC THEN
ASM_REWRITE_TAC[real_pow; REAL_MUL_LID; REAL_MUL_AC]);;
let REAL_POW_INV = prove
(`!x n. (inv x) pow n = inv(x pow n)`,
GEN_TAC THEN INDUCT_TAC THEN
ASM_REWRITE_TAC[real_pow; REAL_INV_1; REAL_INV_MUL]);;
let REAL_INV_POW = prove
(`!x n. inv(x pow n) = (inv x) pow n`,
REWRITE_TAC[REAL_POW_INV]);;
let REAL_POW_DIV = prove
(`!x y n. (x / y) pow n = (x pow n) / (y pow n)`,
REWRITE_TAC[real_div; REAL_POW_MUL; REAL_POW_INV]);;
let REAL_DIV_EQ_0 = prove
(`!x y. x / y = &0 <=> x = &0 \/ y = &0`,
REWRITE_TAC[real_div; REAL_INV_EQ_0; REAL_ENTIRE]);;
let REAL_POW_ADD = prove
(`!x m n. x pow (m + n) = x pow m * x pow n`,
GEN_TAC THEN INDUCT_TAC THEN
ASM_REWRITE_TAC[ADD_CLAUSES; real_pow; REAL_MUL_LID; REAL_MUL_ASSOC]);;
let REAL_POW_NZ = prove
(`!x n. ~(x = &0) ==> ~(x pow n = &0)`,
GEN_TAC THEN INDUCT_TAC THEN
REWRITE_TAC[real_pow; REAL_OF_NUM_EQ; ARITH] THEN
ASM_MESON_TAC[REAL_ENTIRE]);;
let REAL_POW_SUB = prove
(`!x m n. ~(x = &0) /\ m <= n ==> (x pow (n - m) = x pow n / x pow m)`,
REPEAT GEN_TAC THEN
DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC) THEN
REWRITE_TAC[LE_EXISTS] THEN
DISCH_THEN(CHOOSE_THEN SUBST1_TAC) THEN
REWRITE_TAC[ADD_SUB2] THEN REWRITE_TAC[REAL_POW_ADD] THEN
REWRITE_TAC[real_div] THEN ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
GEN_REWRITE_TAC LAND_CONV [GSYM REAL_MUL_LID] THEN
REWRITE_TAC[REAL_MUL_ASSOC] THEN AP_THM_TAC THEN AP_TERM_TAC THEN
CONV_TAC SYM_CONV THEN MATCH_MP_TAC REAL_MUL_LINV THEN
MATCH_MP_TAC REAL_POW_NZ THEN ASM_REWRITE_TAC[]);;
let REAL_LT_LCANCEL_IMP = prove
(`!x y z. &0 < x /\ x * y < x * z ==> y < z`,
REPEAT GEN_TAC THEN
DISCH_THEN(fun th -> ASSUME_TAC(CONJUNCT1 th) THEN MP_TAC th) THEN DISCH_THEN
(MP_TAC o uncurry CONJ o (MATCH_MP REAL_LT_INV F_F I) o CONJ_PAIR) THEN
DISCH_THEN(MP_TAC o MATCH_MP REAL_LT_LMUL) THEN
POP_ASSUM(ASSUME_TAC o MATCH_MP REAL_MUL_LINV o MATCH_MP REAL_LT_IMP_NZ) THEN
ASM_REWRITE_TAC[REAL_MUL_ASSOC; REAL_MUL_LID]);;
let REAL_LT_RCANCEL_IMP = prove
(`!x y z. &0 < z /\ x * z < y * z ==> x < y`,
ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN REWRITE_TAC[REAL_LT_LCANCEL_IMP]);;
let REAL_LE_LCANCEL_IMP = prove
(`!x y z. &0 < x /\ x * y <= x * z ==> y <= z`,
REPEAT GEN_TAC THEN REWRITE_TAC[REAL_LE_LT; REAL_EQ_MUL_LCANCEL] THEN
ASM_CASES_TAC `x = &0` THEN ASM_REWRITE_TAC[REAL_LT_REFL] THEN
STRIP_TAC THEN ASM_REWRITE_TAC[] THEN DISJ1_TAC THEN
MATCH_MP_TAC REAL_LT_LCANCEL_IMP THEN
EXISTS_TAC `x:real` THEN ASM_REWRITE_TAC[]);;
let REAL_LE_RCANCEL_IMP = prove
(`!x y z. &0 < z /\ x * z <= y * z ==> x <= y`,
ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN REWRITE_TAC[REAL_LE_LCANCEL_IMP]);;
let REAL_LE_RMUL_EQ = prove
(`!x y z. &0 < z ==> (x * z <= y * z <=> x <= y)`,
MESON_TAC[REAL_LE_RMUL; REAL_LE_RCANCEL_IMP; REAL_LT_IMP_LE]);;
let REAL_LE_LMUL_EQ = prove
(`!x y z. &0 < z ==> (z * x <= z * y <=> x <= y)`,
MESON_TAC[REAL_LE_RMUL_EQ; REAL_MUL_SYM]);;
let REAL_LT_RMUL_EQ = prove
(`!x y z. &0 < z ==> (x * z < y * z <=> x < y)`,
SIMP_TAC[GSYM REAL_NOT_LE; REAL_LE_RMUL_EQ]);;
let REAL_LT_LMUL_EQ = prove
(`!x y z. &0 < z ==> (z * x < z * y <=> x < y)`,
SIMP_TAC[GSYM REAL_NOT_LE; REAL_LE_LMUL_EQ]);;
let REAL_LE_MUL_EQ = prove
(`(!x y. &0 < x ==> (&0 <= x * y <=> &0 <= y)) /\
(!x y. &0 < y ==> (&0 <= x * y <=> &0 <= x))`,
MESON_TAC[REAL_LE_LMUL_EQ; REAL_LE_RMUL_EQ; REAL_MUL_LZERO; REAL_MUL_RZERO]);;
let REAL_LT_MUL_EQ = prove
(`(!x y. &0 < x ==> (&0 < x * y <=> &0 < y)) /\
(!x y. &0 < y ==> (&0 < x * y <=> &0 < x))`,
MESON_TAC[REAL_LT_LMUL_EQ; REAL_LT_RMUL_EQ; REAL_MUL_LZERO; REAL_MUL_RZERO]);;
let REAL_MUL_POS_LT = prove
(`!x y. &0 < x * y <=> &0 < x /\ &0 < y \/ x < &0 /\ y < &0`,
REPEAT STRIP_TAC THEN
STRIP_ASSUME_TAC(SPEC `x:real` REAL_LT_NEGTOTAL) THEN
STRIP_ASSUME_TAC(SPEC `y:real` REAL_LT_NEGTOTAL) THEN
ASM_REWRITE_TAC[REAL_MUL_LZERO; REAL_MUL_RZERO; REAL_LT_REFL] THEN
ASSUM_LIST(MP_TAC o MATCH_MP REAL_LT_MUL o end_itlist CONJ) THEN
REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC);;
let REAL_MUL_POS_LE = prove
(`!x y. &0 <= x * y <=>
x = &0 \/ y = &0 \/ &0 < x /\ &0 < y \/ x < &0 /\ y < &0`,
REWRITE_TAC[REAL_ARITH `&0 <= x <=> x = &0 \/ &0 < x`] THEN
REWRITE_TAC[REAL_MUL_POS_LT; REAL_ENTIRE] THEN REAL_ARITH_TAC);;
let REAL_LE_RDIV_EQ = prove
(`!x y z. &0 < z ==> (x <= y / z <=> x * z <= y)`,
REPEAT STRIP_TAC THEN
FIRST_ASSUM(fun th ->
GEN_REWRITE_TAC LAND_CONV [GSYM(MATCH_MP REAL_LE_RMUL_EQ th)]) THEN
ASM_SIMP_TAC[real_div; GSYM REAL_MUL_ASSOC; REAL_MUL_LINV;
REAL_MUL_RID; REAL_LT_IMP_NZ]);;
let REAL_LE_LDIV_EQ = prove
(`!x y z. &0 < z ==> (x / z <= y <=> x <= y * z)`,
REPEAT STRIP_TAC THEN
FIRST_ASSUM(fun th ->
GEN_REWRITE_TAC LAND_CONV [GSYM(MATCH_MP REAL_LE_RMUL_EQ th)]) THEN
ASM_SIMP_TAC[real_div; GSYM REAL_MUL_ASSOC; REAL_MUL_LINV;
REAL_MUL_RID; REAL_LT_IMP_NZ]);;
let REAL_LT_RDIV_EQ = prove
(`!x y z. &0 < z ==> (x < y / z <=> x * z < y)`,
SIMP_TAC[GSYM REAL_NOT_LE; REAL_LE_LDIV_EQ]);;
let REAL_LT_LDIV_EQ = prove
(`!x y z. &0 < z ==> (x / z < y <=> x < y * z)`,
SIMP_TAC[GSYM REAL_NOT_LE; REAL_LE_RDIV_EQ]);;
let REAL_EQ_RDIV_EQ = prove
(`!x y z. &0 < z ==> ((x = y / z) <=> (x * z = y))`,
REWRITE_TAC[GSYM REAL_LE_ANTISYM] THEN
SIMP_TAC[REAL_LE_RDIV_EQ; REAL_LE_LDIV_EQ]);;
let REAL_EQ_LDIV_EQ = prove
(`!x y z. &0 < z ==> ((x / z = y) <=> (x = y * z))`,
REWRITE_TAC[GSYM REAL_LE_ANTISYM] THEN
SIMP_TAC[REAL_LE_RDIV_EQ; REAL_LE_LDIV_EQ]);;
let REAL_LT_DIV2_EQ = prove
(`!x y z. &0 < z ==> (x / z < y / z <=> x < y)`,
SIMP_TAC[real_div; REAL_LT_RMUL_EQ; REAL_LT_INV_EQ]);;
let REAL_LE_DIV2_EQ = prove
(`!x y z. &0 < z ==> (x / z <= y / z <=> x <= y)`,
SIMP_TAC[real_div; REAL_LE_RMUL_EQ; REAL_LT_INV_EQ]);;
let REAL_MUL_2 = prove
(`!x. &2 * x = x + x`,
REAL_ARITH_TAC);;
let REAL_POW_EQ_0 = prove
(`!x n. (x pow n = &0) <=> (x = &0) /\ ~(n = 0)`,
GEN_TAC THEN INDUCT_TAC THEN
ASM_REWRITE_TAC[NOT_SUC; real_pow; REAL_ENTIRE] THENL
[REAL_ARITH_TAC;
CONV_TAC TAUT]);;
let REAL_LE_MUL2 = prove
(`!w x y z. &0 <= w /\ w <= x /\ &0 <= y /\ y <= z
==> w * y <= x * z`,
REPEAT STRIP_TAC THEN MATCH_MP_TAC REAL_LE_TRANS THEN
EXISTS_TAC `w * z` THEN CONJ_TAC THENL
[MATCH_MP_TAC REAL_LE_LMUL; MATCH_MP_TAC REAL_LE_RMUL] THEN
ASM_REWRITE_TAC[] THEN
MATCH_MP_TAC REAL_LE_TRANS THEN EXISTS_TAC `y:real` THEN
ASM_REWRITE_TAC[]);;
let REAL_LT_MUL2 = prove
(`!w x y z. &0 <= w /\ w < x /\ &0 <= y /\ y < z
==> w * y < x * z`,
REPEAT STRIP_TAC THEN MATCH_MP_TAC REAL_LET_TRANS THEN
EXISTS_TAC `w * z` THEN CONJ_TAC THENL
[MATCH_MP_TAC REAL_LE_LMUL; MATCH_MP_TAC REAL_LT_RMUL] THEN
ASM_REWRITE_TAC[] THENL
[MATCH_MP_TAC REAL_LT_IMP_LE THEN ASM_REWRITE_TAC[];
MATCH_MP_TAC REAL_LET_TRANS THEN EXISTS_TAC `y:real` THEN
ASM_REWRITE_TAC[]]);;
let REAL_LT_SQUARE = prove
(`!x. (&0 < x * x) <=> ~(x = &0)`,
GEN_TAC THEN REWRITE_TAC[REAL_LT_LE; REAL_LE_SQUARE] THEN
GEN_REWRITE_TAC (LAND_CONV o RAND_CONV) [EQ_SYM_EQ] THEN
REWRITE_TAC[REAL_ENTIRE]);;