File: AlgoPredSucc.v

package info (click to toggle)
coq-float 1%3A8.4-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,692 kB
  • ctags: 30
  • sloc: makefile: 209
file content (2820 lines) | stat: -rw-r--r-- 128,482 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
Require Import AllFloat.
Require Import Veltkamp.

Section AFZ.
Variable b : Fbound.
Variable radix : Z.
Variable precision : nat.
 
Coercion Local FtoRradix := FtoR radix.
Hypothesis radixMoreThanOne : (1 < radix)%Z.
Hypothesis precisionGreaterThanOne : 1 < precision.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix precision.


Definition AFZClosest (r : R) (p : float) :=
  Closest b radix r p /\
  ((Rabs r <= Rabs p)%R \/ (forall q : float, Closest b radix r q -> q = p :>R)).
 
Theorem AFZClosestTotal : TotalP AFZClosest.
red in |- *; intros r.
case MinEx with (r := r) (3 := pGivesBound); auto with arith.
intros min H'.
case MaxEx with (r := r) (3 := pGivesBound); auto with arith.
intros max H'0.
cut (min <= r)%R; [ intros Rl1 | apply isMin_inv1 with (1 := H'); auto ].
cut (r <= max)%R; [ intros Rl2 | apply isMax_inv1 with (1 := H'0) ].
case (Rle_or_lt (r - min) (max - r)); intros H'1.
case H'1; intros H'2; auto.
exists min; split.
apply ClosestMin with (max := max); auto.
replace (2%nat * r)%R with (r + r)%R; [ idtac | simpl in |- *; ring ].
apply Rminus_le; auto.
fold FtoRradix; replace (r + r - (min + max))%R with (r - min - (max - r))%R;
 [ idtac | simpl in |- *; ring ].
apply Rle_minus; auto.
right; intros q H'3.
apply ClosestMinEq with (r := r) (max := max) (b:=b) ; auto.
fold FtoRradix; replace (2%nat * r)%R with (r + r)%R; [ idtac | simpl in |- *; ring ].
apply Rminus_lt; auto.
replace (r + r - (min + max))%R with (r - min - (max - r))%R;
 [ idtac | simpl in |- *; ring ].
apply Rlt_minus; auto.
case (Rle_or_lt (Rabs r) (Rabs min)); intros G.
exists min; split; auto.
apply ClosestMin with (max := max); auto.
fold FtoRradix; replace (2%nat * r)%R with (r + r)%R; [ idtac | simpl in |- *; ring ].
apply Rminus_le; auto.
replace (r + r - (min + max))%R with (r - min - (max - r))%R;
 [ idtac | simpl in |- *; ring ].
apply Rle_minus; auto.
exists max; split; auto.
apply ClosestMax with (min := min); auto.
fold FtoRradix; replace (2%nat * r)%R with (r + r)%R; [ idtac | simpl in |- *; ring ].
apply Rminus_le; auto.
replace (min + max - (r + r))%R with (max - r - (r - min))%R;
 [ idtac | simpl in |- *; ring ].
apply Rle_minus; auto.
rewrite H'2; auto with real.
case (Rle_or_lt 0 r); intros M.
left; repeat rewrite Rabs_right; try apply Rle_ge; auto with real.
apply Rle_trans with (1:=M); auto.
absurd ((Rabs min < Rabs r)%R); auto.
apply Rle_not_lt.
repeat rewrite Rabs_left1; auto with real.
apply Rle_trans with (1:=Rl1); auto with real.
exists max; split; auto.
apply ClosestMax with (min := min); auto.
replace (2%nat * r)%R with (r + r)%R; [ idtac | simpl in |- *; ring ].
apply Rminus_le; auto.
fold FtoRradix; replace (min + max - (r + r))%R with (max - r - (r - min))%R;
 [ idtac | simpl in |- *; ring ].
apply Rle_minus; auto with real.
right; intros q H'2.
apply ClosestMaxEq with (r := r) (min := min) (b:=b); auto.
replace (2%nat * r)%R with (r + r)%R; [ idtac | simpl in |- *; ring ].
apply Rminus_lt; auto.
fold FtoRradix; replace (min + max - (r + r))%R with (max - r - (r - min))%R;
 [ idtac | simpl in |- *; ring ].
apply Rlt_minus; auto.
Qed.


Theorem AFZClosestCompatible : CompatibleP b radix AFZClosest.
red in |- *; simpl in |- *.
intros r1 r2 p q H' H'0 H'1 H'2; red in |- *.
inversion H'.
split.
apply (ClosestCompatible b radix r1 r2 p q); auto.
case H0; intros H1.
left.
rewrite <- H'0; fold FtoRradix in H'1; rewrite <- H'1; auto.
right; intros q0 H'3.
unfold FtoRradix in |- *; rewrite <- H'1; auto.
apply H1; auto.
apply (ClosestCompatible b radix r2 r1 q0 q0); auto.
case H'3; auto.
Qed.



Theorem AFZClosestMinOrMax : MinOrMaxP b radix AFZClosest.
red in |- *; intros r p H'; case (ClosestMinOrMax b radix r p); auto.
case H'; auto.
Qed.
 
Theorem AFZClosestMonotone : MonotoneP radix AFZClosest.
red in |- *; simpl in |- *; intros p q p' q' H' H'0 H'1.
apply (ClosestMonotone b radix p q); auto; case H'0; case H'1; auto.
Qed.

Theorem AFZClosestRoundedModeP : RoundedModeP b radix AFZClosest.
red in |- *; split.
exact AFZClosestTotal.
split.
exact AFZClosestCompatible.
split.
exact AFZClosestMinOrMax.
exact AFZClosestMonotone.
Qed.
 
Theorem AFZClosestUniqueP : UniqueP radix AFZClosest.
red in |- *; simpl in |- *.
intros r p q H' H'0.
inversion H'; inversion H'0; case H0; case H2; auto.
intros H'1 H'2; case (AFZClosestMinOrMax r p);
 case (AFZClosestMinOrMax r q); auto.
intros H'3 H'4; apply (MinUniqueP b radix r); auto.
intros H'3 H'4; case (Req_dec p q); auto; intros H'5.
Contradict H'1; auto.
apply Rlt_not_le.
cut (p <= r)%R; [ intros Rl1 | apply isMin_inv1 with (1 := H'4); auto ].
cut (r <= q)%R; [ intros Rl2 | apply isMax_inv1 with (1 := H'3) ].
assert (FtoRradix p=r -> False).
intros; Contradict H'5.
apply
 (RoundedProjector b radix _
    (MaxRoundedModeP _ _ _ radixMoreThanOne precisionGreaterThanOne
       pGivesBound)); auto.
case H'4; auto.
fold FtoRradix; rewrite H3; auto.
case (Rle_or_lt 0 r); intros G.
absurd ( (Rabs r <= Rabs p)%R); auto.
apply Rlt_not_le; repeat rewrite Rabs_right; try apply Rle_ge; auto with real.
case Rl1; auto.
intros; absurd False; auto; apply H3; auto.
apply RleMinR0 with b precision r; auto with real zarith.
repeat rewrite Rabs_left1; auto with real.
case Rl2; auto with real.
intros; Contradict H'5; apply sym_eq.
apply
 (RoundedProjector b radix _
    (MinRoundedModeP _ _ _ radixMoreThanOne precisionGreaterThanOne
       pGivesBound)); auto.
case H'3; auto.
fold FtoRradix; rewrite <- H4; auto.
apply RleMaxR0 with b precision r; auto with real zarith.
intros H'3 H'4; case (Req_dec p q); auto; intros H'5.
Contradict H'1; auto.
apply Rlt_not_le.
cut (q <= r)%R; [ intros Rl1 | apply isMin_inv1 with (1 := H'3); auto ].
cut (r <= p)%R; [ intros Rl2 | apply isMax_inv1 with (1 := H'4) ].
case (Rle_or_lt 0 r); intros G.
repeat rewrite Rabs_right; try apply Rle_ge; auto with real.
case Rl1; auto with real.
intros; Contradict H'5; apply sym_eq.
apply
 (RoundedProjector b radix _
    (MaxRoundedModeP _ _ _ radixMoreThanOne precisionGreaterThanOne
       pGivesBound)); auto.
case H'3; auto.
fold FtoRradix; rewrite H3; auto.
apply RleMinR0 with b precision r; auto with real zarith.
absurd ( (Rabs r <= Rabs p)%R); auto.
apply Rlt_not_le; repeat rewrite Rabs_left1; auto with real.
case Rl2; auto with real.
intros; Contradict H'5.
apply
 (RoundedProjector b radix _
    (MinRoundedModeP _ _ _ radixMoreThanOne precisionGreaterThanOne
       pGivesBound)); auto.
case H'4; auto.
fold FtoRradix; rewrite <- H3; auto.
apply RleMaxR0 with b precision r; auto with real zarith.
intros H'3 H'4; apply (MaxUniqueP b radix r); auto.
intros H'1 H'2; apply sym_eq; auto.
Qed.


Theorem AFZClosestSymmetric : SymmetricP AFZClosest.
red in |- *; intros r p H'; case H'; clear H'.
intros H' H'0; case H'0; clear H'0; intros H'0.
split; auto.
apply (ClosestSymmetric b radix r p); auto.
left.
unfold FtoRradix; rewrite Fopp_correct; auto with zarith.
repeat rewrite Rabs_Ropp; auto with real.
split; auto.
apply (ClosestSymmetric b radix r p); auto.
right.
intros q H'1.
cut (Fopp q = p :>R).
intros H'2; unfold FtoRradix in |- *; rewrite Fopp_correct.
unfold FtoRradix in H'2; rewrite <- H'2.
rewrite Fopp_correct; ring.
apply H'0; auto.
replace r with (- - r)%R; [ idtac | ring ].
apply (ClosestSymmetric b radix (- r)%R q); auto.
Qed.

End AFZ.
Section Closest2.
Variable b : Fbound.
Variable prec : nat.
Variable radix:Z.

Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.


Hypothesis radixMoreThanOne : (1 < radix)%Z.
Hypothesis precisionGreaterThan : 1 < prec.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix prec.


Lemma ClosestClosestPredSucc: forall (f g:float) (r:R),
    (Closest b radix r f) ->  (Closest b radix r g) -> 
    (FtoRradix f=g) 
            \/  (FtoRradix f=FNPred b radix prec g)
            \/  (FtoRradix f=FNSucc b radix prec g). 
intros.
elim H; intros Bf T; elim H0; intros Bg T'; clear T T'. 
case (ClosestMinOrMax b radix r f); auto; intros T1;
    case (ClosestMinOrMax b radix r g); auto; intros T2.
left; unfold FtoRradix; apply (MinUniqueP b radix r); auto.
assert (f <= g)%R.
elim T1; elim T2; intros; apply Rle_trans with r; intuition.
case H1; auto; intros.
right; left; unfold FtoRradix.
rewrite <- FnormalizeCorrect with radix b prec f; auto with zarith.
rewrite <- FPredSuc with b radix prec (Fnormalize radix b prec f); auto with zarith.
2: apply FnormalizeCanonic; auto with zarith.
unfold FNPred.
replace (FSucc b radix prec (Fnormalize radix b prec f)) with (Fnormalize radix b prec g); auto.
apply FcanonicUnique with radix b prec; auto with zarith float.
unfold FtoRradix; apply (MaxUniqueP b radix r); auto.
apply (MaxCompatible b radix r r g); auto with real zarith float.
rewrite FnormalizeCorrect; auto with zarith real.
apply MinMax; auto with zarith.
fold FtoRradix; Contradict H2.
replace (FtoRradix f) with (FtoRradix g); auto with real.
apply sym_eq; apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
eapply ClosestRoundedModeP; eauto.
fold FtoRradix; rewrite <- H2; auto.
assert (g <= f)%R.
elim T1; elim T2; intros; apply Rle_trans with r; intuition.
case H1; auto; intros.
right; right; unfold FtoRradix.
unfold FtoRradix; apply (MaxUniqueP b radix r); auto.
apply MinMax; auto with zarith.
fold FtoRradix; Contradict H2.
replace (FtoRradix f) with (FtoRradix g); auto with real.
apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
eapply ClosestRoundedModeP; eauto.
fold FtoRradix; rewrite <- H2; auto.
left; unfold FtoRradix; apply (MaxUniqueP b radix r); auto.
Qed.



Lemma ClosestStrictMonotone2l: forall (r1 r2 : R) (f1 f2 : float),
     Closest b radix r1 f1 -> (Fcanonic radix b f2) ->
      (Rabs (r2 - f2) < Rabs (r2 - FSucc b radix prec f2))%R ->
      (Rabs (r2 - f2) < Rabs (r2 - FPred b radix prec f2))%R ->
     (r2 <= r1)%R -> 
     (FtoRradix f2 <= FtoRradix f1)%R.
intros.
assert (Closest b radix r2 f2).
apply ClosestSuccPred with prec; auto with real.
eapply FcanonicBound; eauto.
case H3; intros.
generalize ClosestMonotone; unfold MonotoneP; intros T.
unfold FtoRradix; apply T with b r2 r1; auto.
case (ClosestClosestPredSucc f1 f2 r1); auto with real.
rewrite <- H5; auto.
intros K; case K; intros.
absurd (  (Rabs (r2 - f2) < Rabs (r2 - f1)))%R.
apply Rle_not_lt.
rewrite <- Rabs_Ropp with (r2-f1)%R; rewrite <- Rabs_Ropp with (r2-f2)%R.
replace (-(r2-f1))%R with (f1-r2)%R by ring.
replace (-(r2-f2))%R with (f2-r2)%R by ring.
rewrite H5.
elim H; intros T1 T2; apply T2; auto.
elim H4; auto.
rewrite H6; unfold FNPred.
rewrite FcanonicFnormalizeEq; auto with zarith real.
rewrite H6; left; apply FNSuccLt; auto with zarith.
Qed.

Lemma ClosestStrictMonotone2r: forall (r1 r2 : R) (f1 f2 : float),
     Closest b radix r1 f1 -> (Fcanonic radix b f2) ->
      (Rabs (r2 - f2) < Rabs (r2 - FSucc b radix prec f2))%R ->
      (Rabs (r2 - f2) < Rabs (r2 - FPred b radix prec f2))%R ->
     (r1 <= r2)%R -> 
     (FtoRradix f1 <= FtoRradix f2)%R.
intros.
assert (Closest b radix r2 f2).
apply ClosestSuccPred with prec; auto with real.
eapply FcanonicBound; eauto.
case H3; intros.
generalize ClosestMonotone; unfold MonotoneP; intros T.
unfold FtoRradix; apply T with b r1 r2; auto.
case (ClosestClosestPredSucc f1 f2 r1); auto with real.
rewrite H5; auto.
intros K; case K; intros.
rewrite H6; left; apply FNPredLt; auto with zarith.
absurd (  (Rabs (r2 - f2) < Rabs (r2 - f1)))%R.
apply Rle_not_lt.
rewrite <- Rabs_Ropp with (r2-f1)%R; rewrite <- Rabs_Ropp with (r2-f2)%R.
replace (-(r2-f1))%R with (f1-r2)%R by ring.
replace (-(r2-f2))%R with (f2-r2)%R by ring.
rewrite <- H5.
elim H; intros T1 T2; apply T2; auto.
elim H4; auto.
rewrite H6; unfold FNSucc.
rewrite FcanonicFnormalizeEq; auto with zarith real.
Qed.

Lemma ClosestStrictEq: forall (r : R) (f1 f2 : float),
     Closest b radix r f1 -> (Fcanonic radix b f2) ->
      (Rabs (r - f2) < Rabs (r - FSucc b radix prec f2))%R ->
      (Rabs (r - f2) < Rabs (r - FPred b radix prec f2))%R ->
     (FtoRradix f1 = FtoRradix f2)%R.
intros.
assert (FtoRradix f1 <= f2)%R.
apply ClosestStrictMonotone2r with r r; auto with real.
assert (FtoRradix f2 <= f1)%R; auto with real.
apply ClosestStrictMonotone2l with r r; auto with real.
Qed.


End Closest2.



Section PredComput.
Variable b : Fbound.
Variable prec : nat.
Variable radix radixH : Z.

Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.

Hypothesis radixMoreThanOne : (1 < radix)%Z.
Hypothesis precisionGreaterThan : 3 <= prec.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix prec.
Hypotheses ReasonnableFormat: (2*prec-1 <= dExp b)%Z.
Hypotheses radixEven: (radix=2*radixH)%Z.

Lemma radixHPos: (0 < radixH)%Z.
apply Zmult_lt_reg_r with 2%Z; auto with zarith.
Qed.

Hint Resolve radixHPos.


Lemma RoundedToZero_aux: forall (c:float) (r:R),
   (Fcanonic radix b c) ->
   (0 <= r)%R ->
   (r < /2 * powerRZ radix (-dExp b))%R ->
   (Closest b radix r c) ->
   (FtoRradix c=0)%R.
intros.
assert (0 <= c)%R.
unfold FtoRradix; apply RleRoundedR0 with b prec (Closest b radix) r; auto with real zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
case H3; auto; clear H3; intros H3.
elim H2; intros.
absurd (Rabs (c-r) <= Rabs r)%R.
apply Rlt_not_le.
apply Rlt_le_trans with (Rabs c -Rabs r)%R;[idtac|apply Rabs_triang_inv].
repeat rewrite Rabs_right; try apply Rle_ge; auto with real.
apply Rplus_lt_reg_r with r.
replace (r+r)%R with (2*r)%R;[idtac| ring].
apply Rlt_le_trans with (2*(/ 2 * powerRZ radix (- dExp b)))%R.
apply Rmult_lt_compat_l; auto with real.
apply Rle_trans with  (powerRZ radix (- dExp b)).
right; simpl; field; auto with real.
apply Rle_trans with c;[idtac|right; ring].
apply Rle_trans with (FSucc b radix prec (Float 0 (-(dExp b)))).
right; rewrite FSuccSimpl4; auto with zarith.
unfold FtoRradix, FtoR, Zsucc; simpl; ring.
simpl; assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
simpl; assert (0 < nNormMin radix prec)%Z; auto with zarith.
unfold nNormMin; auto with zarith.
unfold FtoRradix; apply FSuccProp; auto with zarith.
right; split; split; simpl; auto with zarith.
replace (radix*0)%Z with 0%Z; simpl; auto with zarith.
apply Rle_lt_trans with 0%R; auto with real zarith.
unfold FtoR; simpl; right; ring.
rewrite <- (Rabs_Ropp r).
replace (-r)%R with (FtoRradix (Float 0 (-(dExp b)))-r)%R.
apply H5.
split; simpl; auto with zarith.
unfold FtoRradix, FtoR; simpl; ring.
Qed.



Lemma RoundedToZero_aux2: forall (c:float) (r:R),
   (Fcanonic radix b c) -> 
   (Rabs r < /2 * powerRZ radix (-dExp b))%R ->
   (Closest b radix r c) ->
   (FtoRradix c=0)%R.
intros.
case (Rle_or_lt 0 r); intros.
apply RoundedToZero_aux with r; auto.
rewrite <- (Rabs_right r); try apply Rle_ge; auto.
apply Rmult_eq_reg_l with (-1)%R; auto with real.
apply trans_eq with 0%R;[idtac|ring].
apply trans_eq with (FtoRradix (Fopp c)).
unfold FtoRradix; rewrite Fopp_correct; ring.
apply RoundedToZero_aux with (-r)%R; auto with real.
apply FcanonicFopp; auto.
rewrite <- (Rabs_left r); auto with real.
apply ClosestOpp; auto.
Qed.

Lemma RoundedToZero: forall (c:float) (r:R),
   (Rabs r < /2 * powerRZ radix (-dExp b))%R ->
   (Closest b radix r c) ->
   (FtoRradix c=0)%R.
intros.
unfold FtoRradix; rewrite <- FnormalizeCorrect with radix b prec  c; auto with zarith.
fold FtoRradix; apply RoundedToZero_aux2 with r; auto.
apply FnormalizeCanonic; auto with zarith.
elim H0; auto.
generalize ClosestCompatible; unfold CompatibleP.
intros T; apply T with r c; auto with zarith float.
rewrite FnormalizeCorrect; auto with zarith real.
apply FnormalizeBounded; auto with zarith.
elim H0; auto.
Qed.


Definition u:= powerRZ radix (-prec).
Definition phi:=(u*(radixH+radix*u))%R.
Definition eta:= powerRZ radix (-(dExp b)).



Lemma phi_Pos: (0 < phi)%R.
unfold phi,u.
apply Rle_lt_trans with (powerRZ radix (- prec)*0)%R; auto with real.
apply Rmult_lt_compat_l; auto with real zarith.
apply Rle_lt_trans with (0+radix*0)%R; [right; ring|idtac].
apply Rplus_lt_compat; auto with real zarith.
Qed.



Lemma phi_bounded_aux: 
  (Zabs (radixH*nNormMin radix prec + 1) < Zpos (vNum b))%Z.
assert (0 < nNormMin radix prec+1)%Z.
apply Zlt_le_trans with (0+1)%Z; unfold nNormMin; auto with zarith.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound; unfold nNormMin.
apply Zlt_le_trans with (radixH*Zpower_nat radix (pred prec)+radixH*Zpower_nat radix (pred prec))%Z; auto with zarith.
apply Zplus_lt_compat_l.
apply Zle_lt_trans with (radixH*1)%Z; auto with zarith.
apply Zle_lt_trans with (radixH*Zpower_nat radix 0)%Z; auto with zarith.
apply Zmult_lt_compat_l; auto with zarith.
apply Zle_trans with ((2*radixH)*Zpower_nat radix (pred prec))%Z.
apply Zeq_le; ring.
replace (2*radixH)%Z with (Zpower_nat radix 1).
rewrite <- Zpower_nat_is_exp; auto with zarith.
rewrite <- radixEven;unfold Zpower_nat;simpl; auto with zarith.
Qed.

Lemma phi_bounded: (exists f:float, 
   Fbounded b f /\ (FtoRradix f=phi)).
exists (Float (radixH*nNormMin radix prec+1) (-(2*prec-1))); split.
split.
apply Zle_lt_trans with (Zabs (radixH*nNormMin radix prec+1))%Z; auto with zarith.
apply phi_bounded_aux.
apply Zle_trans with (-(2*prec-1))%Z; auto with zarith.
unfold FtoRradix, FtoR, pPred, phi, u.
replace (IZR (Fnum (Float (radixH*nNormMin radix prec + 1) (- (2 * prec - 1))))) with
  (radixH*powerRZ radix (prec-1)  +1)%R.
replace (Fexp (Float (radixH*nNormMin radix prec + 1) (- (2 * prec - 1)))) with (-(2*prec-1))%Z; auto with zarith.
apply trans_eq with  (radixH*((powerRZ radix (prec-1)*powerRZ radix (- (2 * prec-1))))
 +  powerRZ radix (- (2 * prec-1)))%R;[ring|idtac].
apply trans_eq with (radixH*powerRZ radix (- prec)
 + radix * (powerRZ radix (- prec) * powerRZ radix (- prec)))%R;[idtac|ring].
repeat rewrite <- powerRZ_add; auto with real zarith.
replace (prec -1+ - (2 * prec-1))%Z with (-prec)%Z; auto with zarith.
pattern (IZR radix) at 4; replace (IZR radix) with (powerRZ radix 1); auto with zarith.
rewrite <- powerRZ_add; auto with real zarith.
replace (1+(- prec + - prec))%Z with (-(2*prec-1))%Z; auto with zarith real.
simpl; auto with real.
apply trans_eq with (IZR (radixH*nNormMin radix prec+1)); auto with zarith real.
rewrite plus_IZR; rewrite mult_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith.
Qed.

Lemma GepetaGeExp: forall (c:float),
   Fcanonic radix b c -> 
   (powerRZ radix (prec-dExp b) <= c)%R ->
   (-dExp b < Fexp c)%Z.
intros.
assert (-(dExp b)+1 <= Fexp c)%Z; auto with zarith.
apply Zle_trans with (Fexp (Float (nNormMin radix prec) (-(dExp b)+1))); auto with zarith.
apply Fcanonic_Rle_Zle with radix b prec; auto with zarith.
left; split; try split; simpl; auto with zarith.
rewrite Zabs_eq.
apply ZltNormMinVnum; auto with zarith.
apply Zlt_le_weak; apply nNormPos; auto with zarith.
rewrite PosNormMin with radix b prec; auto with zarith.
apply Rle_trans with (powerRZ radix (prec - dExp b)).
rewrite <- Fabs_correct; auto with zarith.
unfold FtoR, Fabs; simpl.
unfold nNormMin; rewrite Zabs_eq; auto with zarith.
rewrite Zpower_nat_Z_powerRZ.
rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + (- dExp b + 1))%Z with (prec - dExp b)%Z; auto with real.
rewrite inj_pred; unfold Zpred; auto with zarith.
fold FtoRradix; rewrite Rabs_right; auto.
apply Rle_ge; apply Rle_trans with (2:=H0); auto with real zarith.
Qed.

Lemma GepetaIsNormal: forall (c:float),
   Fcanonic radix b c -> 
   (powerRZ radix (prec-dExp b) <= c)%R ->
   Fnormal radix b c.
intros.
case H; intros; auto.
absurd (-dExp b < Fexp c)%Z.
elim H1; intros H2 (H3,H4); rewrite H3; auto with zarith.
apply GepetaGeExp; auto.
Qed.



Lemma predSmallOnes: forall (c:float), 
  Fcanonic radix b c ->
  (Rabs c < powerRZ radix (prec-dExp b))%R 
       -> (FtoRradix (FPred b radix prec c) = c-eta)%R.
intros.
assert (Fexp c = (-dExp b))%Z.
case (Zle_lt_or_eq (-(dExp b)) (Fexp c)); auto with zarith.
assert (Fbounded b c); auto with zarith float.
apply FcanonicBound with radix; auto with zarith.
intros; absurd (Rabs c < Rabs c)%R; auto with real.
apply Rlt_le_trans with (1:=H0).
replace (prec-dExp b)%Z with ((prec-1)+(-dExp b+1))%Z;[idtac|ring].
rewrite powerRZ_add; auto with real zarith.
unfold FtoRradix; rewrite <- Fabs_correct; auto with zarith.
unfold FtoR, Fabs; simpl.
apply Rmult_le_compat; auto with real zarith.
apply Rle_trans with (IZR (nNormMin radix prec)).
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
apply Rle_powerRZ; auto with real zarith.
rewrite inj_pred; auto with zarith.
apply Rle_IZR.
apply pNormal_absolu_min with b; auto with zarith.
case H; auto; intros H2; elim H2; intros H3 (H4,H5).
absurd (-dExp b <Fexp c)%Z; auto with zarith.
apply Rle_powerRZ; auto with real zarith.
case (Z_eq_dec (Fnum c) (- pPred (vNum b))%Z); intros H2.
rewrite FPredSimpl1; auto with zarith.
unfold FtoRradix, FtoR, eta; simpl; rewrite H1; rewrite H2.
repeat rewrite Ropp_Ropp_IZR.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite Ropp_mult_distr_l_reverse.
rewrite <- powerRZ_add; auto with real zarith.
unfold pPred, Zpred; rewrite plus_IZR.
rewrite pGivesBound; rewrite Zpower_nat_Z_powerRZ.
apply trans_eq with (-(powerRZ radix prec *powerRZ radix (- dExp b)))%R;
[idtac|simpl; ring].
rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + Zsucc (- dExp b))%Z with (prec + - dExp b)%Z; auto with real.
rewrite inj_pred; unfold Zpred, Zsucc; auto with zarith.
case (Z_eq_dec (Fnum c) (nNormMin radix prec)); intros H3.
replace c with (Float (nNormMin radix prec) (- dExp b)).
rewrite FPredSimpl3; auto with zarith.
unfold FtoRradix, FtoR, Zpred, eta; simpl.
rewrite plus_IZR; simpl; ring.
apply sym_eq; apply floatEq; auto.
rewrite FPredSimpl4; auto.
unfold FtoRradix, FtoR, eta; simpl.
rewrite H1; unfold Zpred.
rewrite plus_IZR; simpl; ring.
Qed.


Lemma predNormal1: forall (c:float),
  Fcanonic radix b c ->
  (powerRZ radix (prec-dExp b) <= c)%R -> 
  (Fnum c=nNormMin radix prec) ->
  (FtoRradix (FPred b radix prec c) = c-powerRZ radix (Fexp c-1))%R.
intros c Cc; intros.
rewrite FPredSimpl2; auto with zarith.
unfold FtoRradix, FtoR; simpl; rewrite H0; simpl.
unfold pPred, Zpred; rewrite plus_IZR.
rewrite Rmult_plus_distr_r; unfold Rminus.
replace (Zpos (vNum b) * powerRZ radix (Fexp c + -1))%R with
   (nNormMin radix prec * powerRZ radix (Fexp c))%R.
replace ((-1)%Z * powerRZ radix (Fexp c + -1))%R with
   (- powerRZ radix (Fexp c - 1))%R; auto with real.
unfold Zminus; simpl; ring.
unfold nNormMin; rewrite pGivesBound.
repeat rewrite Zpower_nat_Z_powerRZ.
repeat rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + Fexp c)%Z with  (prec + (Fexp c + -1))%Z; auto.
rewrite inj_pred; unfold Zpred; auto with zarith.
assert (-dExp b < Fexp c)%Z; auto with zarith.
apply GepetaGeExp; auto.
Qed.



Lemma predNormal2: forall (c:float),
   Fcanonic radix b c ->
  (powerRZ radix (prec-dExp b) <= c)%R -> 
  (Fnum c <> nNormMin radix prec) ->
   (FtoRradix (FPred b radix prec c) = c-powerRZ radix (Fexp c))%R.
intros.
rewrite FPredSimpl4; auto with zarith.
unfold FtoRradix, FtoR, Zpred; simpl.
rewrite plus_IZR; simpl; ring.
assert (-pPred (vNum b) < Fnum c)%Z; auto with zarith float.
apply Zlt_le_trans with 0%Z.
assert (0 < pPred (vNum b))%Z; auto with zarith float.
apply pPredMoreThanOne with radix prec; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
fold FtoRradix; apply Rle_trans with (2:=H0); auto with real zarith.
Qed.

Lemma succNormal: forall (c:float),
   Fcanonic radix b c ->
  (0 <= c)%R -> 
   (FtoRradix (FSucc b radix prec c) = c+powerRZ radix (Fexp c))%R.
intros.
apply Rplus_eq_reg_l with (-c)%R.
apply trans_eq with (FtoRradix (Fminus radix (FSucc b radix prec c) c)).
unfold FtoRradix; rewrite Fminus_correct; auto with real zarith; ring.
unfold FtoRradix; rewrite FSuccDiff1; auto with zarith.
unfold FtoR; simpl; ring.
unfold nNormMin.
assert (-(Zpower_nat radix (pred prec)) < Fnum c)%Z; auto with zarith.
apply Zlt_le_trans with (-0)%Z; auto with zarith.
simpl; apply LeR0Fnum with radix; auto with real zarith.
Qed. 


Lemma eGe: forall (c c' e:float),
  Fcanonic radix b c -> 
  (0 <= c)%R ->
  Closest b radix (phi*c) c' ->
  Closest b radix (c'+eta) e ->
   (powerRZ radix (Fexp c)/2 < e)%R.
intros.
case (Zle_or_lt (-dExp b) (Fexp c -prec)); intros.
assert (powerRZ radix (prec - dExp b) <= c)%R.
unfold FtoRradix, FtoR; simpl.
apply Rle_trans with (1*powerRZ radix (prec - dExp b))%R; auto with real.
apply Rmult_le_compat; auto with real zarith.
apply Rle_trans with (IZR 1); auto with real zarith.
apply Rle_IZR.
apply Zle_trans with (nNormMin radix prec); auto with zarith float.
assert (0 < nNormMin radix prec)%Z; auto with zarith.
apply nNormPos; auto with zarith.
rewrite <- (Zabs_eq (Fnum c)).
apply pNormal_absolu_min with b; auto with zarith real.
case H; auto; intros M.
elim M; intros M1 (M2,M3).
absurd (- dExp b <= Fexp c - prec)%Z; auto.
rewrite M2; auto with zarith.
apply LeR0Fnum with radix; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
apply Rlt_le_trans with c'.
apply Rlt_le_trans with (Float (radixH*nNormMin radix prec + 1)
                                             (Fexp c -prec)).
unfold FtoRradix, FtoR; simpl.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
apply Rlt_le_trans with  (powerRZ radix (Fexp c) *
  ((radixH*nNormMin radix prec + 1)%Z* powerRZ radix (- prec)))%R;[idtac|right; ring].
unfold Rdiv; apply Rmult_lt_compat_l; auto with real zarith.
rewrite plus_IZR; rewrite mult_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite Rmult_plus_distr_r.
replace  (radixH*powerRZ radix (pred prec) * powerRZ radix (- prec))%R with (/2)%R.
apply Rle_lt_trans with (/2+0)%R; auto with real zarith.
apply Rplus_lt_compat_l; simpl.
apply Rlt_le_trans with (powerRZ radix (- prec)); auto with real zarith.
rewrite Rmult_assoc; rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + - prec)%Z with (-1)%Z.
simpl; rewrite radixEven; rewrite mult_IZR; simpl; field; auto with real zarith.
rewrite inj_pred; unfold Zpred; auto with zarith.
unfold FtoRradix; apply RleBoundRoundl with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
apply phi_bounded_aux.
unfold FtoRradix, FtoR; simpl.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
apply Rle_trans with (powerRZ radix (- prec)*
  ((radixH*nNormMin radix prec + 1)%Z*powerRZ radix (Fexp c)))%R;[right; ring|idtac].
unfold phi.
apply Rle_trans with (powerRZ radix (-prec)*
  (((radixH + radix * u)*Fnum c)*powerRZ radix (Fexp c)))%R;[idtac|unfold phi,u; simpl; right;ring].
apply Rmult_le_compat_l; auto with real zarith.
apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with ((radixH + radix * u) * nNormMin radix prec)%R.
rewrite plus_IZR;  rewrite mult_IZR; rewrite Rmult_plus_distr_r.
apply Rplus_le_compat; auto with real.
unfold u; simpl; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
pattern (IZR radix) at 1; replace (IZR radix) with (powerRZ radix 1).
repeat rewrite <- powerRZ_add; auto with real zarith.
replace  (1 + - prec + pred prec)%Z with 0%Z.
simpl; auto with real.
rewrite inj_pred; unfold Zpred; auto with zarith.
simpl; auto with real.
apply Rmult_le_compat_l.
unfold u; apply Rle_trans with (0+0)%R; auto with real; apply Rplus_le_compat; auto with real zarith.
apply Rmult_le_pos; auto with real zarith.
rewrite <- (Zabs_eq (Fnum c)).
apply Rle_IZR; apply pNormal_absolu_min with b; auto with zarith real.
apply GepetaIsNormal; auto.
apply LeR0Fnum with radix; auto with real zarith.
unfold FtoRradix; apply RleBoundRoundl with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
elim H1; auto.
fold FtoRradix; apply Rle_trans with (c'+0)%R; auto with real zarith.
unfold eta; apply Rplus_le_compat_l; auto with real zarith.
assert (powerRZ radix (Fexp c) / 2 = (Float radixH (Fexp c -1)))%R.
unfold FtoRradix, FtoR; simpl.
unfold Zminus; rewrite powerRZ_add; auto with real zarith; simpl.
rewrite radixEven; rewrite mult_IZR; simpl.
field; auto with real zarith.
case (Zle_lt_or_eq (-dExp b) (Fexp c)).
assert (Fbounded b c); auto with zarith float.
apply FcanonicBound with radix; auto with zarith.
intros.
assert (powerRZ radix (Fexp c) / 2 <= c')%R.
rewrite H4.
unfold FtoRradix; apply RleBoundRoundl with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound.
apply Zlt_le_trans with (Zpower_nat radix 1); auto with zarith.
unfold Zpower_nat; simpl; rewrite radixEven; auto with zarith.
unfold phi.
apply Rle_trans with (u*radixH*c)%R.
unfold FtoRradix, FtoR,u; simpl.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
apply Rle_trans with (radixH*(powerRZ radix (Fexp c) *
   (powerRZ radix (- prec) *Fnum c)))%R;[idtac|right; ring].
repeat apply Rmult_le_compat_l; auto with real zarith.
apply Rle_trans with (powerRZ radix (- prec) * nNormMin radix prec)%R.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite <- powerRZ_add; auto with real zarith; apply Rle_powerRZ; auto with real zarith.
rewrite inj_pred; unfold Zpred; auto with zarith.
apply Rmult_le_compat_l; auto with real zarith.
rewrite <- (Zabs_eq (Fnum c)).
apply Rle_IZR; apply pNormal_absolu_min with b; auto with zarith real.
case H; auto; intros M.
elim M; intros M1 (M2,M3). 
Contradict M2; auto with zarith.
apply LeR0Fnum with radix; auto with real zarith.
apply Rle_trans with (u*(radixH+0*0)*c)%R;[right; ring|idtac].
apply Rmult_le_compat_r; auto.
apply Rmult_le_compat_l; unfold u; auto with real zarith.
apply Rle_lt_trans with (1:=H6).
replace (FtoRradix e) with (c'+eta)%R.
unfold eta; apply Rle_lt_trans with (c'+0)%R; auto with real zarith.
replace eta with (FtoRradix (Float 1 (-dExp b))).
2: unfold eta, FtoRradix, FtoR; simpl; ring.
unfold FtoRradix; rewrite <- Fplus_correct; auto with zarith.
apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
2: rewrite Fplus_correct; auto with zarith real.
2: replace (FtoR radix (Float 1 (-dExp b))) with eta; auto with real.
2: unfold eta, FtoRradix, FtoR; simpl; ring.
unfold Fplus.
simpl (Fexp (Float 1 (- dExp b))); simpl (Fnum (Float 1 (- dExp b))).
rewrite Zmin_le2.
replace  (1 * Zpower_nat radix (Zabs_nat (- dExp b - - dExp b)))%Z with 1%Z.
split; simpl; auto with zarith.
apply Zlt_Rlt.
rewrite <- Rabs_Zabs; rewrite pGivesBound; rewrite Zpower_nat_Z_powerRZ.
rewrite plus_IZR.
apply Rle_lt_trans with (Rabs ((Fnum c' * Zpower_nat radix (Zabs_nat (Fexp c' - - dExp b)))%Z) + Rabs 1%Z)%R.
apply Rabs_triang.
rewrite mult_IZR; rewrite Zpower_nat_Z_powerRZ.
replace (Rabs (IZR 1)) with 1%R.
apply Rplus_lt_reg_r with (-1)%R.
apply Rle_lt_trans with (Rabs (Fnum c' * powerRZ radix (Zabs_nat (Fexp c' - - dExp b))));[right; ring|idtac].
apply Rmult_lt_reg_l with (powerRZ radix (-dExp b)); auto with real zarith.
apply Rle_lt_trans with (Rabs c').
unfold FtoRradix, FtoR; simpl; repeat rewrite Rabs_mult.
rewrite (Rabs_right (powerRZ radix (Zabs_nat (Fexp c' - - dExp b)))).
rewrite (Rabs_right (powerRZ radix (Fexp c'))).
right;apply trans_eq with (Rabs (Fnum c') * (
  powerRZ radix (- dExp b) *powerRZ radix (Zabs_nat (Fexp c' - - dExp b))))%R;[ring|idtac].
rewrite <- powerRZ_add; auto with real zarith.
replace (- dExp b + Zabs_nat (Fexp c' - - dExp b))%Z with (Fexp c')%Z; auto.
rewrite <- Zabs_absolu; rewrite Zabs_eq; auto with zarith.
assert (-dExp b <= Fexp c')%Z; auto with zarith float.
elim H1; auto with zarith float.
apply Rle_ge; auto with real zarith.
apply Rle_ge; auto with real zarith.
assert (FtoRradix (Float (radixH*nNormMin radix prec+1) (-dExp b)) = 
   radixH*powerRZ radix (prec-1-dExp b) + powerRZ radix (-dExp b))%R.
unfold FtoRradix, FtoR; simpl.
rewrite plus_IZR; rewrite mult_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith.
apply trans_eq with (radixH*(powerRZ radix (Zpred prec)*powerRZ radix (- dExp b)) + powerRZ radix (- dExp b))%R.
simpl; ring.
rewrite <- powerRZ_add; auto with zarith real.
apply Rle_lt_trans with (Float (radixH*nNormMin radix prec+1) (-dExp b)).
unfold FtoRradix; apply RoundAbsMonotoner with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
apply phi_bounded_aux.
fold FtoRradix; rewrite H7.
rewrite Rabs_mult; repeat rewrite Rabs_right; try apply Rle_ge; auto with real.
2: left; apply phi_Pos.
unfold phi.
apply Rle_trans with ((radixH+radix*u)*powerRZ radix (Fexp c))%R.
apply Rle_trans with ((radixH + radix * u) *(u*c))%R;[right; ring|idtac].
apply Rmult_le_compat_l.
apply Rle_trans with (0+0*0)%R; [right; ring|apply Rplus_le_compat; auto with real zarith].
apply Rmult_le_compat; unfold u; auto with real zarith.
unfold FtoRradix, FtoR, u; simpl.
apply Rle_trans with (powerRZ radix (- prec) * (powerRZ radix prec * powerRZ radix (Fexp c)))%R.
apply Rmult_le_compat_l; auto with real zarith.
apply Rmult_le_compat_r; auto with real zarith.
rewrite <- Zpower_nat_Z_powerRZ; rewrite <- pGivesBound.
apply Rle_IZR.
apply Zle_trans with (Zabs (Fnum c)); auto with zarith float.
assert (Fbounded b c); [apply FcanonicBound with radix|idtac]; auto with zarith float.
repeat rewrite <- powerRZ_add; auto with real zarith.
replace ((- prec + (prec + Fexp c)))%Z with (Fexp c); auto with real; ring.
apply Rle_trans with ((radixH + radix * u) * powerRZ radix (prec-1-dExp b))%R.
apply Rmult_le_compat_l.
apply Rle_trans with (0+0*0)%R; [right; ring|unfold u; apply Rplus_le_compat; auto with real zarith].
apply Rle_powerRZ; auto with real zarith.
rewrite Rmult_plus_distr_r.
apply Rplus_le_compat; auto with real.
pattern (IZR radix) at 1; replace (IZR radix) with (powerRZ radix 1);[idtac|simpl; auto with real].
unfold u; repeat rewrite <- powerRZ_add; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
rewrite H7.
apply Rle_lt_trans with (powerRZ radix (- dExp b) *(powerRZ radix prec / 2+1))%R.
rewrite Rmult_plus_distr_l; apply Rplus_le_compat; auto with real.
unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith; simpl.
replace (IZR radixH) with (radix/2)%R.
right; field; auto with real zarith.
rewrite radixEven; rewrite mult_IZR; simpl; field; auto with real.
apply Rmult_lt_compat_l; auto with real zarith.
apply Rplus_lt_reg_r with (1-powerRZ radix prec / 2)%R.
apply Rmult_lt_reg_l with 2%R; auto with real.
apply Rle_lt_trans with (IZR 2*IZR 2)%R;[simpl; right; ring|idtac].
apply Rlt_le_trans with (powerRZ radix prec)%R;[idtac|right; field; auto with real].
apply Rle_lt_trans with (powerRZ radix 2); auto with real zarith.
apply Rle_trans with (radix*radix)%R;[idtac|simpl; right; ring].
apply Rmult_le_compat; auto with real zarith.
rewrite Rabs_right; try apply Rle_ge; auto with real.
replace (- dExp b - - dExp b)%Z with 0%Z; auto with zarith.
elim H1; auto with zarith float.
intros.
apply Rlt_le_trans with (Float 1 (-(dExp b))).
unfold FtoRradix, FtoR; simpl.
unfold Rdiv; rewrite Rmult_comm; rewrite H5.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rlt_le_trans with (/1)%R; auto with real.
unfold FtoRradix; apply RleBoundRoundl with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith float.
apply vNumbMoreThanOne with radix prec; auto with zarith.
apply Rle_trans with (0+eta)%R.
right; unfold eta, FtoR; simpl; ring.
apply Rplus_le_compat_r.
unfold FtoRradix; apply RleRoundedR0 with b prec (Closest b radix) (phi*c)%R; auto with zarith real float.
apply ClosestRoundedModeP with prec; auto with zarith.
apply Rmult_le_pos; auto.
left; apply phi_Pos.
Qed.


Lemma Algo1_correct_aux_aux:forall (c cinf:float) (r:R),
   Fcanonic radix b c -> (0 <= c)%R ->
   (powerRZ radix (Fexp c)/2 < r)%R ->
   Closest b radix (c-r) cinf ->
   (FtoRradix cinf <= FPred b radix prec c)%R.
intros.
assert (N:Fbounded b c).
apply FcanonicBound with radix; auto.
generalize ClosestMonotone; unfold MonotoneP; intros.
cut (exists f:float, Fbounded b f /\ (FtoRradix f <= FPred b radix prec c)%R /\
   Closest b radix (c-powerRZ radix (Fexp c) / 2)%R f).
intros (f,(L1,(L2,L3))).
apply Rle_trans with (2:=L2).
unfold FtoRradix; apply H3 with b (c-r)%R (c-powerRZ radix (Fexp c) / 2)%R; auto; clear H3.
unfold Rminus; apply Rplus_lt_compat_l; auto with real.
case (Rle_or_lt (powerRZ radix (prec - dExp b)) c); intros.
case (Z_eq_dec (Fnum c) (nNormMin radix prec)); intros.
cut (exists f:float, Fbounded b f /\ 
   (FtoRradix f = (c-powerRZ radix (Fexp c) / 2))%R).
intros (f,(L1,L2)).
exists f; split; auto; split.
rewrite L2; rewrite predNormal1; auto with real zarith.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
unfold Rminus, Rdiv; apply Rplus_le_compat_l.
apply Ropp_le_contravar.
apply Rmult_le_compat_l; auto with real zarith.
simpl; apply Rle_Rinv; auto with real zarith.
replace (radix*1)%R with (IZR radix); auto with real; replace 2%R with (IZR 2); auto with real zarith.
rewrite <- L2; unfold FtoRradix.
apply RoundedModeProjectorIdem with b; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
exists (Float (Zpos (vNum b) -radixH) (Fexp c-1)).
split; try split.
apply Zle_lt_trans with (Zabs (Zpos (vNum b) - radixH)); auto with zarith.
rewrite Zabs_eq; auto with zarith.
apply Zplus_le_reg_l with (radixH).
ring_simplify.
rewrite pGivesBound; apply Zle_trans with (Zpower_nat radix 1); auto with zarith.
unfold Zpower_nat;simpl.
ring_simplify; rewrite radixEven; auto with zarith.
simpl.
assert (- dExp b < Fexp c)%Z; auto with zarith.
apply GepetaGeExp; auto.
unfold FtoRradix, FtoR.
replace (Fnum (Float (Zpos (vNum b) - radixH) (Fexp c - 1)))
  with (Zpos (vNum b) - radixH)%Z; auto.
simpl (Fexp (Float (Zpos (vNum b) - radixH) (Fexp c - 1))).
unfold Zminus; rewrite plus_IZR.
rewrite Ropp_Ropp_IZR.
rewrite pGivesBound; rewrite e; unfold nNormMin; repeat rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith; simpl.
replace (radix*1)%R with (2*radixH)%R.
field; auto with real zarith.
rewrite radixEven; rewrite mult_IZR; simpl; ring.
exists (FPred b radix prec c); split.
apply FBoundedPred; auto with zarith.
split; auto with real.
apply ClosestSuccPred with prec; auto with zarith.
apply FBoundedPred; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite FSucPred; fold FtoRradix; auto with zarith.
replace (c - powerRZ radix (Fexp c) / 2 - c)%R with (-(powerRZ radix (Fexp c)/2))%R;[idtac|ring].
rewrite Rabs_Ropp; rewrite (Rabs_right (powerRZ radix (Fexp c) / 2)).
2: apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
rewrite  predNormal2; auto.
replace  (c - powerRZ radix (Fexp c) / 2 - (c - powerRZ radix (Fexp c)))%R with
    (powerRZ radix (Fexp c) / 2)%R.
rewrite Rabs_right; auto with real.
apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
field; auto with real.
rewrite predNormal2; auto with zarith real.
replace  (c - powerRZ radix (Fexp c) / 2 - (c - powerRZ radix (Fexp c)))%R with
    (powerRZ radix (Fexp c) / 2)%R.
rewrite Rabs_right; auto with real.
2: apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
2: field; auto with real.
case (Zle_lt_or_eq (nNormMin radix prec +1) (Fnum c)).
assert (nNormMin radix prec <= Fnum c)%Z; auto with zarith.
rewrite <- (Zabs_eq (Fnum c)).
apply pNormal_absolu_min with b; auto with zarith real.
apply GepetaIsNormal; auto.
apply LeR0Fnum with radix; auto with real zarith.
intros.
rewrite predNormal2; auto with zarith real.
rewrite FPredSimpl4; auto with zarith.
simpl; unfold FtoRradix, FtoR, Zpred; simpl.
rewrite plus_IZR.
replace (Fnum c * powerRZ radix (Fexp c) - powerRZ radix (Fexp c) / 2 -
    ((Fnum c + (-1)%Z) * powerRZ radix (Fexp c) - powerRZ radix (Fexp c)))%R with
 ((3*powerRZ radix (Fexp c)/2))%R.
rewrite Rabs_right.
apply Rle_trans with (1*powerRZ radix (Fexp c) / 2)%R;auto with real.
right; unfold Rdiv; ring.
unfold Rdiv; apply Rmult_le_compat_r; auto with real.
apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with 2%R; auto with real.
unfold Rdiv; apply Rle_ge; repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith.
right; simpl; ring.
simpl; field.
assert (- pPred (vNum b) < Fnum c)%Z; auto with zarith.
apply Zle_lt_trans with (2:=H5).
apply Zle_trans with 0%Z; auto with zarith.
assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
unfold nNormMin; auto with zarith.
apply FPredCanonic; auto with zarith float.
case H4; intros.
assert (FtoRradix (Float 1 (prec-dExp b))=powerRZ radix (prec - dExp b))%R.
unfold FtoRradix, FtoR; simpl; ring.
rewrite <- H7.
unfold FtoRradix; rewrite <- FnormalizeCorrect with radix b prec (Float 1 (prec-dExp b)); auto.
apply FPredProp; auto with zarith.
apply FnormalizeCanonic; auto with zarith.
split; simpl; auto with zarith float.
apply vNumbMoreThanOne with radix prec; auto with zarith.
rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite H7; auto.
assert (c=Float (nNormMin radix prec) (-dExp b+1)).
apply FcanonicUnique with radix b prec; auto with zarith real.
left; split; try split; simpl; auto with zarith float.
rewrite Zabs_eq.
apply ZltNormMinVnum; auto with zarith.
unfold nNormMin; auto with zarith.
rewrite <- PosNormMin with radix b prec; auto with zarith.
fold FtoRradix; rewrite <- H6; unfold FtoRradix, FtoR; simpl.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + (- dExp b + 1))%Z with (prec-dExp b)%Z; auto.
rewrite inj_pred; auto with zarith.
absurd (Fnum c = nNormMin radix prec)%Z; auto with zarith.
rewrite H7; simpl; auto.
assert ((nNormMin radix prec  < Fnum (FPred b radix prec c)))%Z; auto with zarith.
rewrite FPredSimpl4; auto with zarith.
simpl; unfold Zpred; auto with zarith.
assert (0 < pPred (vNum b))%Z.
apply pPredMoreThanOne with radix prec; auto with zarith.
assert (0 < Fnum c)%Z; auto with zarith.
apply Zle_lt_trans with (2:=H5).
unfold nNormMin; auto with zarith.
intros.
rewrite FPredSimpl4 with (x:=c); auto with zarith.
rewrite FPredSimpl2; auto with zarith.
simpl.
replace (c - powerRZ radix (Fexp c) / 2 -
    FtoR radix (Float (pPred (vNum b)) (Zpred (Fexp c))))%R with
 (powerRZ radix (Fexp c)* (/2 +/radix))%R.
rewrite Rabs_right; unfold Rdiv.
apply Rmult_le_compat_l; auto with real zarith.
apply Rle_trans with (/2+0)%R; auto with real zarith.
apply Rle_ge; apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (0+0)%R; auto with real zarith.
apply Rplus_le_compat; auto with real zarith.
unfold FtoRradix, FtoR; simpl.
rewrite <- H5; unfold pPred, Zpred; repeat rewrite plus_IZR; rewrite pGivesBound; simpl.
unfold nNormMin; repeat rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith; simpl.
field; auto with real zarith.
rewrite <- H5; simpl; unfold Zpred; auto with zarith.
assert (-dExp b < Fexp c)%Z; auto with zarith.
apply GepetaGeExp; auto.
assert (0 < pPred (vNum b))%Z.
apply pPredMoreThanOne with radix prec; auto with zarith.
assert (0 < Fnum c)%Z; auto with zarith.
rewrite <- H5; unfold nNormMin; auto with zarith.
apply Zlt_le_trans with (0+1)%Z; auto with zarith.
case (Zle_lt_or_eq (-dExp b) (Fexp c)); auto.
assert (Fbounded b c); auto with zarith float.
intros; absurd  (c < powerRZ radix (prec - dExp b))%R; auto.
apply Rle_not_lt.
unfold FtoRradix, FtoR; simpl.
replace (prec-dExp b)%Z with ((prec-1)+(-dExp b+1))%Z;[idtac| ring].
rewrite powerRZ_add; auto with real zarith.
apply Rmult_le_compat; auto with real zarith.
apply Rle_trans with (nNormMin radix prec).
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
apply Rle_powerRZ; auto with real zarith.
rewrite inj_pred; auto with zarith.
rewrite <- (Zabs_eq (Fnum c)).
apply Rle_IZR; apply pNormal_absolu_min with b; auto with zarith real.
case H; auto.
intros L; elim L; intros L1 (L2,L3).
Contradict L2; auto with zarith.
apply LeR0Fnum with radix; auto with real zarith.
apply Rle_powerRZ; auto with zarith real.
intros.
exists (FPred b radix prec c); split.
apply FBoundedPred; auto with zarith.
split; auto with real.
apply ClosestSuccPred with prec; auto with zarith.
apply FBoundedPred; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite FSucPred; fold FtoRradix; auto with zarith.
replace (c - powerRZ radix (Fexp c) / 2 - c)%R with (-(powerRZ radix (Fexp c)/2))%R;[idtac|ring].
rewrite Rabs_Ropp; rewrite (Rabs_right (powerRZ radix (Fexp c) / 2)).
2: apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
rewrite predSmallOnes; auto.
unfold eta; replace (-dExp b)%Z with (Fexp c).
replace  (c - powerRZ radix (Fexp c) / 2 - (c - powerRZ radix (Fexp c)))%R with
    (powerRZ radix (Fexp c) / 2)%R.
rewrite Rabs_right; auto with real.
apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
field; auto with real.
rewrite Rabs_right; try apply Rle_ge; auto with real.
repeat rewrite predSmallOnes; auto.
unfold eta; rewrite H5.
replace (c - powerRZ radix (Fexp c) / 2 - (c - powerRZ radix (Fexp c)))%R
 with (powerRZ radix (Fexp c) */ 2)%R;[idtac|field].
replace (c - powerRZ radix (Fexp c) / 2 -
    (c - powerRZ radix (Fexp c) - powerRZ radix (Fexp c)))%R with
     ((3*powerRZ radix (Fexp c) */ 2))%R;[idtac|field].
repeat rewrite Rabs_right; try apply Rle_ge.
apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with (1*powerRZ radix (Fexp c))%R; auto with real.
apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith.
simpl; right; ring.
repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith.
simpl; right; ring.
apply Rmult_le_pos; auto with real zarith.
rewrite Rabs_right; try apply Rle_ge; auto with real.
apply FPredCanonic; auto with zarith.
case (Rle_or_lt 0 (c-eta)); intros.
rewrite Rabs_right;[idtac|apply Rle_ge; auto with real].
apply Rle_lt_trans with (FtoRradix c); auto with real.
apply Rle_trans with (c-0)%R; auto with real.
unfold Rminus, eta; auto with real zarith.
rewrite Rabs_left; auto.
apply Rle_lt_trans with eta.
apply Rle_trans with (eta-c)%R;[right; ring|idtac].
apply Rle_trans with (eta-0)%R;[auto with real|right; ring].
unfold Rminus; apply Rplus_le_compat_l; auto with real.
unfold eta; apply Rlt_powerRZ; auto with zarith real.
rewrite Rabs_right; try apply Rle_ge; auto with real.
rewrite Rabs_right; try apply Rle_ge; auto with real.
Qed.

Lemma Algo1_correct_aux_aux2:forall (c csup:float) (r:R),
   Fcanonic radix b c -> (0 <= c)%R ->
   (powerRZ radix (Fexp c)/2 < r)%R ->
   Closest b radix (c+r) csup ->
   (FtoRradix (FSucc b radix prec c) <= csup)%R.
intros.
assert (N:Fbounded b c).
apply FcanonicBound with radix; auto.
generalize ClosestMonotone; unfold MonotoneP; intros.
cut (exists f:float, Fbounded b f /\ (FtoRradix (FSucc b radix prec c) <= f)%R /\
   Closest b radix (c+powerRZ radix (Fexp c) / 2)%R f).
intros (f,(L1,(L2,L3))).
apply Rle_trans with (1:=L2).
unfold FtoRradix; apply H3 with b (c+powerRZ radix (Fexp c) / 2)%R (c+r)%R; auto; clear H3.
unfold Rminus; apply Rplus_lt_compat_l; auto with real.
exists (FSucc b radix prec c); split.
apply FBoundedSuc; auto with zarith.
split; auto with real.
apply ClosestSuccPred with prec; auto with zarith.
apply FBoundedSuc; auto with zarith.
apply FSuccCanonic; auto with zarith.
rewrite succNormal; auto with zarith.
replace (c + powerRZ radix (Fexp c) / 2 - 
  (c + powerRZ radix (Fexp c)))%R with
    (-(powerRZ radix (Fexp c)/2))%R.
2: field.
rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
rewrite succNormal; auto with zarith.
rewrite succNormal; auto with zarith.
replace (c + powerRZ radix (Fexp c) / 2 -
    (c + powerRZ radix (Fexp c) + 
   powerRZ radix (Fexp (FSucc b radix prec c))))%R with
   (-(powerRZ radix (Fexp c)/2+powerRZ radix 
      (Fexp (FSucc b radix prec c))))%R.
2: field.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rle_trans with (powerRZ radix (Fexp c) / 2+0)%R; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; auto with real.
apply Rplus_le_compat; auto with real zarith.
unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
apply FSuccCanonic; auto with zarith.
apply Rle_trans with (1:=H0).
left; unfold FtoRradix; apply FSuccLt; auto with zarith.
rewrite FPredSuc; fold FtoRradix; auto with zarith.
replace (c + powerRZ radix (Fexp c) / 2 - c)%R with ((powerRZ radix (Fexp c)/2))%R;[idtac|ring].
rewrite (Rabs_right (powerRZ radix (Fexp c) / 2)).
2: apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
rewrite  succNormal; auto.
replace  (c + powerRZ radix (Fexp c) / 2 - (c + powerRZ radix (Fexp c)))%R with
    (-(powerRZ radix (Fexp c) / 2))%R.
rewrite Rabs_Ropp; rewrite Rabs_right; auto with real.
apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
field; auto with real.
Qed.



Lemma Algo1_correct_aux: forall (c c' e cinf csup:float),
  Fcanonic radix b c -> 
  (0 <= c)%R ->
  Closest b radix (phi*c) c' ->
  Closest b radix (c'+eta) e ->
  Closest b radix (c-e) cinf ->
  Closest b radix (c+e) csup ->
  (FtoRradix cinf <= FPred b radix prec c)%R
   /\  (FtoRradix (FSucc b radix prec c) <= csup)%R .  
intros c c' e cinf csup Cc Cpos Hc' He Hcinf Hcsup.
assert (powerRZ radix (Fexp c)/2 < e)%R.
apply eGe with c'; auto.
split.
apply Algo1_correct_aux_aux with e; auto.
apply Algo1_correct_aux_aux2 with e; auto.
Qed.

Lemma PredSucc_Algo1_correct: forall (c c' e cinf csup:float),
  Fcanonic radix b c -> 
  Closest b radix (phi*(Rabs c)) c' ->
  Closest b radix (c'+eta) e ->
  Closest b radix (c-e) cinf ->
  Closest b radix (c+e) csup ->
  (FtoRradix cinf <= FPred b radix prec c)%R
   /\  (FtoRradix (FSucc b radix prec c) <= csup)%R .  
intros c c' e cinf csup Cc Hc' He Hcinf Hcsup.
case (Rle_or_lt 0 c); intros.
apply Algo1_correct_aux with c' e; auto.
rewrite <- (Rabs_right c); auto.
apply Rle_ge; auto.
assert ((Fopp csup <= FPred b radix prec (Fopp c))%R 
   /\ (FSucc b radix prec (Fopp c) <= (Fopp cinf))%R).
apply Algo1_correct_aux with c' e; auto.
apply FcanonicFopp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
replace (FtoRradix (Fopp c)) with (Rabs c); auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
rewrite Rabs_left; auto with real.
replace (Fopp c -e)%R with (-(c+e))%R.
apply ClosestOpp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
replace (Fopp c +e)%R with (-(c-e))%R.
apply ClosestOpp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
elim H0; intros L1 L2; clear H0; split; apply Ropp_le_cancel.
rewrite FPredFopFSucc; auto with zarith.
apply Rle_trans with (FSucc b radix prec (Fopp c)).
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
apply Rle_trans with (1:=L2).
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
apply Rle_trans with (Fopp csup).
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
apply Rle_trans with (1:=L1).
rewrite FPredFopFSucc; auto with zarith.
rewrite Fopp_Fopp.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
Qed.

Hypothesis precisionGreaterThanbis : 4 <= prec.

Lemma eLe: forall (c c' e:float),
  Fcanonic radix b c -> 
  (0 <= c)%R ->
  Closest b radix (phi*c) c' ->
  Closest b radix (c'+eta) e -> 
   (-dExp b <= Fexp c-2)%Z ->
   (e <= powerRZ radix (Fexp c)*(radix/2+powerRZ radix (-2)))%R.
intros c c' e H H0 H1 H2 V.
assert (Bc:(Fbounded b c));[apply FcanonicBound with radix; auto|idtac].
assert (powerRZ radix (Fexp c) * radix / 2=Float radixH (Fexp c))%R.
unfold FtoRradix, FtoR; simpl.
pattern radix at 2; rewrite radixEven; rewrite mult_IZR; simpl; field.
assert (Fbounded b (Float radixH (Fexp c))).
split; simpl.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound; apply Zle_lt_trans with (Zpower_nat radix 1); auto with zarith.
apply Zle_trans with radix;[rewrite radixEven| unfold Zpower_nat; simpl]; auto with zarith.
elim Bc; auto.
assert (powerRZ radix (Fexp c) * radix / 2=
             Float (radixH*nNormMin radix prec) (Fexp c -prec+1))%R.
unfold FtoRradix, FtoR; simpl.
rewrite mult_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite Rmult_assoc; rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + (Fexp c - prec + 1))%Z with (Fexp c).
rewrite radixEven; rewrite mult_IZR; simpl; field.
rewrite inj_pred; auto with zarith.
assert ( (-dExp b <= Fexp c -prec+1)%Z 
   ->    (Fnormal radix b (Float (radixH*nNormMin radix prec) 
           (Fexp c -prec+1)))).
intros I; split; try split; simpl; auto with zarith.
rewrite Zabs_eq.
unfold nNormMin; rewrite pGivesBound.
apply Zlt_le_trans with (radix*Zpower_nat radix (pred prec))%Z; auto with zarith.
apply Zmult_gt_0_lt_compat_r; auto with zarith.
apply Zlt_gt; auto with zarith.
pattern radix at 1; replace radix with (Zpower_nat radix 1).
rewrite <- Zpower_nat_is_exp; auto with zarith.
unfold Zpower_nat; simpl; auto with zarith.
unfold nNormMin; auto with zarith.
rewrite Zabs_eq.
replace (radix * (radixH * nNormMin radix prec))%Z with
   (radixH * (radix * nNormMin radix prec))%Z;[idtac| ring].
rewrite <- (PosNormMin radix b prec); auto with zarith.
apply Zle_trans with (1*Zpos (vNum b) )%Z; auto with zarith.
unfold nNormMin; auto with zarith.
assert (powerRZ radix (Fexp c) * radix / 2 =
(Float (radixH * nNormMin radix prec) (Fexp c - prec + 1)))%R.
unfold FtoRradix, FtoR; simpl.
rewrite mult_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite Rmult_assoc; rewrite <- powerRZ_add; auto with real zarith.
replace (IZR radixH) with (radix/2)%R.
replace (pred prec + (Fexp c - prec + 1))%Z with (Fexp c); [unfold Rdiv; ring|idtac].
rewrite inj_pred; auto with zarith; unfold Zpred; ring.
rewrite radixEven; rewrite mult_IZR; simpl; field.
assert (c' <= powerRZ radix (Fexp c) * radix / 2)%R.
rewrite H3.
unfold FtoRradix; rewrite <- FnormalizeCorrect  with radix b prec (Float radixH (Fexp c)); auto.
generalize ClosestMonotone; unfold MonotoneP; intros T.
apply T with b (phi*c)%R 
  (powerRZ radix (Fexp c)*(radixH+powerRZ radix (1-prec) /2))%R; auto; clear T.
apply Rle_lt_trans with (phi*((powerRZ radix prec -1)*powerRZ radix (Fexp c)))%R.
apply Rmult_le_compat_l.
left; apply phi_Pos.
unfold FtoRradix, FtoR; simpl; apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with (Zpred (Zpos (vNum b))).
apply Rle_IZR.
assert (Fnum c < (Zpos (vNum b)))%Z; auto with zarith float.
apply Zle_lt_trans with (Zabs (Fnum c)); auto with zarith float.
unfold Zpred; rewrite plus_IZR; rewrite pGivesBound; rewrite Zpower_nat_Z_powerRZ.
simpl; right; ring.
apply Rle_lt_trans with (powerRZ radix (Fexp c)*(phi*(powerRZ radix prec - 1)))%R;[right; ring|idtac].
apply Rmult_lt_compat_l; auto with real zarith.
unfold phi.
apply Rle_lt_trans with ((radixH+radix*u)*(1-powerRZ radix (-prec)))%R.
right; apply trans_eq with ((radixH + radix * u)*
  (powerRZ radix prec*u - u))%R;[ring|unfold u].
replace (powerRZ radix prec * powerRZ radix (- prec))%R with 1%R; auto with real.
rewrite <- powerRZ_add; auto with real zarith.
replace (prec+-prec)%Z with 0%Z; simpl; auto with zarith.
apply Rle_lt_trans with (radixH+((radix*u-radixH*powerRZ radix (-prec))-radix*u
  *powerRZ radix (-prec)))%R;[right; ring|idtac].
apply Rplus_lt_compat_l.
replace (IZR radixH) with (radix/2)%R.
replace (radix  * u - radix/2 * powerRZ radix (- prec))%R with 
  (powerRZ radix (1 - prec) / 2)%R.
apply Rlt_le_trans with (powerRZ radix (1 - prec) / 2-0)%R;[idtac|right; ring].
unfold Rminus; apply Rplus_lt_compat_l; apply Ropp_lt_contravar.
apply Rle_lt_trans with (radix*u*0)%R;[right; ring|idtac].
unfold u; apply Rmult_lt_compat_l; auto with real zarith.
apply Rle_lt_trans with (radix*0)%R;[right; ring|idtac].
apply Rmult_lt_compat_l; auto with real zarith.
unfold u, Zminus; rewrite powerRZ_add; auto with real zarith.
simpl; field.
rewrite radixEven; rewrite mult_IZR; simpl; field; auto with real.
apply ClosestSuccPred with prec; auto with zarith real float.
rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite <- H3.
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    powerRZ radix (Fexp c) * radix / 2)%R with
    (powerRZ radix (Fexp c)*powerRZ radix (1 - prec) / 2)%R.
2: replace (IZR radixH) with (radix/2)%R;[field|idtac].
2:rewrite radixEven; rewrite mult_IZR; simpl; field.
rewrite Rabs_right.
2: apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
rewrite succNormal; auto with zarith float.
unfold FtoRradix; rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite <- H3.
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    (powerRZ radix (Fexp c) * radix / 2 +
     powerRZ radix (Fexp (Fnormalize radix b prec (Float radixH (Fexp c))))))%R
  with (powerRZ radix (Fexp c)*powerRZ radix (1 - prec) / 2
         - powerRZ radix (Fexp (Fnormalize radix b prec (Float radixH (Fexp c)))))%R.
case (Zle_or_lt (- dExp b) (Fexp c - prec + 1)); intros I.
replace (Fnormalize radix b prec (Float radixH (Fexp c))) with
    (Float (radixH * nNormMin radix prec) (Fexp c - prec + 1)).
simpl ((Fexp (Float (radixH * nNormMin radix prec) (Fexp c - prec + 1)))).
replace (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2 -
    powerRZ radix (Fexp c - prec + 1))%R with 
   (-(powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2))%R.
rewrite Rabs_Ropp.
rewrite Rabs_right; auto with real.
apply Rle_ge; unfold Rdiv;repeat apply Rmult_le_pos; auto with real zarith.
replace (Fexp c - prec + 1)%Z with (Fexp c+(1-prec))%Z;[idtac| ring].
rewrite powerRZ_add; auto with real zarith; field.
apply FcanonicUnique with radix b prec; auto with zarith float.
left; apply H6; auto.
rewrite FnormalizeCorrect; auto with zarith float; fold FtoRradix; rewrite <- H5;auto.
rewrite Rabs_left1.
apply Rplus_le_reg_l with 
  (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2)%R.
apply Rle_trans with (powerRZ radix (Fexp c) * powerRZ radix (1 - prec))%R.
right; field.
apply Rle_trans with 
 (powerRZ radix (Fexp (Fnormalize radix b prec (Float radixH (Fexp c)))))%R;[idtac|right; ring].
rewrite <- powerRZ_add; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
apply Zle_trans with (-dExp b)%Z; auto with zarith.
assert (Fbounded b (Fnormalize radix b prec (Float radixH (Fexp c)))); auto with zarith float.
apply Rplus_le_reg_l with 
 (powerRZ radix (Fexp (Fnormalize radix b prec (Float radixH (Fexp c))))).
ring_simplify.
apply Rle_trans with (powerRZ radix (Fexp c) * powerRZ radix (1 - prec))%R.
unfold Rdiv; apply Rle_trans with (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) *1)%R;[idtac|right; ring].
apply Rmult_le_compat_l; [apply Rmult_le_pos; auto with real zarith|idtac].
apply Rle_trans with (/1)%R; auto with real.
rewrite <- powerRZ_add; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
apply Zle_trans with (-dExp b)%Z; auto with zarith.
assert (Fbounded b (Fnormalize radix b prec (Float radixH (Fexp c)))); auto with zarith float.
replace (IZR radixH) with (radix/2)%R;[field|idtac].
rewrite radixEven; rewrite mult_IZR; simpl; field.
unfold FtoRradix; rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite <- H3.
unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite <- H3.
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    powerRZ radix (Fexp c) * radix / 2)%R with
    (powerRZ radix (Fexp c)*powerRZ radix (1 - prec) / 2)%R.
2: replace (IZR radixH) with (radix/2)%R;[field|idtac].
2:rewrite radixEven; rewrite mult_IZR; simpl; field.
rewrite Rabs_right.
2: apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
case (Zle_or_lt (- dExp b) (Fexp c - prec + 1)); intros I.
replace (Fnormalize radix b prec (Float radixH (Fexp c)))
  with (Float (radixH * nNormMin radix prec) (Fexp c - prec + 1)).
2: apply FcanonicUnique with radix b prec; auto with zarith float.
2: left; apply H6; auto.
2: rewrite FnormalizeCorrect; auto with zarith float; fold FtoRradix; rewrite <- H5;auto.
case (Rle_or_lt (powerRZ radix (prec - dExp b)) 
                        (powerRZ radix (Fexp c) * radix / 2)); intros M.
case (Z_eq_dec  (radixH * nNormMin radix prec)  (nNormMin radix prec)); intros N.
rewrite predNormal1; auto.
rewrite <- H7.
simpl ((Fexp (Float (radixH * nNormMin radix prec) (Fexp c - prec + 1)))).
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    (powerRZ radix (Fexp c) * radix / 2 -
     powerRZ radix (Fexp c - prec + 1 - 1)))%R with
  ((powerRZ radix (Fexp c) *powerRZ radix (1 - prec)) *(/ 2+/radix))%R.
rewrite Rabs_right.
unfold Rdiv; apply Rmult_le_compat_l.
apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (/2+0)%R; auto with real zarith.
apply Rle_ge; repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (0+0)%R; try apply Rplus_le_compat; auto with real zarith.
replace (Fexp c - prec + 1-1)%Z with (Fexp c+(1-prec)+(-1))%Z;[idtac|ring].
repeat rewrite powerRZ_add; auto with real zarith.
simpl (powerRZ radix (-1)).
replace (IZR radixH) with (radix/2)%R;[field; auto with real zarith|idtac].
rewrite radixEven; rewrite mult_IZR; simpl; field.
left; auto.
rewrite <- H7; auto.
rewrite predNormal2; auto.
rewrite <- H7.
simpl ((Fexp (Float (radixH * nNormMin radix prec) (Fexp c - prec + 1)))).
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    (powerRZ radix (Fexp c) * radix / 2 - powerRZ radix (Fexp c - prec + 1)))%R
   with ((3*(powerRZ radix (Fexp c) * powerRZ radix (1 - prec)/ 2)))%R.
rewrite Rabs_right; auto with real.
apply Rle_trans with (1*(powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2))%R;
  [right; ring|apply Rmult_le_compat_r].
unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith; simpl; right; ring.
unfold Rdiv; apply Rle_ge; repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith; simpl; right; ring.
replace (Fexp c - prec + 1)%Z with (Fexp c+(1-prec))%Z;[idtac| ring].
rewrite powerRZ_add; auto with real zarith.
replace (IZR radixH) with (radix/2)%R;[field|idtac].
rewrite radixEven; rewrite mult_IZR; simpl; field.
left; auto.
rewrite <- H7; auto.
rewrite predSmallOnes.
rewrite <- H7.
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    (powerRZ radix (Fexp c) * radix / 2 - eta))%R with
    (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2 +eta)%R.
rewrite Rabs_right.
apply Rle_trans with (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2+0)%R; auto with real.
apply Rplus_le_compat_l.
unfold eta; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; auto with real.
apply Rplus_le_compat; try unfold eta; auto with real zarith.
unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
replace (IZR radixH) with (radix/2)%R;[field|idtac].
rewrite radixEven; rewrite mult_IZR; simpl; field.
left; auto.
rewrite <- H7; auto.
rewrite Rabs_right; auto.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
rewrite predSmallOnes.
unfold FtoRradix; rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite <- H3.
replace (powerRZ radix (Fexp c) * (radixH + powerRZ radix (1 - prec) / 2) -
    (powerRZ radix (Fexp c) * radix / 2 - eta))%R with
    (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2 +eta)%R.
rewrite Rabs_right.
apply Rle_trans with (powerRZ radix (Fexp c) * powerRZ radix (1 - prec) / 2+0)%R; auto with real.
apply Rplus_le_compat_l.
unfold eta; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; auto with real.
apply Rplus_le_compat; try unfold eta; auto with real zarith.
unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
replace (IZR radixH) with (radix/2)%R;[field|idtac].
rewrite radixEven; rewrite mult_IZR; simpl; field.
apply FnormalizeCanonic; auto with zarith.
unfold FtoRradix; rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite <- H3.
rewrite Rabs_right.
apply Rlt_le_trans with (powerRZ radix (Fexp c+1)).
rewrite powerRZ_add; auto with real zarith.
unfold Rdiv; rewrite Rmult_assoc; apply Rmult_lt_compat_l; auto with real zarith.
simpl; apply Rmult_lt_compat_l; auto with real zarith.
apply Rlt_le_trans with (/1)%R; auto with real.
apply Rle_powerRZ; auto with real zarith.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
assert (powerRZ radix (Fexp c-1)  <= c')%R. 
apply Rle_trans with (Float 1 (Fexp c -1)).
right; unfold FtoRradix, FtoR; simpl; ring.
unfold FtoRradix; apply RleBoundRoundl with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith float.
apply vNumbMoreThanOne with radix prec; auto with zarith.
unfold FtoRradix, FtoR, Zminus; simpl; rewrite powerRZ_add; auto with real zarith.
apply Rle_trans with (/radix*powerRZ radix (Fexp c))%R.
simpl; right; field; auto with real zarith.
rewrite <- Rmult_assoc; apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with (phi*nNormMin radix prec)%R.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
unfold phi, u.
apply Rle_trans with (radixH*(powerRZ radix (-prec)
  *powerRZ radix (pred prec))+radix*(powerRZ radix (-prec)
  *powerRZ radix (pred prec)*powerRZ radix (-prec)))%R;
  [idtac|right; ring].
repeat rewrite <- powerRZ_add; auto with real zarith.
apply Rle_trans with (/radix+0)%R; auto with real; apply Rplus_le_compat.
apply Rle_trans with (1*/radix)%R; auto with real.
apply Rmult_le_compat; auto with real zarith.
rewrite inj_pred; auto with zarith; unfold Zpred.
replace (-prec+(prec+-1))%Z with (-1)%Z;[idtac|ring].
simpl; right; field; auto with real zarith.
apply Rmult_le_pos; auto with real zarith.
apply Rmult_le_compat_l.
left; apply phi_Pos.
rewrite <- (Zabs_eq (Fnum c)).
apply Rle_IZR.
apply pNormal_absolu_min with b; auto with zarith.
case H; auto; intros H2'; elim H2'; intros H3' (H4',H5').
absurd (-dExp b <Fexp c)%Z; auto with zarith.
apply LeR0Fnum with radix; auto with zarith.
assert (powerRZ radix (Fexp c) * (radix / 2 + powerRZ radix (- 2))
   = Float (radixH * radix*radix + 1) (Fexp c-2))%R.
unfold FtoRradix, FtoR.
apply trans_eq with ((radixH *radix*radix + 1) %Z*
   powerRZ radix (Fexp c -  2))%R; auto with real.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite plus_IZR; rewrite mult_IZR; rewrite mult_IZR.
replace (IZR radixH) with (radix/2)%R.
simpl; field; auto with real zarith.
rewrite radixEven; rewrite mult_IZR; simpl; field.
assert (Fbounded  b 
  (Float (radixH * radix*radix+ 1) (Fexp c - 2))).
split; simpl; auto with zarith.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound; apply Zlt_le_trans with (Zpower_nat radix 3); auto with zarith.
replace (Zpower_nat radix 3) with ((radixH * radix * radix+radixH * radix * radix))%Z.
apply Zplus_lt_compat_l; auto with zarith.
apply Zlt_le_trans with (1*2*2)%Z; auto with zarith.
repeat apply Zmult_le_compat; auto with zarith.
unfold Zpower_nat; simpl.
repeat rewrite radixEven; ring.
rewrite H10.
apply RleBoundRoundr with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
fold FtoRradix; rewrite <- H10.
apply Rle_trans with (powerRZ radix (Fexp c) * radix / 2+
    powerRZ radix (Fexp c)*powerRZ radix (- 2))%R;[idtac|right; unfold Rdiv;ring].
apply Rplus_le_compat; auto.
unfold eta; rewrite <- powerRZ_add; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
Qed.


Lemma Algo1_correct_r2_aux_aux1:forall (c cinf:float) (r:R),
   (radix=2)%Z ->
   Fcanonic radix b c -> (0 <= c)%R -> 
   (Fnum c <> nNormMin radix prec) ->
   (Fnum c <> nNormMin radix prec+1)%Z ->
   (r <= 5/4*powerRZ radix (Fexp c))%R ->
   Closest b radix (c-r) cinf ->
   (FtoRradix (FPred b radix prec c) <= cinf)%R.
intros c cinf r K; intros.
assert (Bc:(Fbounded b c));[apply FcanonicBound with radix; auto|idtac].
assert (G1:(0 < 4)%R).
apply Rlt_le_trans with (IZR 4); auto with real zarith; simpl; right; ring.
assert (G2:(0 < 5)%R).
apply Rlt_le_trans with (IZR 5); auto with real zarith; simpl; right; ring.
assert (FtoRradix (FPred b radix prec c) = c -powerRZ radix (Fexp c))%R.
rewrite FPredSimpl4; auto.
unfold FtoRradix, FtoR, Zpred; simpl.
rewrite plus_IZR; simpl; ring.
assert (-pPred (vNum b) < Fnum c)%Z; auto with zarith float.
apply Zlt_le_trans with 0%Z.
assert (0 < pPred (vNum b))%Z; auto with zarith float.
apply pPredMoreThanOne with radix prec; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
assert (c - 5 / 4 * powerRZ radix (Fexp c) - FtoR radix (FPred b radix prec c)
   =  (-(/4 * powerRZ radix (Fexp c))))%R.
fold FtoRradix; rewrite H5; field.
unfold FtoRradix; apply ClosestStrictMonotone2l with b prec (c-r)%R (c-5 / 4 * powerRZ radix (Fexp c))%R; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite H6; rewrite Rabs_Ropp.
rewrite Rabs_right;[idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
rewrite FSucPred; auto with zarith; fold FtoRradix.
replace (c - 5 / 4 * powerRZ radix (Fexp c) - c)%R with (-(5/4*powerRZ radix (Fexp c)))%R by ring.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rmult_lt_compat_r; auto with real zarith.
unfold Rdiv; apply Rle_lt_trans with (1*/4)%R; auto with real.
apply Rmult_lt_compat_r; auto with real.
apply Rlt_le_trans with (IZR 5); auto with real zarith; simpl; right; ring.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
rewrite H6; rewrite Rabs_Ropp.
rewrite Rabs_right;[idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
assert ((FtoRradix (FPred b radix prec (FPred b radix prec c)) = 
        c-2*powerRZ radix (Fexp c)))%R.
assert (FPred b radix prec c = Float (Zpred (Fnum c)) (Fexp c)).
rewrite FPredSimpl4; auto with zarith.
assert (-pPred (vNum b) < Fnum c)%Z; auto with zarith float.
apply Zlt_le_trans with 0%Z.
assert (0 < pPred (vNum b))%Z; auto with zarith float.
apply pPredMoreThanOne with radix prec; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
rewrite H7; rewrite  FPredSimpl4; auto with zarith.
unfold FtoRradix, FtoR; simpl.
unfold Zpred; repeat rewrite plus_IZR; simpl; ring.
simpl.
assert (-pPred (vNum b) < (Zpred (Fnum c)))%Z; auto with zarith float.
apply Zlt_le_trans with (Zpred 0)%Z; unfold pPred, Zpred.
assert (2 < Zpos (vNum b))%Z; auto with zarith float.
rewrite pGivesBound; apply Zle_lt_trans with (Zpower_nat radix 1); auto with zarith. 
unfold Zpower_nat; simpl; auto with zarith.
assert (0 <= Fnum c)%Z; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
simpl; auto with zarith.
fold FtoRradix; rewrite H7.
replace (c - 5 / 4 * powerRZ radix (Fexp c) - (c - 2 * powerRZ radix (Fexp c)))%R
   with  ( 3/ 4 * powerRZ radix (Fexp c))%R by field.
rewrite Rabs_right; auto with real.
apply Rmult_lt_compat_r; auto with real zarith.
unfold Rdiv; apply Rle_lt_trans with (1*/4)%R; auto with real.
apply Rmult_lt_compat_r; auto with real.
apply Rlt_le_trans with (IZR 3); auto with real zarith; simpl; right; ring.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith; simpl; right; ring.
unfold Rminus; apply Rplus_le_compat_l; auto with real.
Qed.

Lemma Algo1_correct_r2_aux_aux2:forall (c c' e cinf:float),
   (radix=2)%Z ->
   Fcanonic radix b c -> (0 <= c)%R -> 
   (Fnum c = nNormMin radix prec+1)%Z ->
     (-dExp b <= Fexp c-2)%Z ->
    Closest b radix (phi*c) c' ->
   Closest b radix (c'+eta) e ->
   Closest b radix (c-e) cinf ->
   (FtoRradix (FPred b radix prec c) <= cinf)%R.
intros.
assert (Bc:(Fbounded b c));[apply FcanonicBound with radix; auto|idtac].
assert (G1:(0 < 4)%R).
apply Rlt_le_trans with (IZR 4); auto with real zarith; simpl; right; ring.
assert (G2:(0 < 5)%R).
apply Rlt_le_trans with (IZR 5); auto with real zarith; simpl; right; ring.
generalize ClosestMonotone; unfold MonotoneP; intros T.
unfold FtoRradix; apply T with b  (c-5 / 4 * powerRZ radix (Fexp c))%R (c-e)%R; auto.
unfold Rminus; apply Rplus_lt_compat_l; auto with real.
apply Ropp_lt_contravar.
apply Rle_lt_trans with (Float 1 (Fexp c)).
apply RleBoundRoundr with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith float.
apply vNumbMoreThanOne with radix prec; auto with zarith.
apply Rle_trans with  (FtoRradix (Float 3 (Fexp c-2))+powerRZ radix (Fexp c -2))%R.
apply Rplus_le_compat.
apply RleBoundRoundr with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith float.
rewrite pGivesBound; apply Zlt_le_trans with (Zpower_nat radix 2); auto with zarith.
unfold Zpower_nat; rewrite H; simpl; auto with zarith.
unfold FtoRradix, FtoR; simpl.
rewrite H2; unfold phi, u.
rewrite plus_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
replace radixH with 1%Z; auto with zarith.
replace (radix*powerRZ radix (- prec))%R with (powerRZ radix (1-prec)).
apply Rle_trans with
   (powerRZ radix (Fexp c) *(powerRZ radix (-prec)*
     ((powerRZ radix (pred prec) +1 + 
          powerRZ radix (1 - prec)*powerRZ radix (pred prec) + 
       powerRZ radix (1 - prec)))))%R;[right; simpl; ring|idtac].
rewrite inj_pred; auto with zarith; unfold Zpred.
replace (powerRZ radix (1 - prec) * powerRZ radix (prec + -1))%R
  with 1%R.
apply Rle_trans with (powerRZ radix (Fexp c) *(3/4))%R.
apply Rmult_le_compat_l; auto with real zarith.
apply Rle_trans with (powerRZ radix (- prec) *
 powerRZ radix (prec + -1) + (2* powerRZ radix (- prec)
  + powerRZ radix (- prec)*powerRZ radix (1 - prec)))%R;[right; ring|idtac].
repeat rewrite <- powerRZ_add; auto with real zarith.
apply Rle_trans with (/2+/4)%R;[apply Rplus_le_compat|right; field].
replace (- prec + (prec + -1))%Z with (-1)%Z by ring.
simpl; rewrite H; simpl; right; field.
apply Rle_trans with 
 (2 * powerRZ radix (- 4) + powerRZ radix (- 4))%R.
apply Rplus_le_compat.
apply Rmult_le_compat_l; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
rewrite H; simpl; apply Rmult_le_reg_l with (IZR 16); auto with real zarith.
apply Rle_trans with (IZR 3);[right; simpl; field|idtac].
apply Rle_trans with (IZR 4);[auto with real zarith|right; simpl; field].
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; field.
rewrite <- powerRZ_add; auto with real zarith.
replace (1 - prec + (prec + -1))%Z with 0%Z by ring; simpl; ring.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
unfold eta; apply Rle_powerRZ; auto with real zarith.
unfold FtoRradix, FtoR; simpl.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; field.
unfold FtoRradix, FtoR; simpl; apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (4/4)%R; auto with real.
right; field.
unfold Rdiv; apply Rmult_lt_compat_r; auto with real.
replace 5%R with (IZR 5);[idtac|simpl; ring].
replace 4%R with (IZR 4);[auto with real zarith|simpl; ring].
assert (FtoRradix (FPred b radix prec c) = c -powerRZ radix (Fexp c))%R.
rewrite FPredSimpl4; auto.
unfold FtoRradix, FtoR, Zpred; simpl.
rewrite plus_IZR; simpl; ring.
assert (-pPred (vNum b) < Fnum c)%Z; auto with zarith float.
apply Zlt_le_trans with 0%Z.
assert (0 < pPred (vNum b))%Z; auto with zarith float.
apply pPredMoreThanOne with radix prec; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
rewrite H2; auto with zarith.
assert (c - 5 / 4 * powerRZ radix (Fexp c) - FtoR radix (FPred b radix prec c)
   =  (-(/4 * powerRZ radix (Fexp c))))%R.
fold FtoRradix; rewrite H7; field.
apply ClosestSuccPred with prec; auto with zarith.
apply FBoundedPred; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite H8; rewrite Rabs_Ropp.
rewrite Rabs_right;[idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
rewrite FSucPred; auto with zarith; fold FtoRradix.
replace (c - 5 / 4 * powerRZ radix (Fexp c) - c)%R with (-(5/4*powerRZ radix (Fexp c)))%R by ring.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rmult_le_compat_r; auto with real zarith.
unfold Rdiv; apply Rle_trans with (1*/4)%R; auto with real.
apply Rmult_le_compat_r; auto with real.
apply Rle_trans with (IZR 5); auto with real zarith; simpl; right; ring.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
rewrite H8; rewrite Rabs_Ropp.
rewrite Rabs_right;[idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
assert (FPred b radix prec c=Float (nNormMin radix prec) (Fexp c)).
rewrite FPredSimpl4; auto with zarith.
replace  (Zpred (Fnum c)) with  (nNormMin radix prec); auto.
rewrite H2; unfold Zpred; ring.
assert (-pPred (vNum b) < Fnum c)%Z; auto with zarith float.
apply Zlt_le_trans with 0%Z.
assert (0 < pPred (vNum b))%Z; auto with zarith float.
apply pPredMoreThanOne with radix prec; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
assert ((FtoRradix (FPred b radix prec (FPred b radix prec c)) = 
        c-3/2*powerRZ radix (Fexp c)))%R.
rewrite H9; rewrite  FPredSimpl2; auto with zarith.
unfold FtoRradix, FtoR; simpl.
rewrite H2; unfold pPred, Zpred; repeat rewrite plus_IZR; rewrite pGivesBound.
unfold nNormMin; repeat rewrite Zpower_nat_Z_powerRZ; simpl.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith.
simpl; rewrite H; simpl; field.
simpl; auto with zarith.
fold FtoRradix; rewrite H10.
replace (c - 5 / 4 * powerRZ radix (Fexp c) - (c - 3/2 * powerRZ radix (Fexp c)))%R
   with  ( / 4 * powerRZ radix (Fexp c))%R by field.
rewrite Rabs_right; auto with real.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
Qed.



Lemma Algo1_correct_r2_aux_aux3:forall (c c' e cinf:float),
   (radix=2)%Z ->
   Fcanonic radix b c -> (0 <= c)%R -> 
   (-dExp b <= Fexp c-3)%Z ->
   (Fnum c = nNormMin radix prec) ->
   Closest b radix (phi*c) c' ->
   Closest b radix (c'+eta) e ->
   Closest b radix (c-e) cinf ->
   (prec=4 -> EvenClosest b radix prec (phi*c)%R c' 
         \/ AFZClosest b radix (c-e)%R cinf) ->
   (FtoRradix (FPred b radix prec c) <= cinf)%R.
intros c c' e cinf H H0 H1 H2 H3 H4 H5 H6 MM.
assert (FtoRradix (FPred b radix prec c) = (c-/2*powerRZ radix (Fexp c)))%R.
rewrite FPredSimpl2; auto with zarith.
unfold FtoRradix, FtoR, pPred, Zpred.
rewrite pGivesBound; rewrite H3; simpl.
rewrite plus_IZR; unfold nNormMin; repeat rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
case (Zle_or_lt (-dExp b) (Fexp c -prec)); intros I.
assert (c - / 2 * powerRZ radix (Fexp c) - powerRZ radix (Fexp c + 1 - prec) -
    FtoR radix (FPred b radix prec c) =
     (-powerRZ radix (Fexp c + 1 - prec)))%R.
fold FtoRradix; rewrite H7; ring.
unfold FtoRradix; apply ClosestStrictMonotone2l with b prec (c-e)%R (c-/2*powerRZ radix (Fexp c) - powerRZ radix (Fexp c +1-prec))%R; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite H8; rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; auto with real zarith.
rewrite FSucPred; auto with zarith; fold FtoRradix.
replace (c - / 2 * powerRZ radix (Fexp c) - powerRZ radix (Fexp c + 1 - prec) - c)%R with
   (-(/ 2 * powerRZ radix (Fexp c) + powerRZ radix (Fexp c + 1 - prec)))%R by ring.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rle_lt_trans with (0+powerRZ radix (Fexp c + 1 - prec))%R;[right; ring|idtac].
apply Rplus_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (/2*0)%R; try apply Rmult_lt_compat_l; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; try apply Rplus_le_compat; auto with real zarith.
apply Rmult_le_pos; auto with real zarith.
rewrite H8; rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; auto with real zarith.
rewrite FPredSimpl2 with b radix prec c; auto with zarith.
rewrite FPredSimpl4; simpl; auto with zarith.
replace (FtoR radix (Float (Zpred (pPred (vNum b))) (Zpred (Fexp c)))) with
    (c-powerRZ radix (Fexp c))%R.
replace (c - / 2 * powerRZ radix (Fexp c) - powerRZ radix (Fexp c + 1 - prec) -
    (c - powerRZ radix (Fexp c)))%R with
    (/ 2 * powerRZ radix (Fexp c) - powerRZ radix (Fexp c + 1 - prec))%R by field.
rewrite Rabs_right.
apply Rplus_lt_reg_r with (powerRZ radix (Fexp c + 1 - prec)).
apply Rmult_lt_reg_l with 2%R; auto with real.
apply Rle_lt_trans with (4*powerRZ radix (Fexp c + 1 - prec))%R;[right; field|idtac].
apply Rle_lt_trans with (powerRZ radix (Fexp c + 3 - prec)).
right; unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl;  ring.
apply Rlt_le_trans with (powerRZ radix (Fexp c));[idtac|right; field].
apply Rlt_powerRZ; auto with real zarith.
apply Rle_ge; apply Rplus_le_reg_l with (powerRZ radix (Fexp c + 1 - prec)).
ring_simplify.
apply Rle_trans with (powerRZ radix (Fexp c -1)); auto with real zarith.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; field.
unfold FtoRradix, FtoR; simpl.
rewrite H3; unfold pPred; rewrite pGivesBound.
unfold nNormMin, Zpred; repeat rewrite plus_IZR.
repeat rewrite Zpower_nat_Z_powerRZ; simpl.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
assert (nNormMin radix prec < pPred (vNum b))%Z; auto with zarith.
apply nNormMimLtvNum; auto with zarith.
unfold Rminus; rewrite Rplus_assoc; apply Rplus_le_compat_l.
apply Rle_trans with (-(/ 2 * powerRZ radix (Fexp c)
  +powerRZ radix (Fexp c + 1 - prec)))%R;[right; ring|idtac].
apply Ropp_le_contravar.
assert (/ 2 * powerRZ radix (Fexp c) + powerRZ radix (Fexp c + 1 - prec)
    = Float  (nNormMin radix prec +2)  (Fexp c -prec))%R.
unfold FtoRradix, FtoR; simpl.
rewrite plus_IZR; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith; unfold Zpred, Zminus.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; rewrite <- Rinv_powerRZ; auto with real zarith.
field; auto with real zarith.
assert (0 < powerRZ 2 prec)%R; auto with real zarith.
rewrite H9; apply RleBoundRoundr with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite Zabs_eq.
rewrite PosNormMin with radix b prec; auto with zarith.
rewrite H; apply Zlt_le_trans with (nNormMin radix prec + nNormMin radix prec)%Z; auto with zarith.
rewrite H; apply Zplus_lt_compat_l.
unfold nNormMin; apply Zle_lt_trans with (Zpower_nat 2 1); auto with zarith.
apply Zeq_le; rewrite H; ring.
unfold nNormMin; auto with zarith.
fold FtoRradix; rewrite <- H9.
apply Rle_trans with ((/ 2 * powerRZ radix (Fexp c) 
   + powerRZ radix (Fexp c- prec)) + powerRZ radix (Fexp c- prec))%R.
2: unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
2: rewrite H; simpl; right; ring.
apply Rplus_le_compat.
2: unfold eta; apply Rle_powerRZ; auto with real zarith.
assert (/ 2 * powerRZ radix (Fexp c) + powerRZ radix (Fexp c - prec)
  = Float (nNormMin radix prec+1) (Fexp c-prec))%R.
unfold FtoRradix, FtoR; simpl; rewrite plus_IZR.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ; simpl.
rewrite inj_pred; auto with zarith; unfold Zpred, Zminus.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite <- Rinv_powerRZ; auto with real zarith; simpl.
rewrite H; simpl; field.
assert (0 < powerRZ 2 prec)%R; auto with real zarith.
rewrite H10.
apply RleBoundRoundr with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
replace (nNormMin radix prec) with (radixH*nNormMin radix prec)%Z.
apply phi_bounded_aux.
replace radixH with 1%Z; auto with zarith.
fold FtoRradix; rewrite <- H10.
unfold phi,u, FtoRradix, FtoR; simpl.
rewrite H3; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith; unfold Zpred.
unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
rewrite <- Rinv_powerRZ; auto with real zarith; simpl.
replace (IZR radixH) with 1%R.
rewrite H; simpl; right; field.
assert (0 < powerRZ 2 prec)%R; auto with real zarith.
replace radixH with 1%Z; auto with real zarith.
case (Zle_lt_or_eq (Fexp c) (-dExp b+prec-1)); auto with zarith; intros I'.
assert (G1: (0 < 8)%R).
apply Rlt_le_trans with (IZR 8); [auto with real zarith|simpl; right; ring].
assert (G2: (0 < 5)%R).
apply Rlt_le_trans with (IZR 5); [auto with real zarith|simpl; right; ring].
assert (c - 5/8* powerRZ radix (Fexp c) - FtoR radix (FPred b radix prec c)
  = (-(/ 8 * powerRZ radix (Fexp c))))%R.
fold FtoRradix; rewrite H7; field.
unfold FtoRradix; apply ClosestStrictMonotone2l with b prec (c-e)%R (c-5/8*powerRZ radix (Fexp c))%R; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite H8; rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; apply Rmult_le_pos; auto with real zarith.
rewrite FSucPred; auto with zarith; fold FtoRradix.
replace (c -  5/8* powerRZ radix (Fexp c) - c)%R with
   (- (5/8*powerRZ radix (Fexp c)))%R by ring.
rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (1*/8)%R;
  [right; ring|unfold Rdiv; apply Rmult_lt_compat_r; auto with real zarith].
apply Rlt_le_trans with (IZR 5)%R; auto with real zarith.
right; simpl; ring.
rewrite H8; rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; apply Rmult_le_pos; auto with real zarith.
rewrite FPredSimpl2 with b radix prec c; auto with zarith.
rewrite FPredSimpl4; simpl; auto with zarith.
replace (FtoR radix (Float (Zpred (pPred (vNum b))) (Zpred (Fexp c)))) with
    (c-powerRZ radix (Fexp c))%R.
replace (c - 5/ 8 * powerRZ radix (Fexp c) - 
    (c - powerRZ radix (Fexp c)))%R with
    (3/ 8 * powerRZ radix (Fexp c))%R  by field.
rewrite Rabs_right.
2: apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
2: apply Rle_trans with (IZR 3); auto with real zarith; simpl; right; ring.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (1*/8)%R;
  [right; ring|unfold Rdiv; apply Rmult_lt_compat_r; auto with real zarith].
apply Rlt_le_trans with (IZR 3)%R; auto with real zarith.
right; simpl; ring.
unfold FtoRradix, FtoR; simpl.
rewrite H3; unfold pPred; rewrite pGivesBound.
unfold nNormMin, Zpred; repeat rewrite plus_IZR.
repeat rewrite Zpower_nat_Z_powerRZ; simpl.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
assert (nNormMin radix prec < pPred (vNum b))%Z; auto with zarith.
apply nNormMimLtvNum; auto with zarith.
unfold Rminus; apply Rplus_le_compat_l; apply Ropp_le_contravar.
assert (5 / 8 * powerRZ radix (Fexp c)= Float 5 (Fexp c-3))%R.
unfold FtoRradix, FtoR, Zminus; simpl.
rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
rewrite H9; apply RleBoundRoundr with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite pGivesBound; apply Zlt_le_trans with (Zpower_nat radix 3); auto with zarith.
rewrite H; simpl; auto with zarith.
fold FtoRradix; rewrite <- H9.
apply Rle_trans with (powerRZ radix (Fexp c-1)+ powerRZ radix (Fexp c-3))%R.
2: right; unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
2: rewrite H; simpl; field.
apply Rplus_le_compat.
2: unfold eta; apply Rle_powerRZ; auto with real zarith.
assert (powerRZ radix (Fexp c - 1) = Float (Zpower_nat radix (Zabs_nat (Fexp c-1+dExp b))) (-dExp b))%R.
unfold FtoRradix, FtoR; simpl; rewrite Zpower_nat_Z_powerRZ.
rewrite <- powerRZ_add; auto with real zarith.
replace (Zabs_nat (Fexp c - 1 + dExp b) + - dExp b)%Z with (Fexp c-1)%Z; auto with zarith.
rewrite <- Zabs_absolu; rewrite Zabs_eq; auto with zarith.
assert (Fsubnormal radix b (Float (Zpower_nat radix (Zabs_nat (Fexp c - 1 + dExp b))) (- dExp b))).
split; try split; simpl; auto with zarith.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound; apply Zpower_nat_monotone_lt; auto with zarith.
apply ZleLe.
apply Zle_trans with (Zabs_nat (Fexp c - 1 + dExp b)+1)%nat; auto with zarith.
rewrite inj_plus; rewrite <- Zabs_absolu; rewrite Zabs_eq; auto with zarith.
simpl; auto with zarith.
rewrite Zabs_eq; auto with zarith.
apply Zle_lt_trans with (Zpower_nat radix (1+Zabs_nat (Fexp c - 1 + dExp b))).
apply Zeq_le;rewrite Zpower_nat_is_exp; auto with zarith.
replace (Zpower_nat radix 1) with radix; auto with zarith.
unfold Zpower_nat; simpl; ring.
rewrite pGivesBound; apply Zpower_nat_monotone_lt; auto with zarith.
apply ZleLe.
apply Zle_trans with ((1+Zabs_nat (Fexp c - 1 + dExp b)+1))%nat; auto with zarith.
repeat rewrite inj_plus; rewrite <- Zabs_absolu; rewrite Zabs_eq; auto with zarith.
apply Zle_trans with (Fexp c +dExp b +1)%Z; auto with zarith.
replace (Z_of_nat 1) with 1%Z; auto with zarith.
rewrite H10.
apply ClosestStrictMonotone2r with b prec (phi*c)%R (powerRZ radix (Fexp c -1) + powerRZ radix (Fexp c -prec))%R; auto with zarith.
right; auto.
fold FtoRradix; rewrite <- H10.
ring_simplify  (powerRZ radix (Fexp c - 1) + powerRZ radix (Fexp c - prec) -
    powerRZ radix (Fexp c - 1))%R.
rewrite Rabs_right; try (apply Rle_ge; auto with real zarith).
rewrite succNormal.
2: right; auto.
2: rewrite <- H10; auto with real zarith.
rewrite <- H10; simpl.
replace (powerRZ radix (Fexp c - 1) + powerRZ radix (Fexp c - prec) -
    (powerRZ radix (Fexp c - 1) + powerRZ radix (- dExp b)))%R with
    ( - (powerRZ radix (- dExp b) - powerRZ radix (Fexp c - prec)))%R by ring.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rplus_lt_reg_r with (powerRZ radix (Fexp c - prec)); ring_simplify.
apply Rle_lt_trans with (powerRZ radix (1+(Fexp c - prec))).
rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; ring.
apply Rlt_powerRZ; auto with real zarith.
apply Rle_ge; apply Rplus_le_reg_l with (powerRZ radix (Fexp c - prec)); ring_simplify.
apply Rle_powerRZ; auto with real zarith.
fold FtoRradix; rewrite <- H10.
ring_simplify  (powerRZ radix (Fexp c - 1) + powerRZ radix (Fexp c - prec) -
    powerRZ radix (Fexp c - 1))%R.
rewrite Rabs_right; try (apply Rle_ge; auto with real zarith).
rewrite predSmallOnes; auto with zarith.
rewrite <- H10; unfold eta.
replace (powerRZ radix (Fexp c - 1) + powerRZ radix (Fexp c - prec) -
    (powerRZ radix (Fexp c - 1) - powerRZ radix (- dExp b)))%R with
   (powerRZ radix (- dExp b)+powerRZ radix (Fexp c - prec))%R by ring.
rewrite Rabs_right.
apply Rle_lt_trans with (0+powerRZ radix (Fexp c - prec))%R; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; auto with real.
apply Rplus_le_compat; auto with real zarith.
right; auto.
rewrite <- H10.
rewrite Rabs_right; try (apply Rle_ge; auto with real zarith).
apply Rlt_powerRZ; auto with real zarith.
unfold phi, u, FtoRradix, FtoR; simpl; rewrite H3.
replace radixH with 1%Z; auto with zarith.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite inj_pred; auto with zarith; unfold Zpred, Zminus.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite <- Rinv_powerRZ; auto with real zarith.
rewrite H; simpl; right; field.
assert (0 < powerRZ 2 prec)%R; auto with real zarith.
case (Zle_lt_or_eq 4 prec); auto with zarith; intros precBis.
assert (c - / 2 * powerRZ radix (Fexp c) - powerRZ radix (1- dExp b) -
    FtoR radix (FPred b radix prec c) = -powerRZ radix (1- dExp b))%R.
fold FtoRradix; rewrite H7; ring.
unfold FtoRradix; apply ClosestStrictMonotone2l with b prec (c-e)%R (c-/2*powerRZ radix (Fexp c) - powerRZ radix (1-dExp b))%R; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite H8; rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; auto with real zarith.
rewrite FSucPred; auto with zarith; fold FtoRradix.
replace (c - / 2 * powerRZ radix (Fexp c) - powerRZ radix (1- dExp b) - c)%R with
   (-(/2*powerRZ radix (Fexp c) + powerRZ radix (1-dExp b)))%R by ring.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rle_lt_trans with (0+powerRZ radix (1- dExp b))%R; auto with real.
apply Rplus_lt_compat_r.
apply Rle_lt_trans with (/2*0)%R; auto with real.
apply Rmult_lt_compat_l; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; auto with real.
apply Rplus_le_compat; try apply Rmult_le_pos; auto with real zarith.
rewrite H8; rewrite Rabs_Ropp; rewrite Rabs_right.
2: apply Rle_ge; auto with real zarith.
rewrite FPredSimpl2 with b radix prec c; auto with zarith.
rewrite FPredSimpl4;auto with zarith.
simpl (Fnum (Float (pPred (vNum b)) (Zpred (Fexp c)))).
simpl (Fexp (Float (pPred (vNum b)) (Zpred (Fexp c)))).
replace (FtoR radix (Float (Zpred (pPred (vNum b))) (Zpred (Fexp c)))) with
    (c-powerRZ radix (Fexp c))%R.
replace (c - / 2 * powerRZ radix (Fexp c) - powerRZ radix (1- dExp b) -
    (c - powerRZ radix (Fexp c)))%R with
    (/ 2 * powerRZ radix (Fexp c) - powerRZ radix (1- dExp b))%R by field.
rewrite Rabs_right.
apply Rplus_lt_reg_r with (powerRZ radix (1- dExp b)); ring_simplify.
apply Rle_lt_trans with (powerRZ radix (1+(1- dExp b))).
rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; ring.
apply Rlt_le_trans with (powerRZ radix (Fexp c-1)).
apply Rlt_powerRZ; auto with real zarith.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; field.
apply Rle_ge; apply Rplus_le_reg_l with (powerRZ radix (1- dExp b)); ring_simplify.
apply Rle_trans with (powerRZ radix (Fexp c-1)).
apply Rle_powerRZ; auto with real zarith.
unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; field.
unfold FtoRradix, FtoR; simpl.
rewrite H3; unfold pPred; rewrite pGivesBound.
unfold nNormMin, Zpred; repeat rewrite plus_IZR.
repeat rewrite Zpower_nat_Z_powerRZ; simpl.
rewrite inj_pred; auto with zarith; unfold Zpred.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
simpl; assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
simpl; assert (nNormMin radix prec < pPred (vNum b))%Z; auto with zarith.
apply nNormMimLtvNum; auto with zarith.
unfold Rminus; rewrite Rplus_assoc; apply Rplus_le_compat_l.
apply Rle_trans with (-(/ 2 * powerRZ radix (Fexp c)
  +powerRZ radix (1- dExp b)))%R;[right; ring|idtac].
apply Ropp_le_contravar.
assert (/ 2 * powerRZ radix (Fexp c) + powerRZ radix (1 - dExp b)
    = Float  (Zpower_nat radix (pred (pred prec)) +2)  (-dExp b))%R.
unfold FtoRradix, FtoR.
simpl (Fnum (Float (Zpower_nat radix (pred (pred prec)) + 2) (- dExp b))).
simpl (Fexp (Float (Zpower_nat radix (pred (pred prec)) + 2) (- dExp b))).
rewrite plus_IZR;  rewrite Zpower_nat_Z_powerRZ; rewrite I'.
repeat rewrite inj_pred; auto with zarith; unfold Zpred, Zminus.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
rewrite H9; apply RleBoundRoundr with b prec (Closest b radix) (c'+eta)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound; apply Zlt_le_trans with (Zpower_nat radix (pred prec+1)); auto with zarith.
apply Zlt_le_trans with (Zpower_nat radix (pred prec)+Zpower_nat radix (pred prec))%Z; auto with zarith.
apply Zplus_lt_compat; auto with zarith.
replace 2%Z with (Zpower_nat radix 1); auto with zarith.
rewrite H; simpl; auto.
rewrite Zpower_nat_is_exp; auto with zarith; rewrite H.
replace (Zpower_nat 2 1) with 2%Z; auto with zarith.
fold FtoRradix; rewrite <- H9.
apply Rle_trans with ( (/2 * powerRZ radix (Fexp c) 
  +powerRZ radix (- dExp b))+powerRZ radix (- dExp b))%R.
unfold eta; apply Rplus_le_compat_r.
2: unfold Zminus; rewrite powerRZ_add; auto with real zarith.
2: rewrite H; simpl; right; ring.
clear H8 H9.
assert ( /2 * powerRZ radix (Fexp c) + powerRZ radix (- dExp b)
  = Float (Zpower_nat radix (pred (pred prec)) + 1) (- dExp b))%R.
unfold FtoRradix, FtoR.
simpl (Fnum (Float (Zpower_nat radix (pred (pred prec)) + 1) (- dExp b))).
simpl (Fexp (Float (Zpower_nat radix (pred (pred prec)) + 1) (- dExp b))).
rewrite plus_IZR;  rewrite Zpower_nat_Z_powerRZ; rewrite I'.
repeat rewrite inj_pred; auto with zarith; unfold Zpred, Zminus.
repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
rewrite H8.
apply RleBoundRoundr with b prec (Closest b radix) (phi*c)%R; auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite Zabs_eq; auto with zarith.
rewrite pGivesBound.
apply Zle_lt_trans with (Zpower_nat radix (pred prec)+1)%Z.
apply Zplus_le_compat_r.
apply Zpower_nat_monotone_le; auto with zarith.
apply Zlt_le_trans with (Zpower_nat radix (pred prec) +Zpower_nat radix (pred prec))%Z.
apply Zplus_lt_compat_l.
apply Zle_lt_trans with (Zpower_nat radix 0); auto with zarith.
pattern prec at 3; replace prec with (pred prec +1); auto with zarith.
rewrite Zpower_nat_is_exp; rewrite H; simpl; auto with zarith.
unfold Zpower_nat at 4; simpl; auto with zarith.
fold FtoRradix; rewrite <- H8.
unfold phi,u, FtoRradix, FtoR; simpl.
rewrite H3; rewrite I'; unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
replace radixH with 1%Z; auto with zarith.
apply Rle_trans with 
  (powerRZ radix (- prec)*powerRZ radix (pred prec) * powerRZ radix (- dExp b + prec - 1)
   + radix*(powerRZ radix (- prec)*powerRZ radix (- prec)
    *powerRZ radix (pred prec) * powerRZ radix (- dExp b + prec - 1)))%R;[simpl; right; ring|idtac].
repeat rewrite <- powerRZ_add; auto with real zarith.
apply Rplus_le_compat.
apply Rle_trans with (powerRZ radix (-1+((- dExp b + prec - 1)))).
apply Rle_powerRZ; auto with real zarith.
rewrite inj_pred; auto with zarith; unfold Zpred; auto with zarith.
rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; right; field.
pattern (IZR radix) at 1; replace (IZR radix) with (powerRZ radix 1); auto with real zarith.
rewrite <- powerRZ_add; auto with real zarith.
apply Rle_powerRZ; auto with real zarith.
rewrite inj_pred; auto with zarith; unfold Zpred; auto with zarith.
(* the one problematic float *)
assert (FtoRradix c=powerRZ radix (6-dExp b))%R.
unfold FtoRradix, FtoR; rewrite H3; rewrite I'.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ; rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + (- dExp b + prec - 1))%Z with (6 - dExp b)%Z; auto.
replace prec with 4%nat; auto with zarith.
simpl (pred 4); simpl (Z_of_nat 4); simpl (Z_of_nat 3); auto with zarith.
assert (FtoRradix (Float 4 (-dExp b)) = 4*powerRZ radix (-dExp b))%R.
unfold FtoRradix, FtoR; simpl; ring.
assert (EvenClosest b radix prec (phi * c) c' ->  FtoRradix c'=Float 4 (-dExp b))%R.
intros; generalize EvenClosestUniqueP; unfold UniqueP; intros T.
unfold FtoRradix; apply T with b prec (phi*c)%R; auto with zarith; clear T.
assert (Fcanonic radix b (Float 4 (- dExp b))).
right; repeat split; simpl; auto with zarith.
rewrite pGivesBound; replace 4%Z with (Zpower_nat radix 2); auto with zarith.
unfold Zpower_nat; rewrite H; simpl; auto with zarith.
rewrite pGivesBound; rewrite H.
rewrite Zabs_eq; auto with zarith.
replace (2*4)%Z with (Zpower_nat 2 3); auto with zarith.
assert (phi * c - FtoR radix (Float 4 (- dExp b)) = powerRZ radix (-1-dExp b))%R.
rewrite H8; unfold phi,u.
replace radixH with 1%Z; auto with zarith.
fold FtoRradix; rewrite H9.
rewrite Rmult_plus_distr_l; rewrite Rmult_plus_distr_r.
replace (powerRZ radix (- prec) * 1%Z)%R with (powerRZ radix (- prec));
  [idtac|simpl; ring].
pattern (IZR radix) at 4; replace (IZR radix) with (powerRZ radix 1); auto with real.
repeat rewrite <- powerRZ_add; auto with real zarith.
replace (- prec + (6 - dExp b))%Z with (2-dExp b)%Z; auto with zarith.
replace (- prec + (1 + - prec) + (6 - dExp b))%Z with (-1-dExp b)%Z; auto with zarith.
replace (powerRZ radix (2 - dExp b)) with (4 * powerRZ radix (- dExp b))%R;[ring|idtac].
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; ring.
split.
apply ClosestSuccPred with prec; auto with zarith.
apply FcanonicBound with radix; auto with zarith.
rewrite H12.
rewrite Rabs_right; [idtac|apply Rle_ge; auto with real zarith].
rewrite succNormal; auto with zarith.
replace ((phi * c -
    (Float 4 (- dExp b) + powerRZ radix (Fexp (Float 4 (- dExp b))))))%R with
   ((phi * c - FtoR radix (Float 4 (- dExp b))) - 
   powerRZ radix (Fexp (Float 4 (- dExp b))))%R;[rewrite H12|unfold FtoRradix; ring].
simpl (Fexp (Float 4 (- dExp b))).
replace (powerRZ radix (-1 - dExp b) - powerRZ radix (- dExp b))%R with
    (-powerRZ radix (-1 - dExp b))%R.
rewrite Rabs_Ropp; rewrite Rabs_right; [idtac|apply Rle_ge]; auto with real zarith.
unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
rewrite H9; repeat apply Rmult_le_pos; auto with real zarith.
rewrite H12.
rewrite Rabs_right; [idtac|apply Rle_ge; auto with real zarith].
rewrite predSmallOnes; auto.
replace ((phi * c - (Float 4 (- dExp b) -eta )))%R with
   ((phi * c - FtoR radix (Float 4 (- dExp b))) + eta)%R;[rewrite H12|unfold FtoRradix; ring].
unfold eta; rewrite Rabs_right.
apply Rle_trans with (powerRZ radix (-1 - dExp b)+0)%R; auto with real zarith.
apply Rle_ge; apply Rle_trans with (0+0)%R; try apply Rplus_le_compat; auto with real zarith.
replace (FtoRradix (Float 4 (- dExp b))) with (powerRZ radix (2-dExp b)).
rewrite Rabs_right; try apply Rle_ge; auto with real zarith.
rewrite H9; unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; ring.
left; unfold FNeven.
rewrite FcanonicFnormalizeEq; auto with zarith.
unfold Feven; simpl; unfold Even.
exists 2%Z; auto with zarith.
assert (FtoRradix c' = Float 4 (- dExp b) -> (FPred b radix prec c <= cinf)%R).
intros.
assert (FtoRradix(Float 5 (- dExp b)) = (5 * powerRZ radix (- dExp b)))%R.
unfold FtoRradix, FtoR; simpl; ring.
assert (FtoRradix e=Float 5 (- dExp b)).
apply sym_eq; apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite pGivesBound; apply Zlt_le_trans with (Zpower_nat radix 3); auto with zarith.
rewrite H; unfold Zpower_nat; simpl; auto with zarith.
replace (FtoR radix (Float 5 (- dExp b))) with (c'+eta)%R; auto.
fold FtoRradix; rewrite H12; rewrite H11; rewrite H9; unfold eta; ring.
assert (FPred b radix prec c= Float (pPred (vNum b)) (- dExp b +2)).
rewrite FPredSimpl2; auto with zarith.
replace ((Zpred (Fexp c))) with (-dExp b+2)%Z; auto.
rewrite I'; unfold Zpred; rewrite <- precBis; ring.
assert (c - e - FtoR radix (FPred b radix prec c)=
     -powerRZ radix (- dExp b))%R.
rewrite predNormal1; auto with zarith.
rewrite H13; rewrite H12; rewrite I'.
replace  (powerRZ radix (- dExp b + prec - 1 - 1)) with
   (4* powerRZ radix (- dExp b))%R;[ring|idtac].
replace (-dExp b +prec-1-1)%Z with (-dExp b+2)%Z; auto with zarith.
rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; ring.
rewrite H8; auto with real zarith.
right; apply sym_eq; apply ClosestStrictEq with b prec (c-e)%R; auto with zarith.
apply FPredCanonic; auto with zarith.
rewrite H15; rewrite Rabs_Ropp.
rewrite Rabs_right; [idtac|apply Rle_ge; auto with real zarith].
rewrite FSucPred; auto with zarith.
fold FtoRradix; replace (c-e-c)%R with (-e)%R by ring.
rewrite H13; rewrite H12; rewrite Rabs_Ropp.
rewrite Rabs_right; [idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
apply Rle_lt_trans with (1*powerRZ radix (- dExp b))%R; auto with real.
apply Rmult_lt_compat_r; auto with real zarith.
replace 5%R with (IZR 5); auto with real zarith; simpl; ring.
replace 5%R with (IZR 5); auto with real zarith; simpl; ring.
rewrite H15; rewrite Rabs_Ropp.
rewrite Rabs_right; [idtac|apply Rle_ge; auto with real zarith].
rewrite H14; rewrite FPredSimpl4; auto with zarith; simpl.
replace (FtoR radix (Float (Zpred (pPred (vNum b))) (- dExp b + 2))) with
    (c-8*powerRZ radix (- dExp b))%R.
2: unfold pPred, Zpred; rewrite pGivesBound.
2: unfold FtoR; simpl.
2: repeat rewrite plus_IZR; simpl; rewrite Zpower_nat_Z_powerRZ.
2: repeat rewrite Rmult_plus_distr_r with (r3:=powerRZ radix (- dExp b + 2)).
2: rewrite <- powerRZ_add; auto with real zarith; rewrite H8.
2: replace (prec + (- dExp b + 2))%Z with (6 - dExp b)%Z; auto with zarith.
2: repeat rewrite powerRZ_add with (m:=2); auto with real zarith.
2: rewrite H; simpl; ring.
replace  (c - e - (c - 8 * powerRZ radix (- dExp b)))%R with ((3*powerRZ radix (- dExp b)))%R.
rewrite Rabs_right; try apply Rle_ge; auto with real zarith.
apply Rle_lt_trans with (1*powerRZ radix (- dExp b))%R; auto with real.
apply Rmult_lt_compat_r; auto with real zarith.
replace 3%R with (IZR 3); auto with real zarith; simpl; ring.
apply Rmult_le_pos; auto with real zarith.
replace 3%R with (IZR 3); auto with real zarith; simpl; ring.
rewrite H13; rewrite H12; ring.
assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
assert (nNormMin radix prec < pPred (vNum b))%Z; auto with zarith.
apply nNormMimLtvNum; auto with zarith.
case MM; auto with zarith.
intros.
assert (phi*c=9/2*powerRZ radix (-dExp b))%R.
rewrite H8; unfold phi,u; rewrite <- precBis.
replace (radixH) with 1%Z; auto with zarith.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; field.
assert (FtoRradix (Float 5 (- dExp b)) = 5 * powerRZ radix (- dExp b))%R.
unfold FtoRradix, FtoR; simpl; ring.
assert (Fcanonic radix b (Float 4 (- dExp b))).
right; split; split; simpl; auto with zarith.
rewrite pGivesBound; rewrite H.
replace prec with 4%nat; auto with zarith.
rewrite pGivesBound; rewrite H.
replace prec with 4%nat; auto with zarith.
assert (Fcanonic radix b (Float 5 (- dExp b))).
right; split; split; simpl; auto with zarith.
rewrite pGivesBound; rewrite H.
replace prec with 4%nat; auto with zarith.
rewrite pGivesBound; rewrite H.
replace prec with 4%nat; auto with zarith.
assert (FtoRradix c'= Float 4 (- dExp b) \/ FtoRradix c'= Float 5 (- dExp b))%R.
generalize ClosestMinOrMax; unfold MinOrMaxP; intros T.
case (T b radix (phi*c)%R c'); auto; clear T.
intros; left.
apply (MinUniqueP b radix (phi*c)%R); auto.
split; auto.
apply FcanonicBound with radix; auto.
split.
fold FtoRradix; rewrite H9; rewrite H13.
apply Rmult_le_compat_r; auto with real zarith.
apply Rmult_le_reg_l with 2%R; auto with real.
apply Rle_trans with 9%R;[auto with real|right; field].
apply Rle_trans with (8+1)%R; auto with real.
intros.
apply Rle_trans with (FtoR radix (FPred b radix prec (Float 5 (- dExp b)))).
rewrite <- FnormalizeCorrect with radix b prec f; auto.
apply FPredProp; auto with zarith.
apply FnormalizeCanonic; auto with zarith.
rewrite FnormalizeCorrect; auto with zarith.
apply Rle_lt_trans with (1:=H19).
fold FtoRradix; rewrite H14; rewrite H13.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rmult_lt_reg_l with 2%R; auto with real.
apply Rle_lt_trans with 9%R;[right; field|idtac].
apply Rlt_le_trans with (9+1)%R; auto with real.
right; ring.
rewrite predSmallOnes; auto with zarith.
fold FtoRradix; rewrite H14; rewrite H9.
unfold eta; right; ring.
rewrite H14; rewrite Rabs_right.
unfold Zminus; rewrite powerRZ_add; auto with real zarith.
apply Rmult_lt_compat_r; auto with real zarith.
rewrite H; rewrite <- precBis; simpl.
apply Rlt_le_trans with (IZR 16); auto with real zarith.
apply Rle_lt_trans with (IZR 5); auto with real zarith.
right; simpl; ring.
right; simpl; ring.
apply Rle_ge; apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 5); auto with real zarith; right; simpl; ring.
intros; right.
apply (MaxUniqueP b radix (phi*c)%R); auto.
split; auto.
apply FcanonicBound with radix; auto.
split.
fold FtoRradix; rewrite H14; rewrite H13.
apply Rmult_le_compat_r; auto with real zarith.
apply Rmult_le_reg_l with 2%R; auto with real.
apply Rle_trans with 9%R;[right; field|idtac].
apply Rle_trans with (9+1)%R; auto with real.
right; ring.
intros.
apply Rle_trans with (FtoR radix (FSucc b radix prec (Float 4 (- dExp b)))).
rewrite succNormal; auto with zarith.
fold FtoRradix; rewrite H9; rewrite H14; simpl; right; ring.
rewrite H9; repeat apply Rmult_le_pos; auto with real zarith.
rewrite <- FnormalizeCorrect with radix b prec f; auto.
apply FSuccProp; auto with zarith.
apply FnormalizeCanonic; auto with zarith.
rewrite FnormalizeCorrect; auto with zarith.
apply Rlt_le_trans with (2:=H19).
fold FtoRradix; rewrite H9; rewrite H13.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rmult_lt_reg_l with 2%R; auto with real.
apply Rlt_le_trans with 9%R;[idtac|right; field].
apply Rlt_le_trans with (8+1)%R; auto with real.
case H17; auto.
intros.
assert (FtoRradix e=Float 6 (- dExp b)).
apply sym_eq; apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith.
rewrite pGivesBound; apply Zlt_le_trans with (Zpower_nat radix 3); auto with zarith.
rewrite H; unfold Zpower_nat; simpl; auto with zarith.
replace (FtoR radix (Float 6 (- dExp b))) with (c'+eta)%R; auto.
rewrite H18; unfold FtoRradix, FtoR; unfold eta; simpl; ring.
assert (FPred b radix prec c= Float (pPred (vNum b)) (- dExp b +2)).
rewrite FPredSimpl2; auto with zarith.
replace ((Zpred (Fexp c))) with (-dExp b+2)%Z; auto.
rewrite I'; unfold Zpred; rewrite <- precBis; ring.
assert (FtoRradix (Float 6 (- dExp b)) = (6 * powerRZ radix (- dExp b))%R).
unfold FtoRradix, FtoR; simpl; ring.
assert (c - e - FtoR radix (FPred b radix prec c)=
     -(2* powerRZ radix (- dExp b)))%R.
rewrite predNormal1; auto with zarith.
rewrite H19; rewrite H21; rewrite I'.
replace  (powerRZ radix (- dExp b + prec - 1 - 1)) with
   (4* powerRZ radix (- dExp b))%R;[ring|idtac].
replace (-dExp b +prec-1-1)%Z with (-dExp b+2)%Z; auto with zarith.
rewrite powerRZ_add; auto with real zarith.
rewrite H; simpl; ring.
rewrite H8; auto with real zarith.
generalize AFZClosestUniqueP; unfold UniqueP; intros T.
right; unfold FtoRradix; apply T with b prec (c-e)%R; auto with zarith.
clear T; split.
apply ClosestSuccPred with prec; auto with zarith.
apply FBoundedPred; auto with zarith.
apply FcanonicBound with radix; auto.
apply FPredCanonic; auto with zarith.
rewrite H22; rewrite Rabs_Ropp.
rewrite Rabs_right; [idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
rewrite FSucPred; auto with zarith.
fold FtoRradix; replace (c-e-c)%R with (-e)%R by ring.
rewrite H19; rewrite H21; rewrite Rabs_Ropp.
rewrite Rabs_right; [idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
apply Rmult_le_compat_r; auto with real zarith.
replace 6%R with (IZR 6); auto with real zarith.
replace 2%R with (IZR 2); auto with real zarith.
simpl; ring.
replace 6%R with (IZR 6); auto with real zarith; simpl; ring.
rewrite H22; rewrite Rabs_Ropp.
rewrite Rabs_right; [idtac|apply Rle_ge; apply Rmult_le_pos; auto with real zarith].
rewrite H20; rewrite FPredSimpl4; auto with zarith; simpl.
replace (FtoR radix (Float (Zpred (pPred (vNum b))) (- dExp b + 2))) with
    (c-8*powerRZ radix (- dExp b))%R.
2: unfold pPred, Zpred; rewrite pGivesBound.
2: unfold FtoR; simpl.
2: repeat rewrite plus_IZR; simpl; rewrite Zpower_nat_Z_powerRZ.
2: repeat rewrite Rmult_plus_distr_r with (r3:=powerRZ radix (- dExp b + 2)).
2: rewrite <- powerRZ_add; auto with real zarith; rewrite H8.
2: replace (prec + (- dExp b + 2))%Z with (6 - dExp b)%Z; auto with zarith.
2: repeat rewrite powerRZ_add with (m:=2); auto with real zarith.
2: rewrite H; simpl; ring.
replace  (c - e - (c - 8 * powerRZ radix (- dExp b)))%R with ((2*powerRZ radix (- dExp b)))%R.
rewrite Rabs_right; auto with real; try apply Rle_ge; apply Rmult_le_pos; auto with real zarith.
rewrite H19; rewrite H21; ring.
assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
assert (nNormMin radix prec < pPred (vNum b))%Z; auto with zarith.
apply nNormMimLtvNum; auto with zarith.
left; repeat rewrite Rabs_right; try apply Rle_ge.
apply Rminus_le; rewrite H22.
apply Rle_trans with (-0)%R; auto with real; apply Ropp_le_contravar.
apply Rmult_le_pos;auto with real zarith.
rewrite H20; apply LeFnumZERO; simpl; auto with zarith.
assert (0 < pPred (vNum b))%Z; auto with zarith.
apply pPredMoreThanOne with radix prec; auto with zarith.
apply Rplus_le_reg_l with e; ring_simplify.
rewrite H19; rewrite H21; rewrite H8; unfold Zminus.
rewrite powerRZ_add; auto with real zarith.
apply Rmult_le_compat_r; auto with real zarith.
apply Rle_trans with (powerRZ radix 3); auto with real zarith.
rewrite H; simpl; apply Rle_trans with (IZR 6).
right; simpl; ring.
apply Rle_trans with (IZR 8); auto with real zarith.
right; simpl; ring.
Qed.



Lemma Algo1_correct_r2_aux_aux4:forall (c csup:float) (r:R),
   Fcanonic radix b c -> (0 <= c)%R -> 
   (r <= 5/4*powerRZ radix (Fexp c))%R ->
   Closest b radix (c+r) csup ->
   (FtoRradix csup <= FSucc b radix prec c)%R.
intros c csup r; intros.
assert (N:Fbounded b c).
apply FcanonicBound with radix; auto.
assert (G1:(0 < 4)%R).
apply Rlt_le_trans with (IZR 4); auto with real zarith; simpl; right; ring.
assert (G2:(0 < 5)%R).
apply Rlt_le_trans with (IZR 5); auto with real zarith; simpl; right; ring.
assert (c + 5 / 4 * powerRZ radix (Fexp c) - FtoR radix (FSucc b radix prec c)
   = (/4*powerRZ radix (Fexp c)))%R.
rewrite succNormal; auto with zarith; field.
apply ClosestStrictMonotone2r with b prec (c+r)%R (c+5/4*powerRZ radix (Fexp c))%R; auto with zarith.
apply FSuccCanonic; auto with zarith.
rewrite H3.
rewrite Rabs_right.
2: apply Rle_ge; unfold Rdiv; apply Rmult_le_pos; auto with real zarith.
rewrite succNormal; auto with zarith.
rewrite succNormal; auto with zarith.
replace (c + 5/4*powerRZ radix (Fexp c) -
    (c + powerRZ radix (Fexp c) + 
   powerRZ radix (Fexp (FSucc b radix prec c))))%R with
   ((/4*powerRZ radix (Fexp c)-powerRZ radix 
      (Fexp (FSucc b radix prec c))))%R.
2: field.
assert (Fexp (FSucc b radix prec c) = Fexp c \/ 
              (Fexp (FSucc b radix prec c) = Fexp c+1)%Z).
unfold FSucc.
case (Z_eq_bool (Fnum c) (pPred (vNum b))).
right; simpl; unfold Zsucc; auto.
generalize (Z_eq_bool_correct (Fnum c) (- nNormMin radix prec));
 case (Z_eq_bool (Fnum c) (- nNormMin radix prec)).
intros; absurd (0 <= Fnum c)%Z.
apply Zlt_not_le; apply Zlt_le_trans with (-0)%Z; auto with zarith.
rewrite H4; unfold nNormMin; auto with zarith.
apply LeR0Fnum with radix ; auto with real zarith.
intros; left; simpl; auto.
case H4; intros M; rewrite M.
replace (/ 4 * powerRZ radix (Fexp c) - powerRZ radix (Fexp c))%R with
   (-(3/4*powerRZ radix (Fexp c) ))%R by field.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (1*/4)%R; unfold Rdiv; auto with real.
apply Rmult_lt_compat_r; auto with real.
apply Rlt_le_trans with (IZR 3); auto with real zarith; simpl; right; ring.
apply Rle_ge; unfold Rdiv; repeat apply Rmult_le_pos; auto with real zarith.
apply Rle_trans with (IZR 3); auto with real zarith; simpl; right; ring.
replace (/ 4 * powerRZ radix (Fexp c) - powerRZ radix (Fexp c+1))%R with
   (-((radix-/4)*powerRZ radix (Fexp c) ))%R.
2: rewrite powerRZ_add; auto with real zarith; simpl; field.
rewrite Rabs_Ropp; rewrite Rabs_right.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (1*/4)%R; unfold Rdiv; auto with real.
apply Rlt_le_trans with ((4*radix-1)*/4)%R;[idtac|right; field].
apply Rmult_lt_compat_r; auto with real.
apply Rplus_lt_reg_r with 1%R; ring_simplify.
apply Rlt_le_trans with (4*1)%R; auto with real zarith.
apply Rlt_le_trans with (4)%R; auto with real zarith.
apply Rle_lt_trans with (2*1)%R; auto with real zarith.
apply Rle_ge; apply Rmult_le_pos; auto with real zarith.
apply Rplus_le_reg_l with (/4)%R; ring_simplify.
apply Rle_trans with 1%R; auto with real zarith.
apply Rle_trans with (/1)%R; auto with real.
apply Rle_Rinv; auto with real.
apply Rle_trans with (IZR 4); auto with real zarith; simpl; right; ring.
apply FSuccCanonic; auto with zarith.
apply Rle_trans with (1:=H0).
left; unfold FtoRradix; apply FSuccLt; auto with zarith.
rewrite H3.
rewrite FPredSuc; fold FtoRradix; auto with zarith.
replace (c + 5/4*powerRZ radix (Fexp c)  - c)%R with (5/4*(powerRZ radix (Fexp c)))%R;[idtac|ring].
rewrite (Rabs_right (5/4*(powerRZ radix (Fexp c) ))).
2: apply Rle_ge; unfold Rdiv;repeat apply Rmult_le_pos; auto with real zarith.
rewrite Rabs_right.
2: apply Rle_ge;  apply Rmult_le_pos; auto with real zarith.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (1*/4)%R; auto with real.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rlt_le_trans with (IZR 5); auto with real zarith; simpl; right; ring.
apply Rplus_le_compat_l; auto.
Qed.



Lemma Algo1_correct_r2_aux1: forall (c c' e cinf csup:float),
  (radix=2)%Z ->
  Fcanonic radix b c -> 
  (0 <= c)%R ->
  (powerRZ radix (prec+1-dExp b) < c)%R ->
  Closest b radix (phi*c) c' ->
  Closest b radix (c'+eta) e ->
  Closest b radix (c-e) cinf ->
  Closest b radix (c+e) csup ->
  (prec=4 -> EvenClosest b radix prec (phi*c)%R c' 
     \/ AFZClosest b radix (c-e) cinf) ->
  (FtoRradix (FPred b radix prec c) <= cinf)%R
   /\  (FtoRradix csup <= FSucc b radix prec c)%R.  
intros c c' e cinf csup K Cc Cpos CGe Hc' He Hcinf Hcsup MM.
assert (- dExp b +2 <= Fexp c )%Z.
apply Zle_trans with (Fexp (Float (nNormMin radix prec) (-dExp b+2))); auto with zarith.
apply Fcanonic_Rle_Zle with radix b prec; auto with zarith.
left; split; try split; simpl; auto with zarith.
unfold nNormMin; rewrite pGivesBound; rewrite Zabs_eq; auto with zarith.
rewrite <- (PosNormMin radix b prec); auto with zarith.
fold (FtoRradix c).
replace  (FtoR radix (Float (nNormMin radix prec) (- dExp b + 2))) with
  (powerRZ radix (prec + 1 - dExp b)).
repeat rewrite Rabs_right; try apply Rle_ge; auto with real zarith.
unfold FtoR; simpl.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + (- dExp b + 2))%Z with (prec+1-dExp b)%Z; auto.
rewrite inj_pred; unfold Zpred; auto with zarith.
assert (e <= 5/4*powerRZ radix (Fexp c))%R.
apply Rle_trans with 
  (powerRZ radix (Fexp c) * (radix / 2 + powerRZ radix (-2)))%R.
apply eLe with c'; auto with zarith.
rewrite K; simpl; right; field.
split.
2: apply Algo1_correct_r2_aux_aux4 with e; auto.
case (Z_eq_dec (Fnum c) (nNormMin radix prec)); intros L1.
apply Algo1_correct_r2_aux_aux3 with c' e; auto.
case (Zle_lt_or_eq (- dExp b + 2) (Fexp c)); auto with zarith.
intros M.
Contradict CGe.
replace (FtoRradix c) with (powerRZ radix (prec + 1 - dExp b)); auto with real.
unfold FtoRradix, FtoR; simpl; rewrite <- M; rewrite L1.
unfold nNormMin; rewrite Zpower_nat_Z_powerRZ.
rewrite <- powerRZ_add; auto with real zarith.
replace (pred prec + (- dExp b + 2))%Z with (prec+1-dExp b)%Z; auto.
rewrite inj_pred; unfold Zpred; auto with zarith.
case (Z_eq_dec (Fnum c) (nNormMin radix prec+1)); intros L2.
apply Algo1_correct_r2_aux_aux2 with c' e; auto with zarith.
apply Algo1_correct_r2_aux_aux1 with e; auto with zarith.
Qed.



Lemma Algo1_correct_r2_aux2: forall (c c' e cinf csup:float),
  (radix=2)%Z ->
  Fcanonic radix b c -> 
  (0 <= c)%R ->
  (c < powerRZ radix (prec-dExp b-1))%R ->
  Closest b radix (phi*c) c' ->
  Closest b radix (c'+eta) e ->
  Closest b radix (c-e) cinf ->
  Closest b radix (c+e) csup ->
  (FtoRradix (FPred b radix prec c) <= cinf)%R
   /\  (FtoRradix csup <= FSucc b radix prec c)%R.  
intros.
cut (FtoRradix e = eta)%R; [intros P|idtac].
split.
right; unfold FtoRradix.
apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
apply FBoundedPred;  auto with zarith.
apply FcanonicBound with radix; auto.
replace (FtoR radix (FPred b radix prec c))%R with (c-e)%R; auto.
fold FtoRradix; rewrite predSmallOnes; auto.
rewrite P; auto.
rewrite Rabs_right; try apply Rle_ge; auto with real zarith.
apply Rlt_le_trans with (1:=H2); auto with real zarith.
right; unfold FtoRradix; apply sym_eq.
apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
apply FBoundedSuc;  auto with zarith.
apply FcanonicBound with radix; auto.
replace (FtoR radix (FSucc b radix prec c))%R with (c+e)%R; auto.
fold FtoRradix; rewrite succNormal; auto.
rewrite P; unfold eta; replace (Fexp c) with (-dExp b)%Z; auto.
case H0; auto; intros J.
absurd (FtoRradix (firstNormalPos radix b prec) <= c)%R.
apply Rlt_not_le; unfold FtoRradix; rewrite firstNormalPos_eq; auto with zarith.
fold FtoRradix; apply Rlt_le_trans with (1:=H2).
apply Rle_powerRZ; unfold Zpred; auto with real zarith.
apply FnormalLtFirstNormalPos; auto with zarith.
elim J; intuition.
apply sym_eq; apply trans_eq with (Float 1 (-(dExp b))).
unfold eta, FtoRradix, FtoR; simpl; ring.
apply RoundedModeProjectorIdemEq with b prec (Closest b radix); auto with zarith.
apply ClosestRoundedModeP with prec; auto with zarith.
split; simpl; auto with zarith float.
apply vNumbMoreThanOne with radix prec; auto with zarith.
replace (FtoR radix (Float 1 (- dExp b))) with (c'+eta)%R; auto.
replace (FtoRradix c') with 0%R.
unfold eta, FtoRradix, FtoR; simpl; ring.
apply sym_eq; apply RoundedToZero with (phi*c)%R; auto.
rewrite Rabs_mult.
repeat rewrite Rabs_right; try apply Rle_ge; auto with real.
assert (exists f:float, Fbounded b f /\ (f=Float 1 (prec - dExp b-1)) /\
   (FtoRradix f= powerRZ radix (prec - dExp b-1))%R).
exists (Float 1 (prec-dExp b-1)).
split; try split; simpl; auto with zarith.
apply vNumbMoreThanOne with radix prec; auto with zarith.
unfold FtoRradix, FtoR; simpl; ring.
elim H7; intros f (Bf,(L2,L3)).
apply Rle_lt_trans with (phi*(FPred b radix prec (Fnormalize radix b prec f)))%R.
apply Rmult_le_compat_l; auto with real.
left; apply phi_Pos.
apply FPredProp; auto with zarith real.
apply FnormalizeCanonic; auto with zarith.
rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite L3; auto.
rewrite predSmallOnes.
unfold FtoRradix; rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite L3; unfold eta, phi.
unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
replace radixH with 1%Z; auto with zarith.
apply Rle_lt_trans with ( (u * (1 + radix * u) *
 (powerRZ radix prec * powerRZ radix (- (1)) -1 )) * powerRZ radix (-(dExp b)))%R.
simpl; right; ring.
apply Rmult_lt_compat_r; auto with real zarith.
apply Rle_lt_trans with (/radix - powerRZ radix (1-prec-prec))%R.
replace (powerRZ radix prec) with (/powerRZ radix (-prec))%R.
unfold u; right; unfold Zminus; repeat rewrite powerRZ_add; auto with real zarith.
simpl; field; auto with real zarith.
rewrite <- Rinv_powerRZ; auto with real zarith.
apply Rlt_le_trans with (/radix-0)%R; auto with real zarith.
unfold Rminus; apply Rplus_lt_compat_l; auto with real zarith.
apply Rle_trans with (/radix)%R; auto with real zarith.
apply Rle_Rinv; auto with real zarith.
apply Rle_trans with (IZR 2); auto with real zarith.
apply FnormalizeCanonic; auto with zarith.
unfold FtoRradix; rewrite FnormalizeCorrect; auto with zarith.
fold FtoRradix; rewrite L3.
rewrite Rabs_right; try apply Rle_ge; auto with real zarith.
left; apply phi_Pos.
Qed.






Lemma Algo1_correct_r2_aux3: forall (c c' e cinf csup:float),
  (radix=2)%Z ->
  Fcanonic radix b c -> 
   (Rabs c < powerRZ radix (prec-dExp b-1))%R 
        \/   (powerRZ radix (prec+1-dExp b) < Rabs c)%R ->
  Closest b radix (phi*(Rabs c)) c' ->
  Closest b radix (c'+eta) e ->
  Closest b radix (c-e) cinf ->
  Closest b radix (c+e) csup ->
  (prec=4 -> EvenClosest b radix prec (phi*Rabs c)%R c'
          \/ (AFZClosest b radix (c-e) cinf 
                     /\ AFZClosest b radix (c+e) csup)) ->
  (FtoRradix (FPred b radix prec c) <= cinf)%R
   /\  (FtoRradix csup <= FSucc b radix prec c)%R.  
intros c c' e cinf csup K Cc CInt Hc' He Hcinf Hcsup MM.
case (Rle_or_lt 0 c); intros.
case CInt; intros.
apply Algo1_correct_r2_aux2 with c' e; auto.
rewrite <- (Rabs_right c); auto.
apply Rle_ge; auto.
rewrite <- (Rabs_right c); auto.
apply Rle_ge; auto.
apply Algo1_correct_r2_aux1 with c' e; auto.
rewrite <- (Rabs_right c); auto.
apply Rle_ge; auto.
rewrite <- (Rabs_right c); auto.
apply Rle_ge; auto.
intros; case MM; auto; intros.
left; rewrite <- (Rabs_right c); auto.
apply Rle_ge; auto.
elim H2; auto.
assert ((FPred b radix prec (Fopp c) <= Fopp csup)%R 
   /\ (Fopp cinf <= FSucc b radix prec (Fopp c) )%R).
case CInt; intros.
apply Algo1_correct_r2_aux2 with c' e; auto.
apply FcanonicFopp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
replace (FtoRradix (Fopp c)) with (Rabs c); auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
rewrite Rabs_left; auto with real.
replace (FtoRradix (Fopp c)) with (Rabs c); auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
rewrite Rabs_left; auto with real.
replace (Fopp c -e)%R with (-(c+e))%R.
apply ClosestOpp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
replace (Fopp c +e)%R with (-(c-e))%R.
apply ClosestOpp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
apply Algo1_correct_r2_aux1 with c' e; auto.
apply FcanonicFopp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
replace (FtoRradix (Fopp c)) with (Rabs c); auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
rewrite Rabs_left; auto with real.
replace (FtoRradix (Fopp c)) with (Rabs c); auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
rewrite Rabs_left; auto with real.
replace (Fopp c -e)%R with (-(c+e))%R.
apply ClosestOpp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
replace (Fopp c +e)%R with (-(c-e))%R.
apply ClosestOpp; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
intros; case MM; auto; intros.
left; replace (FtoRradix (Fopp c)) with (Rabs c); auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
rewrite Rabs_left; auto with real.
elim H2; intros.
right; replace (Fopp c -e)%R with (-(c+e))%R.
apply AFZClosestSymmetric; auto.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith; ring.
elim H0; intros L1 L2; clear H0; split; apply Ropp_le_cancel.
rewrite FPredFopFSucc; auto with zarith.
apply Rle_trans with (FSucc b radix prec (Fopp c)).
apply Rle_trans with (2:=L2).
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
apply Rle_trans with (Fopp csup).
2: unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
apply Rle_trans with (2:=L1).
rewrite FPredFopFSucc; auto with zarith.
rewrite Fopp_Fopp.
unfold FtoRradix; rewrite Fopp_correct; auto with real zarith.
Qed.




Lemma PredSucc_Algo1_correct_r2: forall (c c' e cinf csup:float),
  (radix=2)%Z ->
  Fcanonic radix b c -> 
   (Rabs c < powerRZ radix (prec-dExp b-1))%R 
        \/   (powerRZ radix (prec+1-dExp b) < Rabs c)%R ->
  Closest b radix (phi*(Rabs c)) c' ->
  Closest b radix (c'+eta) e ->
  Closest b radix (c-e) cinf ->
  Closest b radix (c+e) csup ->
  (prec=4 -> EvenClosest b radix prec (phi*Rabs c)%R c'
     \/ (AFZClosest b radix (c-e) cinf 
                     /\ AFZClosest b radix (c+e) csup)) ->
  (FtoRradix (FPred b radix prec c) = cinf)%R
   /\  (FtoRradix csup = FSucc b radix prec c)%R.  
intros.
assert ((FtoRradix (FPred b radix prec c) <= cinf)%R
   /\  (FtoRradix csup <= FSucc b radix prec c)%R). 
apply Algo1_correct_r2_aux3 with c' e; auto.
assert ((FtoRradix cinf<= (FPred b radix prec c))%R
   /\  (FtoRradix (FSucc b radix prec c) <= csup)%R). 
apply PredSucc_Algo1_correct with c' e; auto.
elim H7; elim H8; intros; split; auto with real.
Qed.

End PredComput.