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
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
|
% -*- coding: utf-8; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" -*-
% This file: xint.dtx. Proudly produced by xint-dtxbuild.sh.
% Extract all files via "etex xint.dtx" and do "make help"
% or follow instructions from extracted README.md.
%<*dtx>
\def\xintdtxtimestamp {Time-stamp: <20-11-2016 at 22:43:58 CET>}
%</dtx>
%<*drv>
%% ---------------------------------------------------------------
\def\xintdocdate {2016/11/20}
\def\xintbndldate{2016/11/20}
\def\xintbndlversion {1.2h}
%</drv>
%<readme>% README
%<changes>% CHANGE LOG
%<readme|changes>% xint 1.2h
%<readme|changes>% 2016/11/20
%<readme|changes>
%<readme|changes> Source: xint.dtx 1.2h 2016/11/20 (doc 2016/11/20)
%<readme|changes> Author: Jean-Francois Burnol
%<readme|changes> Info: Expandable operations on big integers, decimals, fractions
%<readme|changes> License: LPPL 1.3c
%<readme|changes>
%<*!readme&!changes&!dohtmlsh&!dopdfsh&!makefile>
%% ---------------------------------------------------------------
%% The xint bundle 1.2h 2016/11/20
%% Copyright (C) 2013-2016 by Jean-Francois Burnol
%<xintkernel>%% xintkernel: Paraphernalia for the xint packages
%<xinttools>%% xinttools: Expandable and non-expandable utilities
%<xintcore>%% xintcore: Expandable arithmetic on big integers
%<xint>%% xint: Expandable operations on big integers
%<xintfrac>%% xintfrac: Expandable operations on fractions
%<xintexpr>%% xintexpr: Expandable expression parser
%<xintbinhex>%% xintbinhex: Expandable binary and hexadecimal conversions
%<xintgcd>%% xintgcd: Euclidean algorithm with xint package
%<xintseries>%% xintseries: Expandable partial sums with xint package
%<xintcfrac>%% xintcfrac: Expandable continued fractions with xint package
%% ---------------------------------------------------------------
%</!readme&!changes&!dohtmlsh&!dopdfsh&!makefile>
%<*dtx>
\bgroup\catcode2 0 \catcode`\\ 12 ^^Biffalse
%</dtx>
%<*readme>--------------------------------------------------------
This `README` is also available as `README.pdf` and `README.html`.
Change log is to be found in `CHANGES.pdf` or `CHANGES.html`.
The user manual is `xint.pdf`, and the commented source code is
available as `sourcexint.pdf`.
Aim
===
The basic aim is provide *expandable* computations on integers,
fractions, and floating point numbers. For example
\xinttheexpr reduce(37189719/183618963+11390170/17310720)^17\relax
will evaluate exactly the fraction (the result has 462 characters
including the fraction slash). One can also work with dummy
variables:
\xinttheexpr mul(add(x(x+1)(x+2), x=y..y+15), y=171286,98762,9296)\relax
(evaluates to `15979066346135829902328007959448563667099190784`.)
Float computations are possible at an adjustable precision (default 16).
\xintthefloatexpr 123456789^1000.5\relax
Mathematical functions (apart from `sqrt` which achieves correct
rounding in arbitrary precision) are yet to be implemented.
It is possible to use the package with Plain as well as with LaTeX.
Sub-units `xintcore`, `xint` and `xintfrac` provide the underlying
macros, and `xintexpr` loads all of them and provides expandable
parsers allowing computations such as the above (and more). A more
light-weight package [bnumexpr](http://www.ctan.org/pkg/bnumexpr)
(LaTeX only) loads only `xintcore` and provides a parser which
handles only big integers, the four operations, the power operation
and the factorial (1.2).
Usage
=====
## With LaTeX
\usepackage{xint} % expandable arithmetic with big integers
\usepackage{xintfrac} % decimal numbers, fractions, floats
\usepackage{xintexpr} % expressions with infix operators
Further packages: `xintbinhex`, `xintgcd`, `xintseries` and
`xintcfrac`. All dependencies are handled automatically. For example
`xintexpr` automatically loads `xintfrac` which itself loads `xint`.
Package `xintcore` is the subset of `xint` providing only the five
operations on big integers: `\xintiiAdd`, `\xintiiMul`,\ ...
There is also `xinttools` which is a separate package providing,
among others, expandable and non-expandable loops such as `\xintFor`.
## With TeX
One does for example:
\input xintexpr.sty
Again, all dependencies are handled automatically. The packages may
be loaded in any catcode context such that letters, digits, `\` and
`%` have their standard catcodes.
`xintcore.sty` and `xinttools.sty` both import `xintkernel.sty`
which has the catcode handler and package identifier and defines a
few utilities such as `\oodef`, `\fdef`, or `\xint_dothis/\xint_orthat`.
Installation
============
## Method A: using the package manager of your TeX distribution
`xint` is included in [TeXLive](http://tug.org/texlive/) (hence also
[MacTeX](http://tug.org/mactex/)) and [MikTeX](http://www.miktex.org/).
There can be a few days of delay between apparition of a new version on
[CTAN](http://www.ctan.org/pkg/xint) and availability via the distribution
package manager.
## Method B: manual installation using `xint.tds.zip` and `unzip`
Assumes a GNU/Linux-like system (or Mac OS X).
1. obtain `xint.tds.zip` from CTAN:
<http://mirror.ctan.org/install/macros/generic/xint.tds.zip>
2. cd to the download repertory and issue:
unzip xint.tds.zip -d <TEXMF>
where `<TEXMF>` is a suitable TDS-compliant destination repertory.
For example, with TeXLive:
- Linux, standard access rights, hence sudo is needed, installation
into the "local" tree:
sudo unzip xint.tds.zip -d /usr/local/texlive/texmf-local
sudo texhash /usr/local/texlive/texmf-local
- Mac OS X, installation into user home folder (no sudo needed,
and it is recommended to not have a ls-R file there, hence no texhash):
unzip xint.tds.zip -d ~/Library/texmf
## Method C: manual installation using `Makefile` and `xint.dtx`
The Makefile automatizes rebuilding from `xint.dtx` all documentation
files as well as `xint.tds.zip`. It is for GNU/Linux-like (inc. Mac OS X)
systems, with a teTeX like installation such as TeXLive. Furthermore the
[Pandoc](http://johnmacfarlane.net/pandoc/) software is required.
1. obtain `xint.dtx` and `Makefile` from
<http://mirror.ctan.org/macros/generic/xint>.
2. put them in an otherwise empty working repertory, run `make` or
equivalently `make help` for further instructions.
## Method D: installation starting with only `xint.dtx`
Run `"tex xint.dtx"` or `"etex xint.dtx"` to extract from `xint.dtx`
all packages as well as these files:
`README.md`
: the current README with Markdown formatting.
`CHANGES.md`
: the changes across successive releases.
`xint.tex`
: used to generate `xint.pdf` via `"latex xint.tex"` (thrice) then
`"dvipdfmx xint.dvi"`. It is also possible to compile `xint.tex` with
`xelatex`, or with `pdflatex` (this latter option produces a bigger pdf).
: For successful compilation, packages `newtxtt`, `newtxmath`, `etoc`,
`mathastext` are needed. Inclusion of the source code is off by
default, but the toggle can be set in `xint.tex`.
: A third option is to generate `xint.pdf` via `xelatex xint.dtx` or
`pdflatex xint.dtx`. Source code is then included by default (but some
code comments in French use 8bit characters, hence for `xelatex` an a
priori conversion of xint.dtx into utf-8 will give a better result).
`Makefile.mk`
: this is for UNIX-like systems. Note: this file is only produced
with `"etex xint.dtx"`, not with `"tex xint.dtx"`. Rename it to
`Makefile` and run `make` on the command line for further help.
`doHTMLs.sh` and `doPDFs.sh`
: these are scripts (for UNIX-like systems) which can be used to
convert the `README.md` and `CHANGES.md` to HTML and PDF formats.
They require [Pandoc](http://johnmacfarlane.net/pandoc/).
`pandoctpl.latex`
: a Pandoc template used by `doPDFs.sh`.
Finishing the installation in a TDS hierarchy:
- move the style files to `TDS:tex/generic/xint/`
- `xint.dtx` goes to `TDS:source/generic/xint/`
- the documentation (xint.pdf, README.md,...) goes to `TDS:doc/generic/xint/`
Depending on the destination, it may then be necessary to refresh a
filename database.
License
=======
<div class="mono">
Copyright (C) 2013-2016 by Jean-Francois Burnol
This Work may be distributed and/or modified under the
conditions of the LaTeX Project Public License version 1.3c.
This version of this license is in
> <http://www.latex-project.org/lppl/lppl-1-3c.txt>
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
This Work has the LPPL maintenance status `author-maintained`.
The Author of this Work is Jean-Francois Burnol.
This Work consists of the source file xint.dtx and of its derived
files: xintkernel.sty, xintcore.sty, xint.sty, xintfrac.sty,
xintexpr.sty, xintbinhex.sty, xintgcd.sty, xintseries.sty,
xintcfrac.sty, xinttools.sty, xint.ins, xint.tex, README, README.md,
README.html, README.pdf, CHANGES.md, CHANGES.html, CHANGES.pdf,
pandoctpl.latex, doHTMLs.sh, doPDFs.sh, xint.dvi, xint.pdf,
Makefile.mk.</div>
%</readme>--------------------------------------------------------
%<*changes>-------------------------------------------------------
`1.2h (2016/11/20)`
----
### Improvements and new features
- new macro `\xintNewFunction` in **xintexpr** which allows to extend
the parser syntax with functions in situations where `\xintdeffunc`
is not usable (typically, because dummy variables are used over a not
yet determined range of values because it depends on the variables).
- after three years of strict obedience to `xint` prefix, now
`\thexintexpr`, `\thexintiexpr`, `\thexintfloatexpr`, and
`\thexintiiexpr` are provided as synonyms to `\xinttheexpr`, etc...
### Bug fixes
- the `(cond)?{foo}{bar}` operator from **xintexpr** mis-behaved in
certain circumstances (such as an empty `foo`).
- the **xintexpr** `1.2f` `binomial` function (which uses
`\xintiiBinomial` from **xint.sty** or `\xintFloatBinomial` from
**xintfrac.sty**) deliberately raised an error for `binomial(x,y)`
with `y<0` or `x<y`. This was unfortunate, and it now simply
evaluates to zero in such cases.
- similarly the `pfactorial` function was very strict and
`pfactorial(x,y)` deliberately raised an out-of-range error if not
used with non-negative integers with `x` less than `y`. It now avoids
doing that and allows negative arguments.
- the `add` and `mul` from **xintexpr**, which work with dummy
variables since `1.1`, raised an error since `1.2c 2015/11/16` when
the dummy variable was given an empty range (or list) of values,
rather than producing respectively `0` and `1` as formerly.
`1.2g (2016/03/19)`
----
### Incompatible changes
- inside expressions, list item selector `[L][n]` counts starting at
zero, not at one. This is more coherent with `[L][a:b]` which was
already exactly like in Python since its introduction. A function
len(L) replaces earlier `[L][0]`.
- former `iter` keyword now called `iterr`. Indeed it matched with
`rrseq`, the new `iter` (which was somehow missing from `1.1`) is the
one matching `rseq`. Allows to iterate more easily with a "list"
variable.
### Improvements and new features
- in **xintexpr.sty**: list selectors `[L][n]` and `[L][a:b]` are more
efficient: the earlier `1.1` routines did back and forth conversions
from comma separated values to braced tokens, the `1.2g` routines use
macros from **xinttools.sty** handling directly the encountered lists
of comma separated values.
- in **xinttools.sty**: slight improvements in the efficiency of the
`\xintNthElt`, `\xintKeep`, `\xintTrim` routines and new routines
handling directly comma separated values. The latter are not included
in the user manual (they are not `\long`, they don't make efforts to
preserve some braces, do not worry about spaces, all those worries
being irrelevant to the use in expressions for list selectors).
- a slight speed improvement to `\xintFloatSqrt` in its quest of
correct rounding.
- float multiplication and division handle more swiftly operands
(non-fractional) with few digits, when the float precision is large.
- the syntax of expressions is described in a devoted chapter of the
documentation; an example shows how to implement (expandably) the
Brent-Salamin algorithm for computation of Pi using `iter` in a float
expression.
`1.2f (2016/03/12)`
----
### Incompatible changes
- no more `\xintFac` macro but `\xintiFac/\xintiiFac/\xintFloatFac`.
### Bug fixes
- squaring macro `\xintSqr` from **xintfrac.sty** was broken due to a
misspelled sub-macro name. Dates back to `1.1` release of `2014/10/28`
`:-((`.
- `1.2c`'s fix to the subtraction bug from `1.2` introduced another bug,
which in some cases could create leading zeroes in the output, or even
worse. This could invalidate other routines using subtractions, like
`\xintiiSquareRoot`.
- the comparison operators were not recognized by `\xintNewIIExpr` and
`\xintdefiifunc` constructs.
### Improvements and new features
- functions `binomial`, `pfactorial` and `factorial` in both integer
and float versions.
- macros `\xintiiBinomial`, `\xintiiPFactorial`
(**xint.sty**) and `\xintFloatBinomial`, `\xintFloatPFactorial`
(**xintfrac.sty**). Improvements to `\xintFloatFac`.
- faster implementation and increased accuracy of float power macros.
Half-integer exponents are now accepted inside float expressions.
- faster implementation of both integral and float square root macros.
- the float square root achieves
*correct* (aka *exact*) rounding in arbitrary precision.
- modified behaviour for the `\xintPFloat` macro, used by
`\xintthefloatexpr` to prettify its output. It now opts for decimal
notation if and only if scientific notation would use an exponent between
`-5` and `5` inclusive. The zero value is printed `0.` with a dot.
- the float macros for addition, subtraction, multiplication, division now
first round their two operands to P, not P+2, significant places before
doing the actual computation (P being the target precision). The same
applies to the power macros and to the square root macro.
- the documentation offers a more precise (and accurate) discussion of
floating point issues.
- various under-the-hood code improvements; the floatexpr operations are
chained in a faster way, from skipping some unneeded parsing on results of
earlier computations. The absence of a real inner data structure for floats
(incorporating their precisions, for one) is however still a bit hair
raising: currently the lengths of the mantissas of the operands are computed
again by each float macro or expression operation.
- (TeXperts only) the macros defined (internally) from `\xintdeffunc` et al.
constructs do not incorporate an initial `\romannumeral` anymore.
- renewed desperate efforts at improving the documentation by random
shuffling of sections and well thought additions; cuts were considered and
even performed.
`1.2e (2015/11/22)`
----
### Bug fixes
- in **xintfrac**: the `\xintFloatFac` from release `1.2` parsed its
argument only through `\numexpr` but it should have used `\xintNum`.
- in **xintexpr**: release `1.2d` had broken the recognition of
sub-expressions immediately after variable names (with tacit
multiplication).
- in **xintexpr**: contrarily to what `1.2d` documentation said, tacit
multiplication was not yet always done with enhanced precedence. Now
yes.
### Improvements and new features
- macro `\xintunassignvar`.
- slight modifications of the logged messages in case of `\xintverbosetrue`.
- a space in `\xintdeffunc f(x)<space>:= expression ;` is now accepted.
- documentation enhancements: the _Quick Sort_ section with its included
code samples has been entirely re-written; the _Commands of the xintexpr
package_ section has been extended and reviewed entirely.
`1.2d (2015/11/18)`
----
### Bug fixes
- in **xintcore**: release `1.2c` had inadvertently broken the
`\xintiiDivRound` macro.
### Improvements and new features
- the function definitions done by `\xintdeffunc` et al., as well as
the macro declarations by `\xintNewExpr` et al. now have only local
scope.
- tacit multiplication applies to more cases, for example (x+y)z, and
always ties more than standard * infix operator, e.g. x/2y is like
x/(2*y).
- some documentation enhancements, particularly in the chapter on
xintexpr.sty, and also in the code source comments.
`1.2c (2015/11/16)`
----
### Bug fixes
- in **xintcore**: recent release `1.2` introduced a bug in the
subtraction (happened when 00000001 was found under certain
circumstances at certain mod 8 locations).
### Improvements and new features
- macros `\xintdeffunc`, `\xintdefiifunc`, `\xintdeffloatfunc` and
boolean `\ifxintverbose`.
- on-going code improvements and documentation enhancements, but
stopped in order to issue this bugfix release.
`1.2b (2015/10/29)`
----
### Bug fixes
- in **xintcore**: recent release `1.2` introduced a bug in the division
macros, causing a crash when the divisor started with 99999999 (it was
attempted to use with 1+99999999 a subroutine expecting only 8-digits
numbers).
`1.2a (2015/10/19)`
----
### Bug fixes
- in **xintexpr**: recent release `1.2` introduced a bad bug in the
parsing of decimal numbers and as a result `\xinttheexpr 0.01\relax`
expanded to `0` ! (sigh...)
### Improvements and new features
- added `\xintKeepUnbraced`, `\xintTrimUnbraced` (**xinttools**) and fixed
documentation of `\xintKeep` and `\xintTrim` regarding brace stripping.
- added `\xintiiMaxof/\xintiiMinof` (**xint**).
- TeX hackers only: replaced all code uses of ``\romannumeral-`0``
by the quicker ``\romannumeral`&&@`` (`^` being used as letter,
had to find another character usable with catcode 7).
`1.2 (2015/10/10)`
----
### Improvements and new features
- the basic arithmetic implemented in **xintcore** has been entirely
rewritten. The mathematics remains the elementary school one, but the
`TeX` implementation achieves higher speed (except, regarding
addition/subtraction, for numbers up to about thirty digits), the
gains becoming quite significant for numbers with hundreds of digits.
- the inputs must have less than 19959 digits. But computations with
thousands of digits take time.
- a previously standing limitation of `\xintexpr`, `\xintiiexpr`, and
of `\xintfloatexpr` to numbers of less than 5000 digits has been
lifted.
- a *qint* function is provided to help the parser gather huge integers
in one-go, as an exception to its normal mode of operation which
expands token by token.
- `\xintFloatFac` macro for computing the factorials of integers as
floating point numbers to a given precision. The `!` postfix operator
inside `\xintfloatexpr` maps to this new macro rather than to the
exact factorial as used by `\xintexpr` and `\xintiiexpr`.
- the macros `\xintAdd`, `\xintSub`, ..., now require package
**xintfrac**. With only **xintcore** or **xint** loaded, one _must_
use `\xintiiAdd`, `\xintiiSub`, ..., or `\xintiAdd`, `\xintiSub`,
etc...
- there is more flexibility in the parsing done by the macros from
**xintfrac** on fractional input: the decimal parts of both the
numerator and the denominator may arise from a separate expansion via
``\romannumeral-`0``. Also the strict `A/B[N]` format is a bit
relaxed: `N` may be anything understood by `\numexpr` (it could even
be empty but that possibility has been removed by later `1.2f`
release.)
- on the other hand an isolated dot `.` is not legal syntax anymore
inside the expression parsers: there must be digits either before or
after. It remains legal input for the macros of **xintfrac**.
- added `\ht`, `\dp`, `\wd`, `\fontcharht`, etc... to the tokens
recognized by the parsers and expanded by `\number`.
- an obscure bug in package **xintkernel** has been fixed, regarding
the sanitization of catcodes: under certain circumstances (which
could not occur in a normal `LaTeX` context), unusual catcodes could
end up being propagated to the external world.
- an effort at randomly shuffling around various pieces of the
documentation has been done.
`1.1c (2015/09/12)`
----
- bugfix regarding macro `\xintAssign` from **xinttools** which did
not behave correctly in some circumstances (if there was a space
before `\to`, in particular).
- very minor code improvements, and correction of some issues
regarding the source code formatting in `sourcexint.pdf`, and
minor issues in `Makefile.mk`.
`1.1b (2015/08/31)`
----
- bugfix: some macros needed by the integer division routine from
**xintcore** had been left in **xint.sty** since release `1.1`. This
for example broke the `\xintGCD` from **xintgcd** if package **xint**
was not loaded.
- Slight enhancements to the documentation, particularly in the
`Read this first` section.
`1.1a (2014/11/07)`
----
- fixed a bug which prevented `\xintNewExpr` from producing correctly working
macros from a comma separated replacement text.
- `\xintiiSqrtR` for rounded integer square root; former `\xintiiSqrt`
already produced truncated integer square root; corresponding function
`sqrtr` added to `\xintiiexpr..\relax` syntax.
- use of straight quotes in the documentation for better legibility.
- added `\xintiiIsOne`, `\xintiiifOne`, `\xintiiifCmp`, `\xintiiifEq`,
`\xintiiifGt`, `\xintiiifLt`, `\xintiiifOdd`, `\xintiiCmp`, `\xintiiEq`,
`\xintiiGt`, `\xintiiLt`, `\xintiiLtorEq`, `\xintiiGtorEq`, `\xintiiNeq`,
mainly for efficiency of `\xintiiexpr`.
- for the same reason, added `\xintiiGCD` and `\xintiiLCM`.
- added the previously mentioned `ii` macros, and some others from `1.1`, to
the user manual. But their main usage is internal to `\xintiiexpr`, to skip
unnecessary overheads.
- various typographical fixes throughout the documentation, and a bit
of clean up of the code comments. Improved `\Factors` example of nested
`subs`, `rseq`, `iter` in `\xintiiexpr`.
`1.1 (2014/10/28)`
----
bug fixes
: - `\xintZapFirstSpaces` hence also `\xintZapSpaces` from package **xinttools**
were buggy when used with an argument either empty or containing only
space tokens.
- `\xintiiexpr` did not strip leading zeroes, hence
`\xinttheiiexpr 001+1\relax` did not obtain the expected result ...
- `\xinttheexpr \xintiexpr 1.23\relax\relax` should have produced `1`,
but it produced `1.23`
- the catcode of `;` was not set at package launching time.
- the `\XINTinFloatPrd:csv` macro name had a typo, hence `prd` was
non-functional in `\xintfloatexpr`.
breaking changes
: - in `\xintiiexpr`, `/` does _rounded_ division, rather than the
Euclidean division (for positive arguments, this is truncated division).
The `//` operator does truncated division,
- the `:` operator for three-way branching is gone, replaced with `??`,
- `1e(3+5)` is now illegal. The number parser identifies `e` and `E`
in the same way it does for the decimal mark, earlier versions treated
`e` as `E` rather as infix operators of highest precedence,
- the `add` and `mul` have a new syntax, old syntax is with `` `+` `` and
`` `*` `` (left quotes mandatory), `sum` and `prd` are gone,
- no more special treatment for encountered brace pairs `{..}` by the
number scanner, `a/b[N]` notation can be used without use of braces (the
`N` will end up as is in a `\numexpr`, it is not parsed by the
`\xintexpr`-ession scanner),
- although `&` and `|` are still available as Boolean operators the
use of `&&` and `||` is strongly recommended. The single
letter operators might be assigned some other meaning in later releases
(bitwise operations, perhaps). Do not use them.
- in earlier releases, place holders for `\xintNewExpr` could either
be denoted `#1`, `#2`, ... or also `$1`, `$2`, ...
Only the usual `#` form is now accepted and the special cases previously
treated via the second form are now managed via a `protect(...)` function.
**novelties :**
* new package **xintcore** has been split off **xint**. It contains the
core arithmetic macros. It is loaded by package **bnumexpr**,
* neither **xint** nor **xintfrac** load **xinttools**. Only
**xintexpr** does,
* whenever some portion of code has been revised, often use has been made of
the `\xint_dothis` and `\xint_orthat` pair of macros for expandably
branching,
* these tiny helpful macros, and a few others are in package
**xintkernel** which contains also the catcode and loading order
management code, initially inspired by code found in Heiko Oberdiek's
packages,
* the source code, which was suppressed from `xint.pdf` in release
`1.09n`, is now compiled into a separate file `sourcexint.pdf`,
* faster handling by `\xintAdd`, `\xintSub`, `\xintMul`, ... of the case
where one of the arguments is zero,
* the `\xintAdd` and `\xintSub` macros from package **xintfrac** check if
one of the denominators is a multiple of the other, and only if this is
not the case do they multiply the denominators. But systematic reduction
would be too costly,
* this naturally will be also the case for the `+` and `-` operations
in `\xintexpr`,
* macros `\xintiiDivRound`, `\xintiiDivTrunc` and `\xintiiMod` for
rounded and truncated division of big integers (now in **xintcore**),
alongside the earlier `\xintiiQuo` and `\xintiiRem`,
* with **xintfrac** loaded, the `\xintNum` macro does `\xintTTrunc`
(which is truncation to an integer, same as `\xintiTrunc {0}`),
* macro `\xintMod` in **xintfrac** for modulo operation with
fractional numbers,
* `\xintiexpr`, `\xinttheiexpr` admit an optional argument within brackets
`[d]`, they round the computation result (or results, if comma separated)
to `d` digits after decimal mark, (the whole computation is done exactly,
as in `xintexpr`),
* `\xintfloatexpr`, `\xintthefloatexpr` similarly admit an optional
argument which serves to keep only `d` digits of precision, getting rid
of cumulated uncertainties in the last digits (the whole computation is
done according to the precision set via `\xintDigits`),
* `\xinttheexpr` and `\xintthefloatexpr` _pretty-print_ if possible, the
former removing unit denominator or `[0]` brackets, the latter avoiding
scientific notation if decimal notation is practical,
* the `//` does truncated division and `/:` is the associated modulo,
* multi-character operators `&&`, `||`, `==`, `<=`, `>=`, `!=`,
`**`,
* multi-letter infix binary words `'and'`, `'or'`, `'xor'`, `'mod'`
(straight quotes mandatory),
* functions `even`, `odd`,
* `\xintdefvar A3:=3.1415;` for variable definitions (non expandable,
naturally), usable in subsequent expressions; variable names may contain
letters, digits, underscores. They should not start with a digit, the `@`
is reserved, and single lowercase and uppercase Latin letters are
predefined to work as dummy variables (see next),
* generation of comma separated lists `a..b`, `a..[d]..b`,
* Python syntax-like list extractors `[list][n:]`, `[list][:n]`,
`[list][a:b]` allowing negative indices, but no optional step argument,
and `[list][n]` (`n=0` for the number of items in the list),
* functions `first`, `last`, `reversed`,
* itemwise operations on comma separated lists `a*[list]`, etc.., possible
on both sides `a*[list]^b`, and obeying the same precedence rules as with
numbers,
* `add` and `mul` must use a dummy variable: `add(x(x+1)(x-1), x=-10..10)`,
* variable substitutions with `subs`:
`subs(subs(add(x^2+y^2,x=1..y),y=t),t=20)`,
* sequence generation using `seq` with a dummy variable: `seq(x^3,
x=-10..10)`,
* simple recursive lists with `rseq`, with `@` given the last value,
`rseq(1;2@+1,i=1..10)`,
* higher recursion with `rrseq`, `@1`, `@2`, `@3`, `@4`, and `@@(n)`
for earlier values, up to `n=K` where `K` is the number of terms of the
initial stretch `rrseq(0,1;@1+@2,i=2..100)`,
* iteration with `iter` which is like `rrseq` but outputs only the
last `K` terms, where `K` was the number of initial terms,
* inside `seq`, `rseq`, `rrseq`, `iter`, possibility to use `omit`,
`abort` and `break` to control termination,
* `n++` potentially infinite index generation for `seq`, `rseq`,
`rrseq`, and `iter`, it is advised to use `abort` or `break(..)` at
some point,
* the `add`, `mul`, `seq`, ... are nestable,
* `\xintthecoords` converts a comma separated list of an even number
of items to the format expected by the `TikZ` `coordinates` syntax,
* completely new version `\xintNewExpr`, `protect` function to handle
external macros. The dollar sign
`$` for place holders is not accepted anymore, only the standard macro
parameter `#`. Not all constructs are compatible with `\xintNewExpr`.
% $ this docstripped line for emacs buffer fontification issues in doctex-mode
`1.09n (2014/04/01)`
----
* the user manual does not include by default the source code
anymore: the `\NoSourceCode` toggle in file `xint.tex` has to
be set to 0 before compilation to get source code inclusion
(later release `1.1` made source code available as `sourcexint.pdf`).
* bug fix (**xinttools**) in `\XINT_nthelt_finish` (this bug was
introduced in `1.09i` of `2013/12/18` and showed up when the index
`N` was larger than the number of elements of the list).
`1.09m (2014/02/26)`
----
* new in **xinttools**: `\xintKeep` keeps the first `N` or last
`N` elements of a list (sequence of braced items); `\xintTrim`
cuts out either the first `N` or the last `N` elements from a
list.
* new in **xintcfrac**: `\xintFGtoC` finds the initial partial
quotients common to two numbers or fractions `f` and `g`;
`\xintGGCFrac` is a clone of `\xintGCFrac` which however does not
assume that the coefficients of the generalized continued
fraction are numeric quantities. Some other minor changes.
`1.09kb (2014/02/13)`
----
* bug fix (**xintexpr**): an aloof modification done by `1.09i` to
`\xintNewExpr` had resulted in a spurious trailing space present
in the outputs of all macros created by `\xintNewExpr`, making
nesting of such macros impossible.
* bug fix (**xinttools**): `\xintBreakFor` and `\xintBreakForAndDo`
were buggy when used in the last iteration of an `\xintFor` loop.
* bug fix (**xinttools**): `\xintSeq` from `1.09k` needed a `\chardef`
which was missing from `xinttools.sty`, it was in `xint.sty`.
`1.09k (2014/01/21)`
----
* inside `\xintexpr..\relax` (and its variants) tacit multiplication is
implied when a number or operand is followed directly with an
opening parenthesis,
* the `"` for denoting (arbitrarily big) hexadecimal numbers is
recognized by `\xintexpr` and its variants (package
**xintbinhex** is required); a fractional hexadecimal part
introduced by a dot `.` is allowed.
* re-organization of the first sections of the user manual.
* bug fix (**xinttools**, **xint**, ...): forgotten catcode check of
`"` at loading time has been added.
`1.09j (2014/01/09)`
----
* (**xint**) the core division routines have been re-written for some
(limited) efficiency gain, more pronounced for small divisors. As a
result the *computation of one thousand digits of $\pi$* is close
to three times faster than with earlier releases.
* some various other small improvements, particularly in the power
routines.
* (**xintfrac**) a macro `\xintXTrunc` is designed to produce
thousands or even tens of thousands of digits of the decimal
expansion of a fraction. Although completely expandable it has its
use limited to inside an `\edef`, `\write`, `\message`, \dots. It
can thus not be nested as argument to another package macro.
* (**xintexpr**) the tacit multiplication done in `\xintexpr..\relax`
on encountering a count register or variable, or a `\numexpr`,
while scanning a (decimal) number, is extended to the case of a sub
`\xintexpr`-ession.
* `\xintexpr` can now be used in an `\edef` with no `\xintthe` prefix;
it will execute completely the computation, and the error message
about a missing `\xintthe` will be inhibited. Previously, in the
absence of `\xintthe`, expansion could only be a full one (with
``\romannumeral-`0``), not a complete one (with `\edef`). Note
that this differs from the behavior of the non-expandable
`\numexpr`: `\the` or `\number` (or `\romannumeral`) are needed
not only to print but
also to trigger the computation, whereas `\xintthe` is mandatory
only for the printing step.
* the default behavior of `\xintAssign` is changed, it now does not
do any further expansion beyond the initial full-expansion which
provided the list of items to be assigned to macros.
* bug fix (**xintfrac**): `1.09i` did an unexplainable change to
`\XINT_infloat_zero` which broke the floating point routines for
vanishing operands =:(((
* bug fix: the `1.09i` `xint.ins` file produced a buggy `xint.tex` file.
`1.09i (2013/12/18)`
----
* (**xintexpr**) `\xintiiexpr` is a variant of `\xintexpr` which is
optimized to deal only with (long) integers, `/` does a euclidean
quotient.
* `\xintnumexpr`, `\xintthenumexpr`, `\xintNewNumExpr` are renamed,
respectively, `\xintiexpr`, `\xinttheiexpr`, `\xintNewIExpr`. The
earlier denominations are kept but to be removed at some point.
* it is now possible within `\xintexpr...\relax` and its variants to
use count, dimen, and skip registers or variables without
explicit `\the/\number`: the parser inserts automatically
`\number` and a tacit multiplication is implied when a register
or variable immediately follows a number or fraction. Regarding
dimensions and `\number`, see the further discussion in
*Dimensions*.
* (**xintfrac**) conditional `\xintifOne`; `\xintifTrueFalse`
renamed to `\xintifTrueAelseB`; macros `\xintTFrac`
(`fractional part`, mapped to function `frac` in
`\xintexpr`-essions), `\xintFloatE`.
* (**xinttools**) `\xintAssign` admits an optional argument to
specify the expansion type to be used: `[]` (none, default), `[o]`
(once), `[oo]` (twice), `[f]` (full), `[e]` (`\edef`),... to define
the macros
* **xinttools** defines `\odef`, `\oodef`, `\fdef` (if the names have
already been assigned, it uses `\xintoodef` etc...). These tools are
provided for the case one uses the package macros in a non-expandable
context. `\oodef` expands twice the macro replacement text, and `\fdef`
applies full expansion. They are useful in situations where one does not
want a full `\edef`. `\fdef` appears to be faster than `\oodef` in almost
all cases (with less than thousand digits in the result), and even faster
than `\edef` for expanding the package macros when the result has a few
dozens of digits. `\oodef` needs that expansion ends up in thousands of
digits to become competitive with the other two.
* some across the board slight efficiency improvement as a result of
modifications of various types to *fork macros* and *branching
conditionals* which are used internally.
* bug fix (**xint**): `\xintAND` and `\xintOR` inserted a space token
in some cases and did not expand as promised in two steps `:-((`
(bug dating back to `1.09a` I think; this bug was without
consequences when using `&` and `|` in `\xintexpr-essions`, it
affected only the macro form).
* bug fix (**xintcfrac**): `\xintFtoCCv` still ended fractions with
the `[0]`'s which were supposed to have been removed since release
`1.09b`.
`1.09h (2013/11/28)`
----
* parts of the documentation have been re-written or re-organized,
particularly the discussion of expansion issues and of input and
output formats.
* the expansion types of macro arguments are documented in the margin
of the macro descriptions, with conventions mainly taken over
from those in the `LaTeX3` documentation.
* a dependency of **xinttools** on **xint** (inside `\xintSeq`) has
been removed.
* (**xintgcd**) `\xintTypesetEuclideAlgorithm` and
`\xintTypesetBezoutAlgorithm` have been slightly modified
(regarding indentation).
* (**xint**) macros `xintiSum` and `xintiPrd` are renamed to
`\xintiiSum` and `\xintiiPrd`.
* (**xinttools**) a count register used in `1.09g` in the `\xintFor`
loops for parsing purposes has been removed and replaced by use of
a `\numexpr`.
* the few uses of `\loop` have been replaced by `\xintloop/\xintiloop`.
* all macros of **xinttools** for which it makes sense are now declared
`\long`.
`1.09g (2013/11/22)`
----
* a package **xinttools** is detached from **xint**, to make tools such
as `\xintFor`, `\xintApplyUnbraced`, and `\xintiloop` available
without the **xint** overhead.
* expandable nestable loops `\xintloop` and `\xintiloop`.
* bugfix: `\xintFor` and `\xintFor*` do not modify anymore the value of
`\count 255`.
`1.09f (2013/11/04)`
----
* (**xint**) `\xintZapFirstSpaces`, `\xintZapLastSpaces`,
`\xintZapSpaces`, `\xintZapSpacesB`, for expandably stripping away
leading and/or ending spaces.
* `\xintCSVtoList` by default uses `\xintZapSpacesB` to strip away
spaces around commas (or at the start and end of the comma
separated list).
* also the `\xintFor` loop will strip out all spaces around commas and
at the start and the end of its list argument; and similarly for
`\xintForpair`, `\xintForthree`, `\xintForfour`.
* `\xintFor` *et al.* accept all macro parameters from `#1` to
`#9`.
* for reasons of inner coherence some macros previously with one extra
`i` in their names (e.g. `\xintiMON`) now have a doubled
`ii` (`\xintiiMON`) to indicate that they skip the overhead of
parsing their inputs via `\xintNum`. Macros with a *single*
`i` such as `\xintiAdd` are those which maintain the
non-**xintfrac** output format for big integers, but do parse
their inputs via `\xintNum` (since release `1.09a`). They too may
have doubled-`i` variants for matters of programming optimization
when working only with (big) integers and not fractions or
decimal numbers.
`1.09e (2013/10/29)`
----
* (**xint**) `\xintintegers`, `\xintdimensions`, `\xintrationals`
for infinite `\xintFor` loops, interrupted with `\xintBreakFor` and
`\xintBreakForAndDo`.
* `\xintifForFirst`, `\xintifForLast` for the `\xintFor` and
`\xintFor*` loops,
* the `\xintFor` and `xintFor*` loops are now `\long`, the
replacement text and the items may contain explicit `\par`'s.
* conditionals `\xintifCmp`, `\xintifInt`, `\xintifOdd`.
* bug fix (**xint**): the `\xintFor` loop (not `\xintFor*`) did
not correctly detect an empty list.
* bug fix (**xint**): `\xintiSqrt {0}` crashed. `:-((`
* the documentation has been enriched with various additional examples,
such as the *the quick sort algorithm
illustrated* or the various ways of *computing prime numbers*.
* the documentation explains with more details various expansion
related issues, particularly in relation to conditionals.
`1.09d (2013/10/22)`
----
* bug fix (**xint**): `\xintFor*` is modified to gracefully
handle a space token (or more than one) located at the very end of
its list argument (as the space before `\do` in `\xintFor* #1 in
{{a}{b}{c}<space>} \do {stuff}`; spaces at other locations were
already harmless). Furthermore this new version _f-expands_ the
un-braced list items. After `\def\x{{1}{2}}` and `\def\y{{a}\x
{b}{c}\x }`, `\y` will appear to `\xintFor*` exactly as if it had
been defined as `\def\y{{a}{1}{2}{b}{c}{1}{2}}`.
* same bug fix for `\xintApplyInline`.
`1.09c (2013/10/09)`
----
* (**xintexpr**) added `bool` and `togl` to the `\xintexpr` syntax;
also added `\xintboolexpr` and `\xintifboolexpr`.
* added `\xintNewNumExpr` (now `\xintNewIExpr` and `\xintNewBoolExpr`),
* the factorial `!` and branching `?`, `:`, operators (in
`\xintexpr...\relax`) have now less precedence than a function
name located just before,
* (**xint**) `\xintFor` is a new type of loop, whose replacement text
inserts the comma separated values or list items via macro
parameters, rather than encapsulated in macros; the loops are
nestable up to four levels (nine levels since `1.09f`) and their
replacement texts are allowed to close groups as happens with the
tabulation in alignments,
* `\xintForpair`, `\xintForthree`, `\xintForfour` are experimental
variants of `\xintFor`,
* `\xintApplyInline` has been enhanced in order to be usable for
generating rows (partially or completely) in an alignment,
* command `\xintSeq` to generate (expandably) arithmetic sequences
of (short) integers,
* again various improvements and changes in the documentation.
`1.09b (2013/10/03)`
----
* various improvements in the documentation,
* more economical catcode management and re-loading handling,
* removal of all those `[0]`'s previously forcefully added at the end
of fractions by various macros of **xintcfrac**,
* `\xintNthElt` with a negative index returns from the tail of the
list,
* macro `\xintPRaw` to have something like what `\xintFrac` does in
math mode; i.e. a `\xintRaw` which does not print the denominator
if it is one.
`1.09a (2013/09/24)`
----
* (**xintexpr**) `\xintexpr..\relax` and `\xintfloatexpr..\relax`
admit functions in their syntax, with comma separated values as
arguments, among them `reduce, sqr, sqrt, abs, sgn, floor, ceil,
quo, rem, round, trunc, float, gcd, lcm, max, min, sum, prd, add,
mul, not, all, any, xor`.
* comparison (`<`, `>`, `=`) and logical (`|`, `&`) operators.
* the command `\xintthe` which converts `\xintexpr`essions into
printable format (like `\the` with `\numexpr`) is more efficient,
for example one can do `\xintthe\x` if `\x` was defined to be an
`\xintexpr..\relax`:
\def\x{\xintexpr 3^57\relax}
\def\y{\xintexpr \x^(-2)\relax}
\def\z{\xintexpr \y-3^-114\relax}
\xintthe\z
* `\xintnumexpr .. \relax` (now renamed `\xintiexpr`) is `\xintexpr
round( .. ) \relax`.
* `\xintNewExpr` now works with the standard macro parameter character
`#`.
* both regular `\xintexpr`-essions and commands defined by
`\xintNewExpr` will work with comma separated lists of
expressions,
* commands `\xintFloor`, `\xintCeil`, `\xintMaxof`, `\xintMinof`
(package **xintfrac**), `\xintGCDof`, `\xintLCM`, `\xintLCMof`
(package **xintgcd**), `\xintifLt`, `\xintifGt`, `\xintifSgn`,
`\xintANDof`, ...
* The arithmetic macros from package **xint** now filter their operands
via `\xintNum` which means that they may use directly count
registers and `\numexpr`-essions without having to prefix them by
`\the`. This is thus similar to the situation holding previously
already when **xintfrac** was loaded.
* a bug (**xintfrac**) introduced in `1.08b` made `\xintCmp` crash
when one of its arguments was zero. `:-((`
`1.08b (2013/06/14)`
----
* (**xintexpr**) Correction of a problem with spaces inside
`\xintexpr`-essions.
* (**xintfrac**) Additional improvements to the handling of floating
point numbers.
* section *Use of count registers* documenting how count
registers may be directly used in arguments to the macros of
**xintfrac**.
`1.08a (2013/06/11)`
----
* (**xintfrac**) Improved efficiency of the basic conversion from
exact fractions to floating point numbers, with ensuing speed gains
especially for the power function macros `\xintFloatPow` and
`\xintFloatPower`,
* Better management by `\xintCmp`, `\xintMax`, `\xintMin` and
`\xintGeq` of inputs having big powers of ten in them.
* Macros for floating point numbers added to the **xintseries**
package.
`1.08 (2013/06/07)`
----
* (**xint** and **xintfrac**) Macros for extraction of square roots,
for floating point numbers (`\xintFloatSqrt`), and integers
(`\xintiSqrt`).
* new package **xintbinhex** providing *conversion routines* to and from
binary and hexadecimal bases.
`1.07 (2013/05/25)`
----
* The **xintexpr** package is a new core constituent (which loads
automatically **xintfrac** and **xint**) and implements the
expandable expanding parser
\xintexpr . . . \relax,
and its variant
\xintfloatexpr . . . \relax
allowing on input formulas using the infix operators `+`, `-`, `*`,
`/`, and `^`, and arbitrary levels of parenthesizing. Within a
float expression the operations are executed according to the
current value set by `\xintDigits`. Within an `\xintexpr`-ession the
binary operators are computed exactly.
To write the `\xintexpr` parser I benefited from the commented
source of the `l3fp` parser; the `\xintexpr` parser has its own
features and peculiarities. *See its documentation*.
* The floating point precision `D` is set (this is a local assignment
to a `\mathchar` variable) with `\xintDigits := D;` and queried
with `\xinttheDigits`. It may be set to anything up to
`32767`.[^1] The macro incarnations of the binary operations
admit an optional argument which will replace pointwise `D`; this
argument may exceed the `32767` bound.
* The **xintfrac** macros now accept numbers written in scientific
notation, the `\xintFloat` command serves to output its argument
with a given number `D` of significant figures. The value of `D`
is either given as optional argument to `\xintFloat` or set with
`\xintDigits := D;`. The default value is `16`.
[^1]: but values higher than 100 or 200 will presumably give too slow
evaluations.
`1.06b (2013/05/14)`
----
* Minor code and documentation improvements. Everywhere in the source
code, a more modern underscore has replaced the @ sign.
`1.06 (2013/05/07)`
----
* Some code improvements, particularly for macros of **xint** doing loops.
* New utilities in **xint** for expandable manipulations of lists:
\xintNthElt, \xintCSVtoList, \xintRevWithBraces
* The macros did only a double expansion of their arguments. They now
fully expand them (using ``\romannumeral-`0``). Furthermore, in the
case of arguments constrained to obey the TeX bounds they will be
inserted inside a `\numexpr..\relax`, hence completely expanded, one
may use count registers, even infix arithmetic operations, etc...
`1.05 (2013/05/01)`
----
Minor changes and additions to **xintfrac** and **xintcfrac**.
`1.04 (2013/04/25)`
----
* New component **xintcfrac** devoted to continued fractions.
* bug fix (**xintfrac**): `\xintIrr {0}` crashed.
* faster division routine in **xint**, new macros to deal expandably with
token lists.
* `\xintRound` added.
* **xintseries** has a new implementation of `\xintPowerSeries` based
on a Horner scheme, and new macro `\xintRationalSeries`. Both to help
deal with the *denominator buildup* plague.
* `tex xint.dtx` extracts style files (no need for a `xint.ins`).
`1.03 (2013/04/14)`
----
* new modules **xintfrac** (expandable operations on fractions) and
**xintseries** (expandable partial sums with xint package).
* slightly improved division and faster multiplication (the best
ordering of the arguments is chosen automatically).
* added illustration of Machin algorithm to the documentation.
`1.0 (2013/03/28)`
----
Initial announcement:
> The **xint** package implements with expandable TeX macros the basic
arithmetic operations of addition, subtraction, multiplication
and division, as applied to arbitrarily long numbers represented
as chains of digits with an optional minus sign.
> The **xintgcd** package provides implementations of the Euclidean
algorithm and of its typesetting.
> The packages may be used with Plain and with LaTeX.
%</changes>------------------------------------------------------
%<*makefile>------------------------------------------------------
# This file: Makefile.mk (generated from xint.dtx)
# Tested on Mac OS X Mavericks with GNU Make 3.81,
# TeXLive 2014 and Pandoc 1.13.1.
# Either download the master Makefile from
# http://mirror.ctan.org/macros/generic/xint
# or rename the present one as "Makefile".
# Then run "make" or equivalently "make help" to
# get instructions. Compilation of the complete
# documentation requires Pandoc.
# Note to myself: I wanted to use .RECIPEPREFIX = > but it is supported
# only with GNU Make 3.82 and later.
# this crazyness is to circumvent a problem with docstrip generation
# of the Makefile; we do not want two empty lines becoming only one
nullstring :=
define newline
$(nullstring)
endef
# will speed-up a little, I think.
newline := $(newline)
define helptext
==== INSTRUCTIONS
The Makefile is to automatize the extraction and compilation from
xint.dtx of package files and documentation files, and for producing
xint.tds.zip. It is for GNU/Linux like systems, with a teTeX like
installation such as TeXLive. Tested on Mac OS X Mavericks with TL2014.
For compiling the PDF files, packages newtx, newtxtt, etoc,... are used
and should be up-to-date (as of 2014/10). Conversion to plain, html and
pdf format of README.md and CHANGES.md (make PanPDF, make PanHTML)
require Pandoc software. (tested with Pandoc 1.13.1).
It is recommended to work with xint.dtx and Makefile in an otherwise
initially empty temporary repertory.
make help
prints this help (using more). It will also have already extracted
all files from xint.dtx.
make helpless
prints this help (using less).
make xint.pdf
extracts files and produces only xint.pdf, via latex+dvipdfmx.
No Pandoc needed.
make sourcexint.pdf
extracts files and produces only sourcexint.pdf, via latex+dvipdfmx.
No Pandoc needed.
make PanPDF
produces README.pdf and CHANGES.pdf, requires Pandoc.
make PanHTML
produces README.html and CHANGES.html, requires Pandoc.
make doc
produces all documentation.
make all
produces all documentation, and creates xint.tds.zip.
make xint.tds.zip
same as "make all"
make cleanall
removes all generated files
==== INSTALLING
The following has been tested on a TeXLive installation:
make installhome
creates xint.tds.zip, and unzips it in <TEXMFHOME>
(it assumes there is no ls-R file there)
make installlocal
creates xint.tds.zip, and unzips it in <TEXMFLOCAL>
(and then does texhash <TEXMFLOCAL>)
IT MIGHT BE NEEDED TO RUN IT AS "sudo make installlocal"
This depends on how the access rights are configured.
In case of doubt run first "make doc" and then "make
installlocal". If the latter fails, "sudo make installlocal".
make uninstallhome
removes all xint files and repertories from <TEXMFHOME>
make uninstalllocal
removes all xint files and repertories from <TEXMFLOCAL>
(and then does texhash <TEXMFLOCAL>)
IT MIGHT BE NEEDED TO RUN IT AS "sudo make uninstalllocal"
endef
.PHONY: help helpless all extract doc PanPDF PanHTML clean cleanall\
installhome uninstallhome installlocal uninstalllocal
# for printf with subst and \n, got it from
# http://stackoverflow.com/a/5887751
# I could do the trick with := here, for \n substitution, but this would add
# tiny overhead to all other operations of make
help:
@printf '$(subst $(newline),\n,$(helptext))' | more
helpless:
@printf '$(subst $(newline),\n,$(helptext))' | less
# RM = rm -f
JF_tmpdir := $(shell mktemp -d TEMP_XINT_XXX)
TEXMF_local = $(shell kpsewhich -var-value TEXMFLOCAL)
TEXMF_home = $(shell kpsewhich -var-value TEXMFHOME)
packages = xintkernel.sty xintcore.sty xint.sty xintfrac.sty xintexpr.sty\
xintgcd.sty xintbinhex.sty xintseries.sty xintcfrac.sty\
xinttools.sty
# Makefile.mk is not included in $(extracted). Its extraction rule is in
# master Makefile file. We can not extract Makefile from xint.dtx via
# docstrip, as .tex is always appended if a filename with no extension is
# specified. If "make -f Makefile.mk" is run, Makefile.mk will not be
# overwritten because tex xint.dtx does not extract it (etex xint.dtx does).
extracted = $(packages) xint.tex xint.ins README.md CHANGES.md\
doHTMLs.sh doPDFs.sh pandoctpl.latex
doc_pdf = README.pdf CHANGES.pdf
doc_html = README.html CHANGES.html
filesfortex = $(packages)
filesforsource = xint.dtx xint.ins Makefile
filesfordoc = xint.pdf sourcexint.pdf README $(doc_pdf) $(doc_html)
auxiliaryfiles = xint.tex xint.dvi xint.aux xint.toc xint.log\
sourcexint.dvi sourcexint.aux sourcexint.toc sourcexint.log\
README.tex README.dvi README.aux README.toc README.out README.log\
CHANGES.tex CHANGES.dvi CHANGES.aux CHANGES.toc CHANGES.out CHANGES.log
xint_cmd = latex -interaction=nonstopmode xint
sourcexint_cmd = latex -interaction=nonstopmode -jobname=sourcexint\
"\chardef\dosourcexint=1 \input{xint}"
all: $(extracted) doc xint.tds.zip
@echo 'make all done.'
extract: $(extracted)
$(extracted): xint.dtx
tex xint.dtx
doc: xint.pdf sourcexint.pdf README PanPDF PanHTML
@echo 'make doc done.'
xint.pdf: xint.dtx xint.tex
rm -f xint.aux xint.toc
$(xint_cmd)
$(xint_cmd)
$(xint_cmd)
dvipdfmx xint.dvi
sourcexint.pdf: xint.dtx xint.tex
rm -f sourcexint.aux sourcexint.toc
$(sourcexint_cmd)
$(sourcexint_cmd)
$(sourcexint_cmd)
dvipdfmx sourcexint.dvi
README: README.md
pandoc -t plain -o README README.md
PanPDF: $(doc_pdf)
$(doc_pdf): doPDFs.sh
chmod u+x doPDFs.sh && ./doPDFs.sh
PanHTML: $(doc_html)
$(doc_html): doHTMLs.sh
chmod u+x doHTMLs.sh && ./doHTMLs.sh
xint.tds.zip: $(filesfordoc) $(filesforsource) $(filesfortex)
rm -fr $(JF_tmpdir)
mkdir -p $(JF_tmpdir)/doc/generic/xint
mkdir -p $(JF_tmpdir)/source/generic/xint
mkdir -p $(JF_tmpdir)/tex/generic/xint
chmod -R ugo+rwx $(JF_tmpdir)
cp -a $(filesfordoc) $(JF_tmpdir)/doc/generic/xint
cp -a $(filesforsource) $(JF_tmpdir)/source/generic/xint
cp -a $(filesfortex) $(JF_tmpdir)/tex/generic/xint
cd $(JF_tmpdir); chmod -R ugo+r doc source tex
umask 0022 && cd $(JF_tmpdir) &&\
zip -r xint.tds.zip doc source tex &&\
mv -f xint.tds.zip ../
rm -fr $(JF_tmpdir)
@echo 'make xint.tds.zip done.'
xint.zip: $(filesfordoc) $(filesforsource) $(filesfortex) xint.tds.zip
mkdir -p $(JF_tmpdir)/xint
chmod ugo+rwx $(JF_tmpdir)/xint
cp -a $(filesfordoc) $(JF_tmpdir)/xint
cp -a $(filesforsource) $(JF_tmpdir)/xint
chmod -R ugo+r $(JF_tmpdir)/xint
mv xint.tds.zip $(JF_tmpdir)/
umask 0022 && cd $(JF_tmpdir) && zip -r xint.zip xint.tds.zip xint
mv $(JF_tmpdir)/xint.tds.zip ./
mv -f $(JF_tmpdir)/xint.zip ./
rm -fr $(JF_tmpdir)
@echo 'make xint.zip done.'
installhome: xint.tds.zip
unzip xint.tds.zip -d $(TEXMF_home)
uninstallhome:
cd $(TEXMF_home) && rm -fr doc/generic/xint \
source/generic/xint \
tex/generic/xint
# cf http://stackoverflow.com/a/1909390
# as kpsewhich is very slow (.5s) I want to evaluate once only.
installlocal: xint.tds.zip
$(eval $@_tmp := $(TEXMF_local))
unzip xint.tds.zip -d $($@_tmp) && texhash $($@_tmp)
uninstalllocal:
cd $(TEXMF_local) && rm -fr doc/generic/xint \
source/generic/xint \
tex/generic/xint && texhash .
clean:
rm -f $(auxiliaryfiles)
cleanall: clean
rm -f $(extracted) $(doc_pdf) $(doc_html)\
README xint.pdf sourcexint.pdf xint.tds.zip
%</makefile>$-----------------------------------------------------
%<*pandoctpl>-----------------------------------------------------
$if(dvipdfmx)$
{\csname @for\endcsname\x:=hyperref,graphicx,color,xcolor\do
{\PassOptionsToPackage{dvipdfmx}\x}}
\PassOptionsToPackage{dvipdfmx-outline-open}{hyperref}
\PassOptionsToPackage{dvipdfm}{geometry}
$endif$
\documentclass[$papersize$,fontsize=$fontsize$]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{newtxtext}
\usepackage{newtxtt}
\usepackage{newtxmath}
\usepackage{upquote}
% pour les \texttt venant de la conversion par pandoc des `...`:
\begingroup\makeatletter
\catcode`\'\active
\catcode`\*\active
\catcode`\`\active
\@firstofone {\endgroup
\def\dostraightquotesandstar{% textcomp package is loaded by newtxtext
\let`\textasciigrave
\let'\textquotesingle
\edef*{\noexpand\raisebox{-.25\noexpand\height}{\string*}}%
\catcode39\active % '
\catcode96\active % `
\catcode42\active }% *
}% for \texttt, let's just forget about math and italic correction things
\DeclareRobustCommand\texttt {\bgroup
\dostraightquotesandstar\afterassignment\ttfamily\let\next=}
$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
$if(tables)$
\usepackage{longtable,booktabs}
$endif$
\usepackage[unicode=true,bookmarks]{hyperref}
\hypersetup{breaklinks=true,%
pdfauthor={Jean-Fran\c cois Burnol},%
pdftitle={$title$ $author$ $date$},%
colorlinks=true,%
citecolor=$if(citecolor)$$citecolor$$else$blue$endif$,%
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,%
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,%
pdfborder={0 0 0},%
pdfstartview=FitH,%
pdfpagemode=UseOutlines}
%%\urlstyle{same} % don't use monospace font for urls
\setlength{\parindent}{0pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\usepackage{enumitem}
%% reduce LaTeX's insane vertical spacing around verbatim blocks
\setlength{\parskip}{\medskipamount}
\setlist[trivlist]{topsep=0pt,partopsep=0pt,itemsep=0pt,parsep=0pt}
$if(numbersections)$
\setcounter{secnumdepth}{5}
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(etoc)$\usepackage{etoc}$endif$
\title{$title$}
\author{$author$}
\date{$date$}
$for(header-includes)$
$header-includes$
$endfor$
\begin{document}
$if(title)$
\maketitle
$endif$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
\setcounter{tocdepth}{$toc-depth$}
$if(etoc)$
\etocdefaultlines
\etocmulticolstyle[$etoc$]{}
$endif$
\tableofcontents
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
\end{document}
%</pandoctpl>-----------------------------------------------------
%<*dohtmlsh>------------------------------------------------------
#! /bin/sh
# produces README.html and CHANGES.html from README.md and CHANGES.md
# tested with pandoc 1.13.1
pandoc -o README.html -s --toc -V highlighting-css=' body{margin-left : 10%; margin-right : 15%; margin-top: 4ex; font-size: 12pt;}
pre {white-space: pre-wrap; }
code {white-space: pre-wrap; }
.mono {font-family: monospace;}' README.md
pandoc -o CHANGES.html -s --toc -V highlighting-css=' body{margin-left : 10%; margin-right : 15%; margin-top: 4ex; font-size: 12pt;}
pre {white-space: pre-wrap;}
code {white-space: pre-wrap;}
#TOC {float: right; position: relative; top: 100px; margin-bottom: 100px;}' CHANGES.md
%</dohtmlsh>------------------------------------------------------
%<*dopdfsh>-------------------------------------------------------
#! /bin/sh
# produces README.pdf and CHANGES.pdf from README.md and CHANGES.md
# via latex+dvipdfmx and custom pandoc latex template
pandoc -o README.tex --template=pandoctpl --toc -V papersize=a4paper -V fontsize=11pt -V dvipdfmx --variable=geometry:footskip=1cm,left=2.5cm,right=2.5cm,top=2cm,bottom=3cm -V etoc=1 README.md
rm -f README.aux README.toc README.out
latex -interaction=nonstopmode README
latex -interaction=nonstopmode README
latex -interaction=nonstopmode README
dvipdfmx README.dvi
pandoc -o CHANGES.tex --template=pandoctpl --toc -V 'toc-depth'=2 -V papersize=a4paper -V fontsize=11pt -V dvipdfmx --variable=geometry:footskip=1cm,left=2.5cm,right=2.5cm,top=2cm,bottom=3cm -V etoc=2 CHANGES.md
rm -f CHANGES.aux CHANGES.toc CHANGES.out
latex -interaction=nonstopmode CHANGES
latex -interaction=nonstopmode CHANGES
latex -interaction=nonstopmode CHANGES
dvipdfmx CHANGES.dvi
%</dopdfsh>-------------------------------------------------------
%<*drv>-----------------------------------------------------------
%%
%% Run latex thrice on this file xint.tex then run dvipdfmx on
%% xint.dvi to produce the documentation xint.pdf. Alternatively
%% run xelatex or pdflatex thrice on xint.tex.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{xint.tex}%
[\xintbndldate\space v\xintbndlversion\space driver file for xint documentation (JFB)]%
\PassOptionsToClass{a4paper,fontsize=10pt}{scrdoc}
\chardef\NoSourceCode 1 % set it to 0 if source code inclusion desired
\input xint.dtx
%%% Local Variables:
%%% mode: latex
%%% End:
%</drv>-----------------------------------------------------------
%<*ins>-----------------------------------------------------------
%%
%% tex xint.ins extracts all package files from xint.dtx, as well as
%% xint.tex, README.md, CHANGES.md, doPDFs.sh, doHTMLs.sh.
%%
%% etex xint.ins does the same plus extracts Makefile.mk.
%%
\input docstrip.tex
\askforoverwritefalse
\generate{\nopreamble\nopostamble
\file{README.md}{\from{xint.dtx}{readme}}
\file{CHANGES.md}{\from{xint.dtx}{changes}}
\file{doHTMLs.sh}{\from{xint.dtx}{dohtmlsh}}
\file{doPDFs.sh}{\from{xint.dtx}{dopdfsh}}
\ifx\numexpr\undefined\else\catcode9 11
\file{Makefile.mk}{\from{xint.dtx}{makefile}}\fi
\usepreamble\defaultpreamble
\usepostamble\defaultpostamble
\file{pandoctpl.latex}{\from{xint.dtx}{pandoctpl}}
\file{xint.tex}{\from{xint.dtx}{drv}}
\file{xintkernel.sty}{\from{xint.dtx}{xintkernel}}
\file{xinttools.sty}{\from{xint.dtx}{xinttools}}
\file{xintcore.sty}{\from{xint.dtx}{xintcore}}
\file{xint.sty}{\from{xint.dtx}{xint}}
\file{xintbinhex.sty}{\from{xint.dtx}{xintbinhex}}
\file{xintgcd.sty}{\from{xint.dtx}{xintgcd}}
\file{xintfrac.sty}{\from{xint.dtx}{xintfrac}}
\file{xintseries.sty}{\from{xint.dtx}{xintseries}}
\file{xintcfrac.sty}{\from{xint.dtx}{xintcfrac}}
\file{xintexpr.sty}{\from{xint.dtx}{xintexpr}}}
\catcode32=13\relax% active space
\let =\space%
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* files into a directory searched by TeX:}
\Msg{*}
\Msg{* xintkernel.sty}
\Msg{* xintcore.sty}
\Msg{* xint.sty}
\Msg{* xintbinhex.sty}
\Msg{* xintgcd.sty}
\Msg{* xintfrac.sty}
\Msg{* xintseries.sty}
\Msg{* xintcfrac.sty}
\Msg{* xintexpr.sty}
\Msg{* xinttools.sty}
\Msg{*}
\Msg{* To produce the documentation run latex thrice on xint.tex}
\Msg{* then dvipdfmx on xint.dvi. Edit xint.tex to get the code}
\Msg{* source included.}
\Msg{* dvipdfmx warnings may be ignored, but if the produced pdf}
\Msg{* has font problems, run rather pdflatex on xint.tex}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
\endbatchfile
%</ins>-----------------------------------------------------------
%<*dtx>-----------------------------------------------------------
^^Bfi^^Begroup
\chardef\noetex 0
\ifx\numexpr\undefined\chardef\noetex 1 \fi
\ifnum\noetex=1 \chardef\extractfiles 0 % extract files, then stop
\else
\ifx\ProvidesFile\undefined
\chardef\extractfiles 0 % no LaTeX2e: etex, xetex, ... on xint.dtx
\else
\ifx\NoSourceCode\undefined
% latex/pdflatex/xelatex on xint.dtx, we will extract all files
\chardef\extractfiles 1 % 1 = extract and typeset, 2 = only typeset
\chardef\NoSourceCode 0 % 0 = include source code, 1 = do not
\NeedsTeXFormat{LaTeX2e}%
\PassOptionsToClass{a4paper,fontsize=10pt}{scrdoc}%
\else
% latex/pdflatex/xelatex on xint.tex
\chardef\extractfiles 2 % no extractions, but typeset
% \NoSourceCode is set-up in xint.tex
\fi
\ProvidesFile{xint.dtx}[bundle source (\xintbndlversion, \xintbndldate) %
and documentation (\xintdocdate)]%
\fi
\fi
\ifnum\extractfiles<2 % extract files
\def\MessageDeFin{\newlinechar10 \let\Msg\message
\Msg{^^J}%
\Msg{********************************************************************^^J}%
\Msg{*^^J}%
\Msg{* To finish the installation you have to move the following^^J}%
\Msg{* files into a directory searched by TeX:^^J}%
\Msg{*^^J}%
\Msg{*\space\space\space\space xintkernel.sty^^J}%
\Msg{*\space\space\space\space xintcore.sty^^J}%
\Msg{*\space\space\space\space xint.sty^^J}%
\Msg{*\space\space\space\space xintbinhex.sty^^J}%
\Msg{*\space\space\space\space xintgcd.sty^^J}%
\Msg{*\space\space\space\space xintfrac.sty^^J}%
\Msg{*\space\space\space\space xintseries.sty^^J}%
\Msg{*\space\space\space\space xintcfrac.sty^^J}%
\Msg{*\space\space\space\space xintexpr.sty^^J}%
\Msg{*\space\space\space\space xinttools.sty^^J}%
\Msg{*^^J}%
\Msg{* To produce the documentation run latex thrice on xint.tex^^J}
\Msg{* then dvipdfmx on xint.dvi. Edit xint.tex to get the code^^J}
\Msg{* source included.^^J}
\Msg{* dvipdfmx warnings may be ignored, but if the produced pdf^^J}
\Msg{* has font problems, run rather pdflatex on xint.tex^^J}
\Msg{*^^J}%
\Msg{* Happy TeXing!^^J}%
\Msg{*^^J}%
\Msg{********************************************************************^^J}%
}%
\begingroup
\input docstrip.tex
\askforoverwritefalse
\catcode9 11 % do not kill TAB in producing Makefile.mk
\generate{\nopreamble\nopostamble
\file{README.md}{\from{xint.dtx}{readme}}
\file{CHANGES.md}{\from{xint.dtx}{changes}}
% pure tex will use ^^I notation for TAB character, don't want that.
% there is a problem with xelatex, as it generates ^^I also.
\ifnum\noetex=1 \else\ifx\XeTeXinterchartoks\undefined
\file{Makefile.mk}{\from{xint.dtx}{makefile}}\fi\fi
\file{doHTMLs.sh}{\from{xint.dtx}{dohtmlsh}}
\file{doPDFs.sh}{\from{xint.dtx}{dopdfsh}}
\usepreamble\defaultpreamble
\usepostamble\defaultpostamble
\file{pandoctpl.latex}{\from{xint.dtx}{pandoctpl}}
\file{xint.ins}{\from{xint.dtx}{ins}}
\file{xint.tex}{\from{xint.dtx}{drv}}
\file{xintkernel.sty}{\from{xint.dtx}{xintkernel}}
\file{xinttools.sty}{\from{xint.dtx}{xinttools}}
\file{xintcore.sty}{\from{xint.dtx}{xintcore}}
\file{xint.sty}{\from{xint.dtx}{xint}}
\file{xintbinhex.sty}{\from{xint.dtx}{xintbinhex}}
\file{xintgcd.sty}{\from{xint.dtx}{xintgcd}}
\file{xintfrac.sty}{\from{xint.dtx}{xintfrac}}
\file{xintseries.sty}{\from{xint.dtx}{xintseries}}
\file{xintcfrac.sty}{\from{xint.dtx}{xintcfrac}}
\file{xintexpr.sty}{\from{xint.dtx}{xintexpr}}}
\endgroup
\fi % end of file extraction (from etex/latex/pdflatex/... run on xint.dtx)
\ifnum\extractfiles=0 % no LaTeX, files now extracted. Stop.
\MessageDeFin\expandafter\end
\fi
% From this point on, run is necessarily with e-TeX.
% Check if \MessageDeFin got defined, if yes put it at end of run.
\ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi
%-----------------------------------------------------------------
% -*- coding: utf-8; mode: latex -*-
%
\ifdefined\dosourcexint % this toggle is set from make sourcexint.pdf rule
\chardef\NoSourceCode 0
\else
\chardef\dosourcexint 0
\fi
% default is to assume latex + dvipdfmx
\chardef\Withdvipdfmx 1
\RequirePackage{ifpdf}
\RequirePackage{ifxetex}
\ifpdf \chardef\Withdvipdfmx 0 \fi
\ifxetex\chardef\Withdvipdfmx 0 \fi
\ifnum\Withdvipdfmx=1
\def\pgfsysdriver{pgfsys-dvipdfm.def}
\documentclass [dvipdfm, dvipdfmx, dvipdfmx-outline-open]{scrdoc}
\else
\documentclass {scrdoc}
\fi
\PassOptionsToPackage{bookmarks=true}{hyperref}
\ifnum\NoSourceCode=1 \OnlyDescription\fi
\pagestyle{headings}
\makeatletter
\def\buggysectionmark #1{% KOMA 3.12 as released to CTAN December 2013
\if@twoside\expandafter\markboth\else\expandafter\markright\fi
{\MakeMarkcase{\ifnumbered{section}{\sectionmarkformat\fi}{}#1}}{}}
\ifx\buggysectionmark\sectionmark
\def\sectionmark #1{%
\if@twoside\expandafter\markboth\else\expandafter\markright\fi
{\MakeMarkcase{\ifnumbered{section}{\sectionmarkformat}{}#1}}{}}
\fi
\makeatother
\ifxetex
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% 2016-02-28
% This is for use in pre-CTAN version of the dtx. Not needed for CTAN
% xint.dtx. Again an annoying preamble-only restriction whose rationale
% escape me. (The obelus serves to clean up the private sources from comments
% of the type as this one before uploading to CTAN).
% TS1 declarations loaded by newtxtt.
% \DeclareUnicodeCharacter{00F7}{\textdiv}
\def\PrivateObelus{\textdiv }%
\AtBeginDocument{\DeclareUnicodeCharacter {00F7}{\PrivateObelus}}%
\DeclareUnicodeCharacter {03B4}{\ensuremath{\delta}}%
\fi
\usepackage{multicol}
\usepackage{geometry}
\AtBeginDocument {\ttzfamily
\newgeometry{textwidth=\dimexpr92\fontcharwd\font`X\relax,
vscale=0.75}}
\unless\ifnum\dosourcexint=1
\usepackage{xintexpr}
\usepackage{xintbinhex}
\usepackage{xintgcd}
\usepackage{xintseries}
\usepackage{xintcfrac}
\usepackage{amsmath} % for use of \cfrac in the documentation
\usepackage{pifont} % pour la hollow star \ding{73}
\fi
\usepackage{xinttools}
\usepackage{enumitem}
\usepackage{varioref}
\usepackage{etoolbox}
\usepackage{tocloft}
\usepackage{etoc}[2013/10/16] % I need \etocdepthtag.toc
%---- USE OF ETOC FOR THE TABLES OF CONTENTS
\def\gobbletodot #1.{}
\newif\ifinmanualmaintoc % 1 avril 2014
\ifnum\dosourcexint=0
\inmanualmaintoctrue
\fi
\def\sectioncouleur{{cyan}}
\def\MARGEPAGENO {1.5em}% changera pour la partie implémentation
\etocsetstyle{section}{}
{\normalfont}
{\kern\bigskipamount
\rightskip \MARGEPAGENO\relax
\parfillskip -\MARGEPAGENO\relax
\bfseries
\leftskip \leftmargini
\noindent\llap % \llap
{\makebox[\leftmargini][l]% et \leftmargini le 12/10/2014
{\expandafter\textcolor\sectioncouleur {\etocnumber}}}%
\strut\etocname
\mdseries\nobreak\leaders\etoctoclineleaders\hfill\nobreak\strut
\makebox[\MARGEPAGENO][r]{\etocpage}\par
\let\ETOCsectionnumber\etocthenumber
}%
{}%
\newdimen\margegauchetoc
\AtBeginDocument{\margegauchetoc \dimexpr 5\fontcharwd\font`X\relax}
\makeatletter
\etocsetstyle{subsection}
{\begingroup\normalfont
\setlength{\premulticols}{0pt}%
\setlength{\multicolsep}{0pt}%
\setlength{\columnsep}{\leftmarginii}%
\setlength{\columnseprule}{.4pt}% n'influence pas séparation colonnes
\parskip\z@skip
\raggedcolumns
\addvspace{\smallskipamount}%
\begin{multicols}{2}
\leftskip \margegauchetoc % 12 octobre 2014
\ifinmanualmaintoc
\rightskip \MARGEPAGENO
\else
\rightskip \MARGEPAGENO plus 2em minus 1em
\fi
\parfillskip -\MARGEPAGENO\relax
}
{}
{\noindent
\llap{\makebox[\margegauchetoc][l]{\ttzfamily\bfseries\etoclink
{\ifinmanualmaintoc\expandafter\textcolor\sectioncouleur
{\normalfont\bfseries\ETOCsectionnumber}\fi
.\expandafter\gobbletodot\etocthenumber}}}%
\strut\etocname\nobreak
\unless\ifinmanualmaintoc\leaders\etoctoclineleaders\fi
\hfill\nobreak
\strut\makebox[\MARGEPAGENO][r]{\small\etocpage}\endgraf }
{\end{multicols}\endgroup\addvspace{\smallskipamount}}%
\etocsetstyle{subsubsection}
{\begingroup\normalfont\small
\leftskip \dimexpr\leftmargini+1em\relax }
{}
{\noindent
\llap{\makebox[\dimexpr\leftmargini+1em\relax][l]%
{\ttzfamily\bfseries\etoclink
{.\expandafter\gobbletodot\etocthenumber}}}%
\strut\etocname\nobreak
\leaders\etoctoclineleaders
\hfill\nobreak
\strut\makebox[\MARGEPAGENO][r]{\small\etocpage}\endgraf }
{\endgroup }%
\makeatother
\addtocontents{toc}{\protect\hypersetup{hidelinks}}
\usepackage[zerostyle=a,straightquotes,scaled=0.95]{newtxtt}
\usepackage{newtxmath}
\makeatletter
\DeclareFontFamily{T1}{newtxttb}{\hyphenchar\font\m@ne}
\DeclareFontShape{T1}{newtxttb}{m}{n}{
<-> s*[\newtxtt@scale]newtxttbq
}{}
\DeclareFontShape{T1}{newtxttb}{b}{n}{
<-> s*[\newtxtt@scale]newtxbttbq
}{}
\DeclareFontShape{T1}{newtxttb}{bx}{n}{
<-> ssub * newtxttb/b/n
}{}
\DeclareFontShape{T1}{newtxttb}{m}{sl}{
<-> s*[\newtxtt@scale]newtxttslbq
}{}
\DeclareFontShape{T1}{newtxttb}{m}{it}{
<-> ssub * newtxttb/m/sl
}{}
% Ajouté le 9 mars 2016
\DeclareFontShape{T1}{newtxttb}{m}{sc}{ %cap & small cap
<-> s*[\newtxtt@scale]newtxttscbq
}{}
\DeclareFontShape{T1}{newtxttb}{b}{sc}{ %bold cap & small cap
<-> s*[\newtxtt@scale]newtxbttscbq
}{}
\DeclareFontShape{T1}{newtxttb}{b}{sl}{ %bold slanted
<-> s*[\newtxtt@scale]newtxbttslbq
}{}
\DeclareFontShape{T1}{newtxttb}{b}{it}{ %bold italic
<-> ssub * newtxttb/b/sl%
}{}
\DeclareFontShape{T1}{newtxttb}{bx}{sc}{ %bold extended cap & small cap
<-> ssub * newtxttb/b/sc%
}{}
\DeclareFontShape{T1}{newtxttb}{bx}{sl}{ %bold extended slanted
<-> ssub * newtxttb/b/sl%
}{}
\DeclareFontShape{T1}{newtxttb}{bx}{it}{ %bold extended italic
<-> ssub * newtxttb/b/sl%
}{}
% Ajouté le 9 mars 2016
\DeclareEncodingSubset{TS1}{newtxttb}{0}
\DeclareFontFamily{TS1}{newtxttb}{\hyphenchar\font\m@ne}
\DeclareFontShape{TS1}{newtxttb}{m}{n}{ %medium
<-> s*[\newtxtt@scale]tcxtt%
}{}
\DeclareFontShape{TS1}{newtxttb}{m}{sc}{ %cap & small cap
<->ssub * newtxttb/m/n%
}{}
\DeclareFontShape{TS1}{newtxttb}{m}{sl}{ %slanted
<-> s*[\newtxtt@scale]tcxttsl%
}{}
\DeclareFontShape{TS1}{newtxttb}{m}{it}{ %italic
<->ssub * newtxttb/m/sl%
}{}
\DeclareFontShape{TS1}{newtxttb}{b}{n}{ %bold
<-> s*[\newtxtt@scale]tcxbtt%
}{}
\DeclareFontShape{TS1}{newtxttb}{b}{sc}{ %bold cap & small cap
<->ssub * newtxttb/b/n%
}{}
\DeclareFontShape{TS1}{newtxttb}{b}{sl}{ %bold slanted
<-> s*[\newtxtt@scale]tcxbttsl%
}{}
\DeclareFontShape{TS1}{newtxttb}{b}{it}{ %bold italic
<->ssub * newtxttb/b/sl%
}{}
\DeclareFontShape{TS1}{newtxttb}{bx}{n}{ %bold extended
<->ssub * newtxttb/b/n%
}{}
\DeclareFontShape{TS1}{newtxttb}{bx}{sc}{ %bold extended cap & small cap
<->ssub * newtxttb/b/sc%
}{}
\DeclareFontShape{TS1}{newtxttb}{bx}{sl}{ %bold extended slanted
<->ssub * newtxttb/b/sl%
}{}
\DeclareFontShape{TS1}{newtxttb}{bx}{it}{ %bold extended italic
<->ssub * newtxttb/b/it%
}{}
\makeatother
\newcommand\ttbfamily {\fontfamily{newtxttb}\selectfont }
\def\digitstt #1{\begingroup\color[named]{OrangeRed}#1\endgroup}
\let\dtt\digitstt
\ifnum\dosourcexint=1
\else
\renewcommand\familydefault\ttdefault
\usepackage[noendash]{mathastext}% pas de endahs dans newtxtt
\fi
\renewcommand\familydefault\sfdefault % <-- sans-serif in footnotes, TOC,
% headers etc...
\usepackage{xspace}
\usepackage[dvipsnames]{xcolor}
\usepackage{framed}
\makeatletter
\newenvironment{snugframed}{%
\fboxsep \dimexpr2\fontcharwd\font`X\relax
\advance\linewidth-2\fboxsep
\advance\csname @totalleftmargin\endcsname \fboxsep
\def\FrameCommand##1{\hskip\@totalleftmargin
\hskip-\fboxsep
\fbox{##1}\hskip-\fboxsep
% There is no \@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width \@totalleftmargin\z@ \linewidth\hsize
\@setminipage}%
}{\par\unskip\@minipagefalse\endMakeFramed}
\makeatother
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\definecolor{BLUE}{RGB}{0,0,255}
\definecolor{niceone}{RGB}{38,128,192}
\usepackage[para]{footmisc}
\usepackage[english]{babel}
\usepackage[autolanguage,np]{numprint}
\AtBeginDocument{\npthousandsep{,\hskip .5pt plus .1pt minus .1pt}}
\usepackage[pdfencoding=pdfdoc]{hyperref}
\hypersetup{%
linktoc=all,%
breaklinks=true,%
colorlinks=true,%
urlcolor=niceone,%
linkcolor=blue,%
pdfauthor={Jean-Fran\c cois Burnol},%
pdftitle={The xint bundle},%
pdfsubject={Arithmetic with TeX},%
pdfkeywords={Expansion, arithmetic, TeX},%
pdfstartview=FitH,%
pdfpagemode=UseOutlines}
\ifnum\dosourcexint=1
\hypersetup{pdftitle={The xint bundle source code}}
\fi
\usepackage{bookmark}
\usepackage{picture} % permet d'utiliser des unités dans les dimensions de la
% picture et dans \put
\usepackage{graphicx}
\usepackage{eso-pic}
%---- \MyMarginNote: a simple macro for some margin notes with no fuss
\makeatletter
\def\MyMarginNote {\@ifnextchar[\@MyMarginNote{\@MyMarginNote[]}}%
\let\inmarg\MyMarginNote
\def\@MyMarginNote [#1]#2{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt
{\color[named]{PineGreen}\normalfont\small
\hsize 1.6cm\rightskip.5cm minus.5cm
\hss\vtop{#2}\ $\to$#1\ }}%
\vskip\dp\strutbox }\strut\@esphack}
\def\MyMarginNoteWithBrace #1{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt
{\color[named]{PineGreen}%\normalfont\small
\hss #1\ $\bigg\{$\ }}%
\vskip\dp\strutbox }\strut\@esphack}
\def\IMPORTANT {\MyMarginNoteWithBrace
{\raisebox{-.5\height}{\resizebox{2\width}{!}{\ding{43}}}}}
\def\etype #1{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt {\hss\color[named]{PineGreen}%
\itshape \xintListWithSep{\,}{#1}\ $\star$\quad }}%
\vskip\dp\strutbox }\strut\@esphack}
\def\retype #1{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt {\hss\color[named]{PineGreen}%
\itshape \xintListWithSep{\,}{#1}\ \ding{73}\quad }}%
\vskip\dp\strutbox }\strut\@esphack}
\def\ntype #1{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt {\hss\color[named]{PineGreen}%
\itshape \xintListWithSep{\,}{#1}\quad }}%
\vskip\dp\strutbox }\strut\@esphack}
%-------------------------------------------------------------------------------
\def\Numf {{\vbox{\halign{\hfil##\hfil\cr \footnotesize
\upshape Num\cr
\noalign{\hrule height 0pt \vskip1pt\relax}
\itshape f\cr}}}}
\def\Ff {{\vbox{\halign{\hfil##\hfil\cr \footnotesize
\upshape Frac\cr
\noalign{\hrule height 0pt \vskip1pt\relax}
\itshape f\cr}}}}
\def\numx {{\vbox{\halign{\hfil##\hfil\cr \footnotesize
\upshape num\cr
\noalign{\hrule height 0pt \vskip1pt\relax}
\itshape x\cr}}}}
%-------------------------------------------------------------------------------
\def\NewWith #1{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt {\hss\color[named]{PineGreen}%
\normalfont\small
\hsize 1.5cm\rightskip.5cm minus.5cm
\vtop{\noindent New with #1}\ }}%
\vskip\dp\strutbox }\strut\@esphack}
\def\CHANGED #1{\@bsphack
\vadjust{\vskip-\dp\strutbox
\smash{\hbox to 0pt {\hss\color[named]{PineGreen}%
\normalfont\small
\hsize 1.5cm\rightskip.5cm minus.5cm
\vtop{\noindent Changed (#1)}\ }}%
\vskip\dp\strutbox }\strut\@esphack}
\makeatother
% \centeredline: OUR OWN LITTLE MACRO FOR CENTERING LINES
% =======================================================
% 7 mars 2013
% -----------
%
% This macro allows to conveniently center a line inside a paragraph and still
% allow use therein of \verb or other commands changing catcodes.
% A proposito, the \LaTeX \centerline uses \hsize and not \linewidth !
% (which in my humble opinion is bad)
% Actually my \centeredline works nicely in list environments.
% \ignorespaces ajouté le 9 juin 2013.
% Note: \centeredline creates a group
\makeatletter
\newcommand*\centeredline {%
\ifhmode \\\relax
\def\centeredline@{\hss\egroup\hskip\z@skip\ignorespaces }%
\else
\def\centeredline@{\hss\egroup }%
\fi
\afterassignment\@centeredline
\let\next=}
\def\@centeredline
{\hbox to \linewidth \bgroup \hss \bgroup \aftergroup\centeredline@ }
\newif\ifinlefted
\newcommand*\leftedline {%
\ifhmode \\\relax
\def\leftedline@{\hss\egroup\hskip\z@skip\ignorespaces }%
\else
\def\leftedline@{\hss\egroup }%
\fi
\afterassignment\@leftedline
\let\next=}
\def\@leftedline
{\hbox to \linewidth \bgroup \inleftedtrue
\everbatimeverypar
\bgroup
\aftergroup\leftedline@ }
\makeatother
% verbatim environments
% =====================
%
% June 2013, then October 2014.
% -----------------------------
%
\makeatletter
\catcode`_ 11
% some of my verbatim environments do not make the space active (\lverb e.g.). Then
% \do@noligs must be modified, \char`#1 must be followed by a space token, else,
% the `#1 expansion will swallow one space.
\def\do@noligs #1{%
\catcode`#1\active
\begingroup
\lccode`~`#1\relax
\lowercase{%
\endgroup\def~{\leavevmode\kern\z@\char`#1 }}%
}
%--- \lowast
\def\lowast{\raisebox{-.25\height}{*}}
\catcode`* 13
\def\makestarlowast {\let*\lowast\catcode`\*\active}%
\catcode`* 12
%--- for soft-wrapping. I will use discretionaries.
\DeclareFontFamily{U}{MdSymbolC}{}
\DeclareFontShape {U}{MdSymbolC}{m}{n}{<-> MdSymbolC-Regular}{}
\newbox\SoftWrapIcon
\colorlet {softwrapicon}{blue}
\def\SetSoftWrapIcon{%
\setbox\SoftWrapIcon\hb@xt@\z@
{\hb@xt@\fontdimen2\font
{\hss{\color{softwrapicon}\usefont{U}{MdSymbolC}{m}{n}\char"97}\hss}%
\hss}%
}
\AtBeginDocument {\SetSoftWrapIcon }% ttzfamily déjà fait
%--- \MacroFont, and a \MicroFont
%
% Ne PAS mettre de changement de taille de police dans \MacroFont.
\def\restoreMicroFont {\def\MicroFont {\ttbfamily\makestarlowast
\ifinlefted\else\ifineverb\else\color[named]{Blue}\fi\fi}}
\restoreMicroFont
% Notice that \macrocode uses \macro@font which freezes \MacroFont
% at \begin{document}. But doc.sty verbatim uses \MacroFont which is not
% frozen. Comprenne qui pourra...
\def\restoreMacroFont {\def\MacroFont {\ttbfamily
\ifinlefted\else\ifineverb\else\color[named]{Blue}\fi\fi}}
\restoreMacroFont
%--- straight quotes, also in macrocode (2014/11/04)
%
% There is no hook in \macrocode after \dospecials, which is done *after*
% \macro@font. Thus I will need to take the risk that some future evolution of
% doc.sty (or perhaps scrdoc) invalidates the following.
%
% Note: in contrast, \MacroFont in \verbatim is done *after* \dospecials (but
% before the space becomes active), thus I could use \MacroFont there. But as
% there is no verbatim environment anymore in xint.dtx, I don't need to take
% care of it.
%
% Actually, I should not at all rely on the doc class, I should do it all by
% myself. As I don't use at all \DocInput (which caused me loads of problems
% back then when I was trying to get a workflow satisfying my views on how
% .dtx files should be structured), there is not much rationale for using the
% doc class.
%
\def\macrocode{\macro@code
\frenchspacing \@vobeyspaces
\makestarlowast %\makequotesstraight
\xmacro@code }
% ---- a new \verb
% Initially, June 2013, then Sep 9, 2014, and Oct 9-12 2014
%
% Initial motivation was simply that doc.sty and related classes \verb
% command is with a hard-coded \ttfamily. There were further issues.
%
% 1. with |stuff with space|, paragraph reformatting in the Emacs/AUCTeX
% buffer caused havoc. Thus I wanted to be able to have the input across
% lines.
%
% 2. Hence I did not want to have spaces obeyed, as often the
% reformatting added spaces at the beginning of a line.
%
% 3. Also I wanted to allow hyphenation on output, at least at some
% locations. I did a first version which treated spaces, \, {, and }
% specially.
%
% 4. at some point I wanted to add some colored background (I have
% dropped that since due to pdf file size increase).
%
% 5. and also I got fed up from the non-compatibility with footnotes due
% to catcode freeze.
%
% Because of 5. I opted for a \scantokens approach, hence for a macro
% with delimited argument. Here is what I do now, this is compatible
% with short verbs.
\def\verb
{%
\relax \ifmmode\else\leavevmode\null\fi
\bgroup
\let\do\@makeother \dospecials
\MicroFont % change font, color, catcode hooks, ...
\catcode 32 10
\endlinechar 32
\@@jfverb
}%
% Note (Oct 12, 2014): in the improbable situation a newlinechar is
% found in the ##1, \scantokens will convert this to an end of line in
% its "write" phase, which will be then ignored in its "read" phase due
% to \endlinechar-1. This also avoids possible creation of \par which
% would defeat \@@jfverb@@. Thus it is good.
\def\@@jfverb #1{%
\ifcat\noexpand#1\noexpand~\catcode`#1\active\fi
% No problem with the EOL for the line where the short verb delimiter stands.
\def\next ##1#1{%
\@vobeyspaces\everyeof{\relax}\endlinechar\m@ne
\expandafter\@@jfverb_a\scantokens\expandafter{##1}}%
% hack with \@empty to prevent brace stripping if catcodes have been
% frozen earlier, like in footnotes.
\next \@empty
}
% We don't want a \discretionary at the very start.
% But then an empty argument is forbidden!
\def\@@jfverb_a #1{#1\@@jfverb_b }
\def\@@jfverb_b #1{\ifx\relax #1%
\egroup
\else
% \penalty\z@, or rather (Oct 11, 2014) but I then adjust the textwidth
% precisely:
\discretionary{\copy\SoftWrapIcon}{}{}%
#1\expandafter\@@jfverb_b\fi
}
\catcode`_ 8
\makeatother
% --- \lverb
% Définition de \lverb
\makeatletter
\long\def\lverb {%
\relax\par\smallskip\noindent\null
\begingroup
\bgroup
\aftergroup\@@par \aftergroup\endgroup \aftergroup\medskip
\let\do\do@noligs \verbatim@nolig@list
\let\do\@makeother \dospecials
\def\PrivateObelus{\par\noindent\textdiv}%
\catcode32 10 \catcode`\% 9 \catcode`\& 14 \catcode`\$ 0
\MicroFont % sera donc en couleur.
\@lverb
}
\def\@lverb #1{\catcode`#1\active
\lccode`\~`#1\lowercase{\let~\egroup}}%
\makeatother
%--- everbatim environment
% October 13-14, 2014
% Verbatim with an \everypar hook, mainly to have background color, followed by
% execution of the code
\makeatletter
\catcode`_ 11
\def\everbatimtop {\MacroFont\small }
\let\everbatimbottom\relax
\let\everbatimhook\relax
\newif\ifineverb
\def\everbatim {\s@everbatim\@everbatim }
\@namedef{everbatim*}{\s@everbatim\expandafter\@everbatimx\expandafter
{\the\newlinechar}}
\def\everbatimeverypar{\strut
{\color{yellow!5}\vrule\@width\linewidth }%
\kern-\linewidth
\kern\everbatimindent }
\def\everbatimindent {\z@}
% voir plus loin atbegindocument
\def\endeverbatim {\if@newlist \leavevmode\fi\endtrivlist }
\expandafter\let\csname endeverbatim*\endcsname \endeverbatim
\def\s@everbatim {%
\ineverbtrue
\everbatimtop % put there size changes
\topsep \z@skip
\partopsep \z@skip
\itemsep \z@skip
\parsep \z@skip
\parskip \z@skip
\lineskip \z@skip
\let\do\@makeother \dospecials
\let\do\do@noligs \verbatim@nolig@list
\makestarlowast
\everbatimhook
\trivlist\item\relax
\leftskip \@totalleftmargin
\rightskip \z@skip
\parindent \z@
\parfillskip\@flushglue
\parskip \z@skip
\@@par
\def\par{\leavevmode\null\@@par\pagebreak[1]}%
\everypar\expandafter{\the\everypar \unpenalty
\everbatimeverypar
\everypar \expandafter{\the\everypar\everbatimeverypar}%
}%
\obeylines \@vobeyspaces
}
\begingroup
\lccode`X 13
\catcode`X \active
\lccode`Y `* % this is because of \makestarlowast.
% I have to think whether this is useful: obviously if I were to provide
% everbatim and everbatim* in a package I wouldn't do that.
\catcode`Y \active
\catcode`| 0 \catcode`[ 1 \catcode`] 2 \catcode`* 12
\catcode`{ 12 \catcode`} 12 |catcode`\\ 12
|lowercase[|endgroup% both freezes catcodes and converts X to active ^^M
|def|@everbatim #1X#2\end{everbatim}%
[#2|end[everbatim]|everbatimbottom ]
|def|@everbatimx #1#2X#3\end{everbatimY}]%
{#3\end{everbatim*}%
\everbatimbottom
\newlinechar 13
\everbatimxprehook
\scantokens {#3}%
\newlinechar #1\relax
\everbatimxposthook
}%
% L'espace venant du endofline final mis par \scantokens sera inhibé si #3 se
% termine par un % ou un \x, etc...
\def\everbatimxprehook {\colorlet{everbsavedcolor}{.}\color[named]{OrangeRed}}
\def\everbatimxposthook {\color{everbsavedcolor}}
\ifpdf
\def\everbatimxprehook
{\pdfcolorstack\@pdfcolorstack push{0 1 0.5 0 k 0 1 0.5 0 K}\relax}
\def\everbatimxposthook
{\pdfcolorstack\@pdfcolorstack pop\relax}
\else
\ifxetex
\def\everbatimxprehook {\special{color push cmyk 0 1 0.5 0}}
\def\everbatimxposthook {\special{color pop}}
\else
\ifnum\Withdvipdfmx=1
\def\everbatimxprehook {\special{pdf:bcolor OrangeRed}}
\def\everbatimxposthook {\special{pdf:ecolor}}
\fi\fi\fi
% --- \everb
% Original was called \dverb and I did it in June 2013.
% Then after doing everbatim, I transformed \dverb, now called \everb
% for itself being as compatible as standard verbatim with list making
% surrounding environments.
% Supposed to be used as
% \everb|@ this will be ignored
% stuff
% escape character: "
% | not necessarily starting a line.
% I chose @ as comment character, mainly for pretty-formatting of the
% source, this can be changed by \everbhook.
% " comme caractère d'échappement. Par exemple pour colorier des parties.
\def\restoreeverbhook{\def\everbhook{%
\def\"{\begingroup\catcode123 1 \catcode 125 2 \everbescape }%
\catcode`\" 0 \catcode`\@ 14
}}\restoreeverbhook
\def\everbescape #1;!{#1\endgroup }
\def\everb {%
\bgroup
\let\everbatimhook\everbhook
\s@everbatim
\@everb
}
\def\@everb #1{\catcode`#1\active
\lccode`\~`#1%
\lowercase{\def~{\if@newlist \leavevmode\fi
\endtrivlist
\egroup
\@doendpe
\everbatimbottom }}%
}%
\catcode`_8
\makeatother
%--- \csa, \csbxint, \csh, \csbh
% dates back to earliest versions of this manual, but I changed things a bit
% (back then for example @ was active throughout the document...)
% The mark-up being in place, I only have to use it here.
\DeclareRobustCommand\csa [1]
{{\MicroFont\char92\endlinechar-1 \catcode`_ 11
\scantokens\expandafter{\detokenize{#1}}}}
\DeclareRobustCommand\csbnolk [1]
{{\MicroFont\char92\endlinechar-1 \scantokens\expandafter{\detokenize{#1}}}}
\DeclareRobustCommand\csbxint [1]
{\hyperref[\detokenize{xint#1}]%
{{\ttzfamily\char92\mbox{xint}\-\endlinechar-1 \makestarlowast
\scantokens\expandafter{\detokenize{#1}}}}}
\DeclareRobustCommand\csb [1]
{\hyperref[\detokenize{#1}]%
{{\ttzfamily\char92 \endlinechar-1 \makestarlowast
\scantokens\expandafter{\detokenize{#1}}}}}
\newcommand\csh[1]
{\texorpdfstring{\csa{#1}}{\textbackslash\detokenize{#1}}}
\newcommand\csbh[1]
{\texorpdfstring{\csbnolk{#1}}{\textbackslash\detokenize{#1}}}
% --- \xintname, \xintnameimp etc...
\xintForpair #1#2 in
{(xintkernel,kernel),
(xinttools,tools),
(xintcore,core),(xint,xint),(xintbinhex,binhex),(xintgcd,gcd),%
(xintfrac,frac),(xintseries,series),(xintcfrac,cfrac),(xintexpr,expr)}
\do
{%
\expandafter\def\csname #1name\endcsname
{\texorpdfstring
{\hyperref[sec:#2]%
{\relax{\color{joli}\ttzfamily #1}}}
{#1}%
\xspace }%
\expandafter\def\csname #1nameimp\endcsname
{\texorpdfstring
{\hyperref[sec:#2imp]%
{\relax{\color[named]{RoyalPurple}\ttzfamily #1}}}
{#1}%
\xspace }%
}%
%--- \printnumber
\catcode`_ 11
\makeatletter
\catcode`& 3
\def\allowsplits_a {\futurelet\printnumber_token\allowsplits_b }%
\def\allowsplits_b{\ifx\printnumber_token\@sptoken\space\fi\allowsplits_c }
\def\allowsplits_c #1{\ifx \xint_dothis\xint_gobble_i\fi
\if ,#1\xint_dothis {\discretionary{\rlap,}{}{,}}\fi
\xint_orthat{\discretionary
{\copy\SoftWrapIcon}%
{}%
{}#1}\allowsplits_a }%
\def\printnumber #1{\expandafter\allowsplits_a \romannumeral-`0#1&}%
\hyphenpenalty \z@
\catcode`& 4
\makeatother
\catcode`_ 8
%--- counts used in particular in the samples from the documentation of the
% xintseries.sty package
\newcount\cnta
\newcount\cntb
\newcount\cntc
%--- \fexpan 22 octobre 2013
\newcommand\fexpan {\textit{f}-expan}
\ifnum\dosourcexint=1
\else
% Dependency graph done using TikZ (manually)
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\fi
\colorlet {codeboxbg}{yellow!10}
\colorlet {codeboxframe}{black!30}
\colorlet {execboxfringe}{black!10}
\AtBeginDocument{%
\leftmargini \dimexpr4\fontcharwd\font`X\relax
\leftmarginii\dimexpr3\fontcharwd\font`X\relax
\leftmarginiii \leftmarginii
\leftmarginiv \leftmarginii
\parindent\dimexpr2\fontcharwd\font`X\relax
\leftmargin\leftmargini % pourquoi pas 0?
\edef\everbatimindent{\the\dimexpr\leftmargini\relax\space }%
\cftsubsecnumwidth 2\leftmarginii
\cftsubsubsecnumwidth 2\leftmargini
\cftsubsecindent 0pt
\cftsubsubsecindent \cftsubsecnumwidth
}%
\frenchspacing
\renewcommand\familydefault\sfdefault
% Septembre 2015
\def\liiibigint{\href{http://latex-project.org/svnroot/experimental/trunk/l3trial/l3bigint}{l3bigint}}
\makeatletter
\def\fixmeaning {\expandafter\fix@meaning\meaning}
\expandafter\edef\expandafter\fix@meaning
\expandafter #\expandafter1\string\romannumeral#2#3%
{#1\string\romannumeral`\string^\string^@}
\makeatother
\xintverbosetrue
\begin{document}\thispagestyle{empty}% \ttzfamily already done
\pdfbookmark[1]{Title page}{TOP}
% \makeatletter % @ n'est plus actif dans dtx 1.1, ouf!
{%
\normalfont\Large\parindent0pt \parfillskip 0pt\relax
\leftskip 2cm plus 1fil \rightskip 2cm plus 1fil
\ifnum\dosourcexint=1
The \xintnameimp source code\par
\else
The \xintname bundle\par
\fi
}
{\centering
\textsc{Jean-Fran\c cois Burnol}\par
\footnotesize
jfbu (at) free (dot) fr\par
Package version: \xintbndlversion\ (\xintbndldate);
documentation date: \xintdocdate.\par
{From source file \texttt{xint.dtx}. \xintdtxtimestamp.}\par
}
\bigskip
% Mercredi 08 octobre 2014 à 22:03:19
% Skips safely.
\ifnum\dosourcexint=1
\catcode`+ 0 \catcode0 9 % n'importe quoi sauf 15 (car ^^@)
\catcode`\\ 12
+expandafter+iffalse+fi
\fi
\etocsetlevel{toctobookmark}{6} % 9 octobre 2013, je fais des petits tricks.
\etocsettocdepth {subsection}
\renewcommand*{\etocbelowtocskip}{0pt}
\renewcommand*{\etocinnertopsep}{0pt}
\renewcommand*{\etoctoclineleaders}
{\hbox{\normalfont\normalsize\hbox to 1ex {\hss.\hss}}}
\etocmulticolstyle [1]{%
\phantomsection\section* {Contents}
\etoctoccontentsline*{toctobookmark}{Contents}{1}%
}
\etocsettagdepth {description}{subsection}
\etocsettagdepth {commands} {none}
\etocsettagdepth {implementation}{none}
\tableofcontents
\renewcommand*\etocabovetocskip{\bigskipamount}
\makeatletter
\etocmulticolstyle [2]{\parskip\z@skip\raggedcolumns
\setlength{\columnsep}{\leftmarginii}%
\setlength{\columnseprule}{0pt}%
}%
\makeatother
\etocsettagdepth {description}{none}
\etocsettagdepth {commands} {section}
\ifnum\NoSourceCode=1
\etocsettagdepth {implementation}{none}
\else
\etocsettagdepth {implementation}{section}
\fi
\tableofcontents
\etocignoredepthtags
\etocmulticolstyle [1]{%
\phantomsection% \section* {Contents}
\etoctoccontentsline*{toctobookmark}{Contents}{2}%
}
\inmanualmaintocfalse
\clearpage
% ----
% Fibonacci code
% December 7, 2013. Expandably computing a big Fibonacci number
% with the help of TeX+\numexpr+\xintexpr, (c) Jean-François Burnol
\catcode`_ 11
%
% ajouté 7 janvier 2014 au xint.dtx pour 1.07j.
%
% Le 17 janvier je me décide de simplifier l'algorithme car l'original ne tenait
% pas compte de la relation toujours vraie A=B+C dans les matrices symétriques
% utilisées en sous-main [[A,B],[B,C]].
%
% la version ici est celle avec les * omis: car multiplication tacite devant les
% sous-expressions depuis 1.09j, et aussi devant les parenthèses depuis 1.09k.
% (pour tester)
\def\Fibonacci #1{%
\expandafter\Fibonacci_a\expandafter
{\the\numexpr #1\expandafter}\expandafter
{\romannumeral0\xintiieval 1\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval 1\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval 1\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval 0\relax}}
%
\def\Fibonacci_a #1{%
\ifcase #1
\expandafter\Fibonacci_end_i
\or
\expandafter\Fibonacci_end_ii
\else
\ifodd #1
\expandafter\expandafter\expandafter\Fibonacci_b_ii
\else
\expandafter\expandafter\expandafter\Fibonacci_b_i
\fi
\fi {#1}%
}%
\def\Fibonacci_b_i #1#2#3{\expandafter\Fibonacci_a\expandafter
{\the\numexpr #1/2\expandafter}\expandafter
{\romannumeral0\xintiieval sqr(#2)+sqr(#3)\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval (2#2-#3)#3\relax}%
}% end of Fibonacci_b_i
\def\Fibonacci_b_ii #1#2#3#4#5{\expandafter\Fibonacci_a\expandafter
{\the\numexpr (#1-1)/2\expandafter}\expandafter
{\romannumeral0\xintiieval sqr(#2)+sqr(#3)\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval (2#2-#3)#3\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval #2#4+#3#5\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval #2#5+#3(#4-#5)\relax}%
}% end of Fibonacci_b_ii
\def\Fibonacci_end_i #1#2#3#4#5{\xintthe#5}
\def\Fibonacci_end_ii #1#2#3#4#5{\xinttheiiexpr #2#5+#3(#4-#5)\relax}
\catcode`_ 8
\def\Fibo #1.{\Fibonacci {#1}}
% nice background added for 1.09j release, January 7, 2014.
% superbe, non? moi très content!
\def\specialprintone #1%
{%
\ifx #1\relax \else \makebox[877496sp]{#1}\hskip 0pt plus 2sp\relax
\expandafter\specialprintone\fi
}%
\def\specialprintnumber #1% first ``fully'' expands its argument.
{\expandafter\specialprintone \romannumeral-`0#1\relax }%
\AddToShipoutPicture*{%
\put(10.5cm,14.85cm)
{\makebox(0,0)
{\resizebox{17cm}{!}{\vbox
{\hsize 8cm\Huge\baselineskip.8\baselineskip\color{black!10}%
\specialprintnumber{F(1250)=}%
\specialprintnumber{\Fibonacci{1250}}}\par}%
}%
}%
}
% Samedi 27 septembre 2014 à 16:04:52
\pdfbookmark[1]{Dependency graph}{DependencyGraph}
\tikzstyle{block} = [rectangle, draw,
fill=codeboxbg,
fill opacity=0.5,% fill opacity Octobre 2014
draw=codeboxframe,
line width=2pt,
text width=6em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, line width=1pt, color=codeboxframe]
\vspace*{\stretch{0.3333}}
\begin{figure}[ht!]
\phantomsection\label{dependencygraph}
\centeredline{%
\begin{tikzpicture}[node distance = 2.5cm]
% Place nodes
\node [block] (kernel) {xintkernel};
\node [left of=kernel] (A) {};
\node [right of=kernel] (B) {};
\node [block, below right of=B] (core) {\xintcorename};
\node [block, below left of=A] (tools) {\xinttoolsname};
\node [block, right of=core, xshift=1cm] (bnumexpr) {\href{http://www.ctan.org/pkg/bnumexpr}{bnumexpr}};
\node [block, below of=core] (xint) {\xintname};
\node [block, left of=xint, xshift=-.5cm] (binhex) {\xintbinhexname};
\node [block, left of=binhex] (gcd) {\xintgcdname};
\node [block, below of=xint] (frac) {\xintfracname};
\node [block, below of=frac, yshift=-.5cm] (expr) {\xintexprname};
\node [block, below right of=frac, xshift=1cm] (cfrac) {\xintcfracname};
\node [block, right of=cfrac] (series) {\xintseriesname};
% Draw edges
\path [line] (kernel) -- (core);
\path [line] (kernel) -- (tools);
\path [line] (core) -- (bnumexpr);
\path [line] (core) -- (gcd.north);
\path [line] (core) -- (binhex.north);
\path [line] (core) -- (xint);
\path [line] (xint) -- (frac);
\path [line] (frac) -- (expr);
\path [line] (frac) -- (series.north);
\path [line] (frac) -- (cfrac.north);
\path [line,dashed] (binhex.south) -- (expr);
\path [line,dashed] (gcd.south) -- (expr);
\path [line,dashed] (tools) -- (gcd);
\path [line,dashed] (tools) to [out=270,in=180] (frac);
\path [line] (tools) to [out=270,in=180] (expr);
\end{tikzpicture}}\bigskip
\end{figure}
\vspace{2\baselineskip}
\begin{addmargin}{2cm}
\normalfont\footnotesize Dependency graph for the
\xintname bundle components: modules at the bottom import modules at the
top when connected by a continuous line. No module will be loaded twice,
this is managed internally under Plain as well as \LaTeX. Dashed lines
indicate a partial dependency, and to enable the corresponding
functionalities of the lower module it is necessary for the user to issue
the suitable |\usepackage{top_module}| in the
preamble (or |\input top_module.sty\relax| in Plain
\TeX). The \href{http://ctan.org/pkg/bnumexpr}{bnumexpr} package is a
separate package (\LaTeX{} only) by the author.\par
\end{addmargin}
\vfill
\clearpage
\etocdepthtag.toc {description}
\section{Read this first}\label{sec:quickintro}
This section provides recommended reading on first discovering the package.
\begin{addmargin}{1cm}
\makeatletter
\renewenvironment{description}
{\list{}{\topsep\baselineskip\partopsep\z@skip
\parsep\z@ \labelwidth\z@ \itemindent-\leftmargin
\let\makelabel\descriptionlabel}}
{\endlist}
\makeatother
%\noindent\null\par\kern-\baselineskip
\leavevmode
\begin{description}
\item[\xinttoolsname] provides utilities of independent interest such as
expandable and non-expandable loops. It is \fbox{not}
loaded automatically (nor needed) by the other bundle
packages, apart from \xintexprname.
\item[\xintcorename] provides the
expandable \TeX{} macros doing additions, subtractions, multiplications,
divisions, and powers on arbitrarily long numbers (loaded automatically by
\xintname, and also by package \href{http://ctan.org/pkg/bnumexpr}{bnumexpr}
in its default configuration).
\item[\xintname] extends \xintcorename with additional operations on big
integers. Loads automatically \xintcorename.
\item[\xintfracname] extends the scope of \xintname to decimal numbers, to
numbers in scientific notation and also to fractions with arbitrarily
long such numerators and denominators separated by a forward slash. Loads
automatically \xintname.
\item[\xintexprname] extends \xintfracname with expandable parsers doing
algebra (exact, float, or limited to integers) on comma separated
expressions using standard infix notations with parentheses, numbers in
decimal notation, scientific notation, comparison operators, Boolean logic,
twofold and threefold way conditionals, sub-expressions, some functions with
one or many arguments, user-definable variables, user-definable functions,
nestable use of dummy variables for evaluation of sub-expressions, with
iterations admitting omit, abort, and break instructions.
Automatically loads \xinttoolsname and \xintfracname (hence \xintname and
\xintcorename too).
\end{description}
Further modules:
\begin{description}
\item[\xintbinhexname] is for conversions to and from binary and
hexadecimal bases.
\item[\xintseriesname] provides some basic functionality for computing in an
expandable manner partial sums of series and power series with fractional
coefficients.
\item[\xintgcdname] implements the Euclidean algorithm and its typesetting.
\item[\xintcfracname] deals with the computation of continued fractions.
\end{description}
\end{addmargin}
\begin{framed}
All macros from the \xintname packages doing computations are
\emph{expandable}, and naturally also the parsers provided by \xintexprname.
The reasonable range of use of the package arithmetics is with numbers of
\emph{up to a few hundred digits.}
% Release |1.2|
% has significantly improved the speed of the basic operations for numbers
% with more than $50$ digits, the speed gains getting better for bigger
% numbers.
Although numbers up to about \dtt{19950} digits are acceptable
inputs, the package is not at his peak efficiency when confronted with such
really big numbers having thousands of digits.\footnotemark
\end{framed}
\footnotetext{The maximal handled size for inputs to multiplication is
\dtt{19959} digits. This limit is observed with the current default values
of some parameters of the tex executable (input save stack size at 5000,
maximal expansion depth at 10000). Nesting of macros will reduce it and it
is best to restrain numbers to at most \dtt{19900} digits. The output, as
naturally is the case with multiplication, may exceed the bound.}
\subsection{First examples}
With |\usepackage{xintexpr}| if using \LaTeX, or |\input xintexpr.sty\relax|
for other formats, you can do computations such as the following.
\begin{description}
\item[with floats:]\leavevmode\par
\begin{everbatim*}
\thexintfloatexpr 3.25^100/3.2^100, 2^1000000, sqrt(1000!), 10^-3.5\relax
\end{everbatim*}
\item[with fractions:]\leavevmode\par
\begin{everbatim*}
\thexintexpr reduce(add((-1)^(i-1)/i**2, i=1..25))\relax
\end{everbatim*}
\item[with integers:]\leavevmode\par
\begin{everbatim*}
\thexintiiexpr 3^159+2^234\relax
\end{everbatim*}
\end{description}
Float computations are done by default with \dtt{16} digits of precision.
This can be changed by a prior assignment to |\xintDigits|:
\begin{everbatim*}
% use braces (or a LaTeX environment) to limit the scope of the \xintDigits assignment
{\xintDigits := 88;\thexintfloatexpr 3.25^100-3.2^100\relax}\par
\end{everbatim*}
We can even try daring things:\footnote{The \cs{printnumber} is not part of
the package, see \autoref{ssec:printnumber}.}
\begin{everbatim*}
{\xintDigits:=500;\printnumber{\thexintfloatexpr sqrt(2)\relax}}
\end{everbatim*}
\medskip
This is release \expandafter|\xintbndlversion|.
\begin{enumerate}
\item |exp|, |cos|, |sin|, etc... are \emph{yet to be implemented},
\item |NaN|, |+Infty|, |-Infty|, etc... are \emph{yet to be implemented},
\item powers work currently only with integral \emph{or also
half-integral\NewWith{1.2f}} exponents (but the latter only for float
expressions),
\item \xintname can handle numbers with thousands of digits, but execution
times limit the practical range to a few hundreds (if many such computations
are needed),
\item computations in |\thexintexpr| and |\thexintiiexpr| are exact (except if
using |sqrt|, naturally),
\item fractions are not systematically reduced to smallest terms, use
|reduce| function,
\item for producing fixed point numbers with |d| digits after decimal mark,
use (note the extra `|i|' in the parser name!) |\thexintiexpr [d]
...\relax|. This is actually essentially synonymous with |\thexintexpr
round(..,d)\relax| (for |d=0|, |\thexintiexpr [0]| is the same as
|\thexintiexpr| without optional argument, and is like |\thexintexpr
round(..)\relax|). If truncation rather than rounding is needed use thus
|\thexintexpr trunc(..,d)\relax| (and |\thexintexpr trunc(..)\relax| for
truncation to integers),
\item all three parsers allow some constructs with dummy variables as seen
above; it is possible to define new functions or to declare variables for
use in upcoming computations,
\item |\thexintiiexpr| is slightly faster than |\thexintexpr|, but usually one
can use the latter with no significant time penalty also for integer-only
computations.
\end{enumerate}
All operations executed by the parsers are based on underlying macros from
packages \xintfracname and \xintname which are loaded automatically by
\xintexprname. With extra packages \xintbinhexname and \xintgcdname the
parsers can handle hexadecimal notation on input (even fractional) and compute
|gcd|'s or |lcm|'s of integers.
All macros doing computations ultimately rely on (and reduce to) the
|\numexpr| primitive from \eTeX{}. These \eTeX{} extensions date back to 1999
and are by default incorporated into the |pdftex| etc... executables from
major modern \TeX{} installations since more than ten years now. Only the
|tex| binary does not benefit from them, as it has to remain the original
\textsc{D.~Knuth}'s software, but one can then use |etex| on the command line.
PDF\TeX\ (in pdf or dvi output mode), Lua\TeX, Xe\TeX\ all include the \eTeX\
extensions.
\subsection{Quick overview (expressions with \xintexprname)}
This section gives a first few examples of using the expression parsers which
are provided by package \xintexprname. Loading \xintexprname automatically also
loads packages \xinttoolsname and \xintfracname. The latter loads \xintname
which loads \xintcorename. All three provide the macros which ultimately do the
computations associated in expressions with the various symbols like |+, *, ^,
!| and functions such as |max, sqrt, gcd| (the latter requires
explicit loading of \xintgcdname). The package
\xinttoolsname does not handle computations but provides some useful utilities.
\begin{framed}
Release |1.2h| defines |\thexintexpr| as synonym to |\xinttheexpr|,
|\thexintfloatexpr| as synonym of |\xintthefloatexpr|, etc...
\end{framed}
There are three expression parsers and two subsidiary ones. They
all admit comma separated expressions, and will then output a comma
separated list of results.
\begin{itemize}[nosep]
\item \csbxint{theiiexpr}| ... \relax| does exact computations \emph{only on
integers.} The forward slash \dtt{/} does the rounded integer division
(\dtt{//} does truncated division, and \dtt{/:} is the associated modulo).
There are two square root extractors \dtt{sqrt} and \dtt{sqrtr} for
truncated and rounded square roots. Scientific notation |6.02e23| is
\emph{not} accepted on input, one needs to wrap it as |num(6.02e23)| which
will convert to an integer notation \dtt{\printnumber{\xinttheiiexpr
num(6.02e23)\relax}}.
\item \csbxint{thefloatexpr}| ... \relax| does computations with a given
precision \dtt{P}, as specified via a prior assignment |\xintDigits:=P;|.
The default is \dtt{P=16} digits. An optional argument controls the
precision for \emph{formatting the output} (this is not the precision of the
computations themselves). The four basic operations and the square root
realize \emph{correct rounding.}\footnote{when the inputs are already
floating point numbers with at most |P|-digits mantissas.}
\item \csbxint{theexpr}| ... \relax| handles integers, decimal numbers,
numbers in scientific notation and fractions. The algebraic computations are
done \emph{exactly.} The |sqrt| function is available and works
according to the |\xintDigits| precision or according to its second optional
argument.
\end{itemize}
\begin{framed}
Currently, the sole available non-algebraic function is the square root
extraction \dtt{sqrt}. It is allowed in |\xintexpr..\relax| but naturally
can't return an \emph{exact} value, hence computes as if it was in
|\xintfloatexpr..\relax|. The power operator |^| (equivalently |**|) works
with integral exponents only in \csbxint{iiexpr} (non-negative) and
\csbxint{expr} (negative exponents allowed, of course) and also with
half-integral exponents in \csbxint{floatexpr} (it proceeds via an integral
power followed by a square-root extraction).
\end{framed}
Two derived parsers:
\begin{itemize}[nosep]
\item \csbxint{theiexpr}| ... \relax| does all computations like |\xinttheexpr
... \relax| but rounds the result to the nearest integer. With an optional
positive argument |[D]|, the rounding is to the nearest fixed point number
with |D| digits after the decimal mark.
\item \csbxint{theboolexpr}| ... \relax| does all computations like
|\xinttheexpr ... \relax| but converts the result to $1$ if it is not zero
(works also on comma separated expressions).
See also the booleans \csbxint{ifboolexpr}, \csbxint{ifbooliiexpr},
\csbxint{ifboolfloatexpr} (which do not handle comma separated expressions).
\end{itemize}
Here is a (partial) list of the recognized symbols:
\begin{itemize}[nosep]
\item the comma (to separate distinct computations or arguments to a
function),
\item parentheses,
\item infix operators |+|, |-|, |*|, |/|, |^| (or |**|),
% \item |//| and |/:| only in \csbxint{iiexpr}|..\relax|,
\item branching operators |(x)?{x non zero}{x zero}|, |(x)??{x<0}{x=0}{x>0}|,
\item boolean operators |!|, |&&| or |'and'|, \verb+||+ or |'or'|,
\item comparison operators |=| (or |==|), |<|, |>|, |<=|, |>=|, |!=|,
\item factorial post-fix operator |!|,
\item |"| for hexadecimal input (uppercase only; package \xintbinhexname
must be loaded additionally to \xintexprname),
%\item |'| for octal input (\emph{not yet}),
\item functions \xintFor #1 in {num, reduce, abs, sgn, frac, floor, ceil, sqr, sqrt,
sqrtr, float, round, trunc, mod, quo, rem, gcd, lcm,
max, min, |`+`|, |`*`|, not, all, any, xor, if, ifsgn, even, odd, first,
last, reversed, bool, togl, factorial, binomial, pfactorial}\do {\dtt{#1}, }
\item functions with dummy variables \xintFor #1 in {add, mul, seq, subs,
rseq, iter, rrseq, iterr}\do {\dtt{#1}\xintifForLast{.}{, }}
\end{itemize}
See \autoref{sec:xintexprsyntax} (and \autoref{ssec:syntax}) for the complete
syntax, as well as \autoref{ssec:moredummies} which contains examples
illustrating further some features which were added at the time of release
|1.1 2014/10/28|.
The normal mode of operation of the parsers is to unveil the parsed material
token by token. This means that all elements may arise from expansion of
encountered macros (or active characters). For example a closing parenthesis
does not have to be immediately visible, it may arise later from expansion.
This general behavior has exceptions, in particular constructs with dummy
variables need immediately visible balanced parentheses and commas. The
expansion stops only when the ending |\relax| has been found; it is then removed
from the token stream, and the final computation result is inserted.
Release |1.2| added the (pseudo) functions \dtt{qint}, \dtt{qfrac},
\dtt{qfloat} to allow swallowing in one-go all digits of a big number,
fraction, or float, skipping the token by token expansion.
\medskip
Here is an example of a computation:
\begin{everbatim*}
\xinttheexpr (31.567^2 - 21.56*52)^3/13.52^5\relax
\end{everbatim*}\newline
This illustrates that
|\xinttheexpr..\relax| does its computations \emph{exactly}. The same example
as a floating point evaluation:
\begin{everbatim*}
\xintthefloatexpr (31.567^2 - 21.56*52)^3/13.52^5\relax
\end{everbatim*}
Again, all computations done by |\xinttheexpr..\relax| are completely exact.
Thus, very quickly very big numbers are created (and computation times
increase, not to say explode if one goes into handling numbers with thousands
of digits). To compute something like |1.23456789^10000| it is thus better to
opt for the floating point version:
\begin{everbatim*}
\xintthefloatexpr 1.23456789^10000\relax
\end{everbatim*}
\newline
(we can deduce that the exact value has |80000+916=80916| digits).
A bigger example (the scope of
the assignment to |\xintDigits| is limited by the braces):
\begin{everbatim*}
{\xintDigits:=24; \xintthefloatexpr 1.23456789123456789^123456789\relax }
\end{everbatim*}
(<- notice the size of the power of ten: this surely largely exceeds your pocket
calculator abilities).
It is also possible to do some computer algebra like
evaluations (only numerically though):
\begin{everbatim*}
\xinttheiiexpr add(i^5, i=100..200)\relax\par
\noindent\xinttheexpr reduce(add(x/(x+1), x = 1000..1014))\relax
\end{everbatim*}
\newline Were it not for the \dtt{reduce} function, the latter fraction would
not have been obtained in reduced terms:
\begin{framed}
By default, the basic operations on fractions are not followed in an
automatic manner by reduction to smallest terms: |A/B| multiplied by |C/D|
returns |AC/BD|, |A/B| added to |C/D| returns |(AD+BC)/BD| except if either
|B| divides |D| or |D| divides |B|.
\end{framed}
Make sure to read \autoref{ssec:userinterface}, \autoref{sec:xintexprsyntax}
and also \autoref{sec:expr}.
\subsection{Printing big numbers on the page}\label{ssec:printnumber}
When producing very long numbers there is the question of printing them on
the page, without going beyond the page limits. In this document, I have most
of the time made use of these macros (not provided by the package:)
%
\everb|@
\def\allowsplits #1{\ifx #1\relax \else #1\hskip 0pt plus 1pt\relax
\expandafter\allowsplits\fi}%
\def\printnumber #1{\expandafter\allowsplits \romannumeral-`0#1\relax }%
% \printnumber thus first ``fully'' expands its argument.
|
It may be used like this:
%
\leftedline{|\printnumber {\xintiiQuo{\xintiiPow {2}{1000}}{\xintiFac{100}}}|}
%
or as |\printnumber\mybiginteger| or |\printnumber{\mybiginteger}| if
|\mybiginteger| was previously defined via a |\newcommand|, a |\def| or
an |\edef|.
An alternative is to suitably configure the thousand
separator with the \href{http://ctan.org/pkg/numprint}{numprint} package
(see \autoref{fn:np}. This will not allow linebreaks when used in math
mode; I also tried \href{http://ctan.org/pkg/siunitx}{siunitx} but even
in text mode could not get it to break numbers accross lines). Recently
I became aware of the \href{http://ctan.org/pkg/seqsplit}{seqsplit}
package%
%
\footnote{\url{http://ctan.org/pkg/seqsplit}}
%
which can be used to achieve this splitting accross lines, and does work
in inline math mode (however it doesn't allow to separate digits by
groups of three, for example).\par
\subsection{Randomly chosen examples}
Here are some examples of use of the package macros. The first one uses only
the base module \xintname, the next one requires the \xintfracname package,
which deals with decimal numbers, scientific numbers (lowercase \dtt{e}), and
also fractions (it loads automatically \xintname). Then some examples with
expressions, which require the \xintexprname package (it loads automatically
\xintfracname). And finally some examples using \xintseriesname, \xintgcdname
which are among the extra packages included in the \xintname distribution.
The printing of the outputs will either use a custom |\printnumber| macro as
described in the previous section, or sometimes the |\np| command from the
\href{http://www.ctan.org/pkg/numprint}{numprint} package (see
\autoref{fn:np}).
\begin{itemize}
\item {$123456^{99}$: }\\
|\xintiiPow {123456}{99}|:
\dtt{\printnumber{\xintiiPow {123456}{99}}}
\item {1234/56789 with 1500 digits after the decimal point: }\\
|\xintTrunc {1500}{1234/56789}\dots|:
\dtt{\printnumber {\xintTrunc {1500}{1234/56789}}\dots }
\item {$0.99^{-100}$ with 200 (+1) digits after the decimal point.}\\
|\xinttheiexpr [201] .99^-100\relax|:
\dtt{\printnumber{\xinttheiexpr [201] .99^-100\relax}}\\
Notice that this is rounded, hence we asked |\xinttheiexpr| for one
additional digit. To get a truncated result with 200 digits after the decimal
mark, we should have issued
|\xinttheexpr trunc(.99^-100,200)\relax|, rather.
\begin{snugframed}
The fraction |0.99^-100|'s denominator is first evaluated \emph{exactly}
(\emph{i.e.} the integer |99^100| is evaluated exactly and then used to
divide the suitable power of ten to get the requested digits); for
some longer inputs, such as for example |0.7123045678952^-243|, the
exact evaluation before truncation would be costly, and it is more efficient
to use floating point numbers:
%
\leftedline{|\xintDigits:=20;
\np{\xintthefloatexpr .7123045678952^-243\relax}|}%
%
\leftedline{\xintDigits:=20;\dtt{\np{\xintthefloatexpr .7123045678952^-243\relax }}}
%
\xintDigits:=16;%
%
Side note: the exponent |-243| didn't have to be put inside parentheses,
contrarily to what happens with some professional computational
software. |;-)|
% 6.342,022,117,488,416,127,3 10^35
% maple n'aime pas ^-243 il veut les parenthèses, bon et il donne, en Digits
% = 24: 0.634202211748841612732270 10^36
\end{snugframed}
\item {$200!$:}\\
|\xinttheiiexpr 200!\relax|:
\dtt{\printnumber{\xinttheiiexpr 200!\relax}}
\item {$2000!$ as a float. As \xintexprname does not handle |exp/log| so far,
the computation is done internally without the Stirling formula,
by repeated multiplications truncated suitably:}\\
|\xintDigits:=50;|\newline |\xintthefloatexpr 2000!\relax|:
{\xintDigits:=50;\dtt{\printnumber{\xintthefloatexpr 2000!\relax}}}
\item Just to show off (again), let's print 300 digits (after the decimal
point) of the decimal expansion of $0.7^{-25}$:%
%
\footnote{the |\np| typesetting macro is from the |numprint| package.}
%
\begin{everbatim*}
% % in the preamble:
% \usepackage[english]{babel}
% \usepackage[autolanguage,np]{numprint}
% \npthousandsep{,\hskip 1pt plus .5pt minus .5pt}
% \usepackage{xintexpr}
% in the body:
\np {\xinttheexpr trunc(.7^-25,300)\relax}\dots
\end{everbatim*}
This computation is with \csbxint{theexpr} from package \xintexprname, which
allows to use standard infix notations and function names to access the package
macros, such as here |trunc| which corresponds to the \xintfracname macro
\csbxint{Trunc}. Regarding this computation, please keep in mind that
\csbxint{theexpr} computes \emph{exactly} the result before truncating. As
powers with fractions lead quickly to very big ones, it is good to know that
\xintexprname also provides \csbxint{thefloatexpr} which does computations
with floating point numbers.
\item Computation of a Bezout identity with |7^200-3^200| and |2^200-1|:
(with \xintgcdname)\par
\everb|@
\xintAssign \xintBezout {\xinttheiiexpr 7^200-3^200\relax}
{\xinttheiiexpr 2^200-1\relax}\to\A\B\U\V\D
$\U\times(7^{200}-3^{200})+\xintiOpp\V\times(2^{200}-1)=\D$
|
\xintAssign \xintBezout {\xinttheiiexpr 7^200-3^200\relax}%
{\xinttheiiexpr 2^200-1\relax}\to\A\B\U\V\D
\dtt
{\printnumber\U$\times(7^{200}-3^{200})+{}$%
\printnumber{\xintiOpp\V}$\times(2^{200}-1)={}$\printnumber\D}
\item The Euclide algorithm applied to \np{22206980239027589097} and
\np{8169486210102119257}: (with \xintgcdname)%
%
\footnote {this example is computed tremendously faster than the other
ones, but we had to limit the space taken by the output hence picked
up rather small big integers as input.}\par
\noindent\begingroup\parskip0pt\relax
|\xintTypesetEuclideAlgorithm {22206980239027589097}{8169486210102119257}|\par
\dtt
{\xintTypesetEuclideAlgorithm {22206980239027589097}{8169486210102119257}}
\endgroup
\smallskip
\item $\sum_{n=1}^{500} (4n^2 - 9)^{-2}$ with each term rounded to twelve digits,
and the sum to nine digits:
\begin{everbatim*}
\def\coeff #1{\xintiRound {12}{1/\xintiiSqr{\the\numexpr 4*#1*#1-9\relax }[0]}}
\xintRound {9}{\xintiSeries {1}{500}{\coeff}[-12]}
\end{everbatim*}
The complete series, extended to
infinity, has value
$\frac{\pi^2}{144}-\frac1{162}={}$%
\dtt{\np{0.06236607994583659534684445}\dots}\,%
%
\footnote{\label{fn:np}This number is typeset using the
\href{http://www.ctan.org/pkg/numprint}{numprint} package, with
|\npthousandsep{,\hskip 1pt plus .5pt minus .5pt}|. But the breaking
across lines works only in text mode. The number itself was (of
course...) computed initially with \xintname, with 30 digits of $\pi$
as input. See \hyperref[ssec:Machin]{{how {\xintname} may compute
$\pi$ from scratch}}.}
%
I also used (this is a lengthier computation
than the one above) \xintseriesname to evaluate the sum with \np{100000} terms,
obtaining 16
correct decimal digits for the complete sum. The
coefficient macro must be redefined to avoid a |\numexpr| overflow, as
|\numexpr| inputs must not exceed $2^{31}-1$; my choice
was:
\everb|@
\def\coeff #1%
{\xintiRound {22}{1/\xintiiSqr{\xintiiMul{\the\numexpr 2*#1-3\relax}
{\the\numexpr 2*#1+3\relax}}[0]}}
|
\restoreMacroFont
\edef\Temp {\xintFloatPow [24]{2}{999999999}}
\item {Computation of $2^{\np{999999999}}$ with |24| significant
figures:}
%
\leftedline{|\numprint{\xintFloatPow [24]{2}{999999999}}|}
\leftedline{\dtt{\numprint{\Temp}}}
%
where the \href{http://www.ctan.org/pkg/numprint}{numprint} package was used
(\autoref{fn:np}), directly in text mode (it can also naturally be used from
inside math mode). \xintname provides a simple-minded \csbxint{Frac}
typesetting macro,%
%
\footnote{Plain \TeX{} users of \xintname have \csbxint{FwOver}.}
%
which is math-mode only:
%
\leftedline{|$\xintFrac{\xintFloatPow [24]{2}{999999999}}$|}
\leftedline{\dtt{$\xintFrac{\Temp}$}}
%
The exponent differs, but this is because
|\xintFrac| does not use a decimal mark in the significand of the output.
Admittedly most users will have the need of more powerful (and customizable)
number formatting macros than |\xintFrac|.
%
\footnote{There should be a |\xintFloatFrac|, but it is lacking.}
%
We have already mentioned
|\numprint| which is used above, there is also |\num| from package
\href{http://www.ctan.org/pkg/siunitx}{siunitx}. The raw output from
%
\leftedline{\detokenize{\xintFloatPow[24]{2}{999999999}}}
%
is $\Temp$.
\edef\x{\xintiiQuo{\xintiiPow {2}{1000}}{\xintiFac{100}}}
\edef\y{\xintLen{\x}}
\item As an example of nesting package macros, let us consider the following
code snippet within a file with filename |myfile.tex|:
\everb|@
\newwrite\outstream
\immediate\openout\outstream \jobname-out\relax
\immediate\write\outstream {\xintiiQuo{\xintiiPow{2}{1000}}{\xintiFac{100}}}
% \immediate\closeout\outstream
|
\noindent
The tex run creates a file |myfile-out.tex|, and then writes to it the
quotient from the euclidean division of $2^{1000}$ by $100!$. The number of
digits is |\xintLen{\xintiiQuo{\xintiiPow{2}{1000}}{\xintiFac{100}}}| which
expands (in two steps) and tells us that $[2^{1000}/100!]$ has \dtt{\y}
digits. This is not so many, let us print them here:
\dtt{\printnumber\x}.%
\end{itemize}
\subsection {More examples, some quite elaborate, within this document}
\label{sec:awesome}
\begin{itemize}
\item The utilities provided by \xinttoolsname (\autoref{sec:tools}), some
completely expandable, others not, are of independent interest. Their use
is illustrated through various examples: among those, it is shown in
\autoref{ssec:quicksort} how to implement in a completely expandable way
the \hyperref[ssec:quicksort]{Quick Sort algorithm} and also how to illustrate
it graphically. Other examples include some dynamically constructed
alignments with automatically computed prime number cells: one using a
completely expandable prime test and \csbxint{ApplyUnbraced}
(\autoref{ssec:primesI}), another one with \csbxint{For*} (\autoref{ssec:primesIII}).
\item One has also a \hyperref[edefprimes]{computation of primes within an
\csa{edef}} (\autoref{xintiloop}), with the help of \csbxint{iloop}.
Also with \csbxint{iloop} an
\hyperref[ssec:factorizationtable]{automatically generated table of
factorizations} (\autoref{ssec:factorizationtable}).
\item The code for the title page fun with Fibonacci numbers is given in
\autoref{ssec:fibonacci} with \csbxint{For*} joining the game.
\item The computations of \hyperref[ssec:Machin]{ $\pi$ and $\log 2$}
(\autoref{ssec:Machin}) using \xintname and the computation of the
\hyperref[ssec:e-convergents]{convergents of $e$} with the further help of
the \xintcfracname package are among further examples.
\item Also included,
an \hyperlink{BrentSalamin}{expandable implementation of the Brent-Salamin
algorithm} for evaluating $\pi$.
\item There is also an
example of an \hyperref[xintXTrunc]{interactive session}, where results
are output to the log or to a file.
\item The functionalities of \xintexprname are illustrated with various
examples, and in locations such as in \autoref{xintdeffunc} and
\autoref{ssec:dummies}.
\end{itemize}
Almost all of the computational results interspersed throughout the
documentation are not hard-coded in the source file of this document but are
obtained via the expansion of the package macros during the \TeX{}
run.%
%
\footnote{The CPU of my computer hates me for all those re-compilations
after changing a single letter in the \LaTeX{} source, which require each
time to do all the zillions of evaluations contained in this document\dots}
\subsection{Installation instructions}
\label{ssec:install}
\xintname is made available under the
\href{http://www.latex-project.org/lppl/lppl-1-3c.txt}{LaTeX Project Public
License 1.3c}. It is included in the major \TeX\ distributions, thus there
is probably no need for a custom install: just use the package manager to
update if necessary \xintname to the latest version available.
After installation, issuing in terminal |texdoc --list xint|, on installations
with a |"texdoc"| or similar utility, will offer the choice to display one of
the documentation files: |xint.pdf| (this file), |sourcexint.pdf| (source
code), |README|, |README.pdf|, |README.html|, |CHANGES.pdf|, and
|CHANGES.html|.
For manual installation, follow the instructions from the |README| file which
is to be found on \href{http://www.ctan.org/pkg/xint}{CTAN}; it is also
available there in PDF and HTML formats. The simplest method proposed is to
use the archive file \href{http://www.ctan.org/pkg/xint}{xint.tds.zip},
downloadable from the same location.
The next simplest one is to make use of the |Makefile|, which is also
downloadable from
\href{http://mirror.ctan.org/macros/generic/xint}{CTAN}. This is
for GNU/Linux systems and Mac OS X, and necessitates use of the command
line. If for some reason you have |xint.dtx| but no internet access,
you can recreate |Makefile| as a file with this name and the following
contents:
{\def\everbatimindent {0pt }%
\begin{everbatim}
include Makefile.mk
Makefile.mk: xint.dtx ; etex xint.dtx
\end{everbatim}}
Then run |make| in a working repertory where there is |xint.dtx| and the file
named |Makefile| and having only the two lines above. The |make| will extract
the package files from |xint.dtx| and display some further instructions.
If you have |xint.dtx|, no internet access and can not use the Makefile
method: |etex xint.dtx| extracts all files and among them the |README| as a
file with name |README.md|. Further help and options will be found therein.
\subsection {Changes}
The detailed cumulative change log since the initial release is in files
|CHANGES.html| (also available on \href{http://ctan.org}{CTAN} via
\href{http://mirrors.ctan.org/macros/generic/xint/CHANGES.html}{this link})
and |CHANGES.pdf|.
In a command line console, issue |texdoc --list xint| to access them.
It is also possible to extract them from the source |xint.dtx|: |etex
xint.dtx| in a working repertory which will extract a |CHANGES.md| file with
Markdown syntax. On a unix-like system you can then run |make -f Makefile.mk
CHANGES.html| to get the |html| version (requires |pandoc|).
The last major release is |1.2 (2015/10/10)|. It came with a complete rewrite
of the core arithmetic routines. The efficiency for numbers with less than
$20$ or $30$ digits was slightly compromised (for addition/subtraction) but it
got increased for bigger numbers. For multiplication and division the gains were
there for almost all sizes, and became quite noticeable for numbers with
hundreds of digits. The allowable inputs are constrained to have less than
about $19950$ digits ($19968$ for addition, $19959$ for multiplication).
Among subsequent evolution, we mention here some changes with |1.2f
(2016/03/12)| regarding floating point numbers:
\begin{enumerate}[noitemsep]
\item functions |factorial|, |binomial|, |pfactorial|.
\item more precise discussion of floating point issues in
\autoref{ssec:floatingpoint}, but the coverage by
\xintfracname of floating point operations is yet to be substantially
extended.
\item the float macros for addition, subtraction, multiplication, division
now first round their two operands to P significant places
(not P+2 as earlier) before doing the actual computation (P is the asked
for precision or \csbxint{theDigits}). The same applies to the float power
and square root operations.
\item \csbxint{FloatSqrt} achieves \emph{correct rounding} in
arbitrary precision.
\end{enumerate}
\section{The syntax of \xintexprname expressions}
\label{sec:xintexprsyntax}
\localtableofcontents
\subsection{Infix and other operators and their precedence levels}
% \ctexttt is a remnant of 1.09n manual, don't have time to get rid of it now.
\newcommand\ctexttt [1]{\begingroup\color[named]{DarkOrchid}%\bfseries
#1\endgroup}
We go through the various syntax elements from highest to lowest precedence.
\begin{itemize}[parsep=0pt, labelwidth=\leftmarginii,
itemindent=0pt, listparindent=\leftmarginiii,
leftmargin=\leftmarginii]
\item Functions share the highest precedence.
\item \def\MicroFont{\color[named]{DarkOrchid}\ttfamily}The
|.| as decimal mark; the number scanner treats it as an inherent,
optional and unique component of a being formed number. One can do
things such as
%
\leftedline{\restoreMicroFont|\xinttheexpr 0.^2+2^.0\relax|}
%
which is |0^2+2^0| and produces \dtt{\xinttheexpr 0.^2+2^.0\relax}.
However a single dot |"."| as in |\xinttheexpr .^2\relax| is now illegal
input.\IMPORTANT
\item The |e| and |E| for scientific notation. They are parsed
like the decimal mark is.
\begingroup
\restoreMicroFont |1e3^2| is \dtt{\xinttheexpr 1e3^2\relax}
\endgroup
\item The |"| for hexadecimal numbers: it is treated with highest
priority, allowed only at locations where the parser expects to start
forming a numeric operand, once encountered it triggers the
hexadecimal scanner which looks for successive hexadecimal digits (as
usual skipping spaces and expanding forward everything; letters |A|, ..., |F|,
but not |a|, ..., |f|) possibly a
unique optional dot (allowed directly in front) and then an optional
(possibly empty) fractional part. The dot and fractional part are not
allowed in {\restoreMicroFont|\xintiiexpr..\relax|}. The |"|
functionality \fbox{requires package \xintbinhexname} (there is
no warning, but an ``undefined control sequence'' error will
naturally results if the package has not been loaded).
\begingroup
\restoreMicroFont |"A*"A^"A| is \dtt{\xinttheexpr "A*"A^"A\relax}.
\endgroup
\item The postfix operators \ctexttt{!} and the branching conditionals \ctexttt{?, ??}.
\begin{description}
\item[{\color[named]{DarkOrchid}!}] computes the factorial of an integer.
\item[{\color[named]{DarkOrchid}?}] is used as |(cond)?{yes}{no}|. It
evaluates the (numerical) condition (any non-zero value counts as
|true|, zero counts as |false|). It then acts as a macro with two
mandatory arguments within braces (hence this escapes from the
parser scope, the braces can not be hidden in a macro), chooses the
correct branch \emph{without evaluating the wrong one}. Once the
braces are removed, the parser scans and expands the uncovered
material so for example
%
\leftedline{|\xinttheiexpr (3>2)?{5+6}{7-1}2^3\relax|}
%
is legal and computes
|5+62^3=|\dtt{\xinttheiexpr(3>2)?{5+(6}{7-(1}2^3)\relax}. Note
though that it would be better practice to include here the |2^3|
inside the branches. The contents of the branches may be arbitrary
as long as once glued to what is next the syntax is respected:
{|\xintexpr (3>2)?{5+(6}{7-(1}2^3)\relax| also works.} Differs thus
from the |if| conditional in two ways: the false branch is not at
all computed, and the number scanner is still active on exit, more
digits may follow.
Prior to |1.2h|, inputs such as |(cond)?{?(x)}{bar}| were misinterpreted
as involving the |??| operator and the work-around was to write |(cond)?{
?(x)}{bar}|, with an extra space. This is unneeded now.\NewWith{1.2h}
Also |(cond)?{\foo}{bar}| led to premature expansion of |\foo| and gain
the fix was to insert an extra space. This has been corrected. Note though
that the input |(cond)?{?}{!}(x)| will still confuse the parser but
|(cond)?{?(x)}{!(x)}| or even |(cond)?{?(}{!(}x)| are ok.
\item[{\color[named]{DarkOrchid}??}] is used as |(cond)??{<0}{=0}{>0}|.
|cond| is anything, its sign is evaluated and depending on the sign the
correct branch is un-braced, the two others are swallowed. The un-braced
branch will then be parsed as usual. Differs from the |ifsgn| conditional
as the two false branches are not evaluated and furthermore the number
scanner is still active on exit.
%
\leftedline{|\def\x{0.33}\def\y{1/3}|}
%
\leftedline{|\xinttheexpr (\x-\y)??{sqrt}{0}{1/}(\y-\x)\relax|%
\dtt{=\def\x{0.33}\def\y{1/3}%
\xinttheexpr (\x-\y)??{sqrt}{0}{1/}(\y-\x)\relax }}
%
\end{description}
\item The minus sign |-| as prefix unary operator inherits the precedence of
the infix operator it follows. With things such as |5+------2*3|, the
\xintexprname parsers don't try to be efficient: once |2*3| is evaluated the
opposite function will be applied the necessary number of times. On the other
hand the plus sign |+| as prefix unary operator as in, for example
|5-++++++2*3|, is immediately gobbled.
\item The power operator |^|, or |**|. It is left associative:
{\restoreMicroFont|\xinttheiexpr 2^2^3\relax|} evaluates to \xinttheiexpr
2^2^3\relax, not \xinttheiexpr 2^(2^3)\relax. Note that if the float
precision is too low, iterated powers within |\xintfloatexpr..\relax| may
fail: for example with the default setting |(1+1e-8)^(12^16)| will be
computed with |12^16| approximated from its $16$ most significant digits
but it has $18$ digits (\dtt{={\xintiiPow{12}{16}}}), hence the result is
wrong:
\begingroup
%
\leftedline{$\np{\xintthefloatexpr (1+1e-8)^(12^16)\relax }$}
%
One should code
%
\leftedline{\restoreMicroFont|\xintthe\xintfloatexpr (1+1e-8)^\xintiiexpr 12^16\relax
\relax|}
%
to obtain the correct floating point evaluation
%
\leftedline{$\np{1.00000001}^{12^{16}}\approx\np{\xintthefloatexpr
(1+1e-8)^\xintiiexpr 12^16\relax\relax }$}
%
\endgroup
\item Multiplication and division \raisebox{-.3\height}{|*|}, |/|. The
division is left associative, too:
%
\begingroup\restoreMicroFont
%
|\xinttheiexpr 100/50/2\relax| evaluates to \xinttheiexpr 100/50/2\relax,
not \xinttheiexpr 100/(50/2)\relax.
%
\endgroup
Inside \csbxint{iiexpr}, |/| does \emph{rounded} division.
\item Truncated division |//| and modulo |/:| (equivalently |'mod'|, quotes
mandatory) are at the same level of priority than multiplication and
division, thus left-associative with them. Apply parentheses for
disambiguation.
\begin{everbatim*}
\xinttheexpr 100000//13, 100000/:13, 100000 'mod' 13, trunc(100000/13,10),
trunc(100000/:13/13,10)\relax
\end{everbatim*}
\item The list itemwise operators |*[|, |/[|, |^[|, |**[|, |]*|, |]/|, |]^|,
|]**| are at the same precedence level as, respectively, |*| and |/| or |^|
and |**|.
\item Addition and subtraction |+|, |-|. Again, |-| is left
associative:
%
\begingroup\restoreMicroFont
%
|\xinttheiexpr 100-50-2\relax| evaluates to \xinttheiexpr 100-50-2\relax,
not \xinttheiexpr 100-(50-2)\relax.
%
\endgroup
\item The list itemwise operators |+[|, |-[|, |]+|, |]-|, are at
the same precedence level as |+| and |-|,
\item Comparison operators |<|, |>|, |=| (same as |==|), |<=|, |>=|, |!=| all
at the same level of precedence, use parentheses for disambiguation.
\item Conjunction (logical and): |&&| or equivalently
|'and'| (quotes mandatory).
\item Inclusive disjunction (logical or): \verb+||+
and equivalently |'or'| (quotes mandatory).
\item XOR: |'xor'| with mandatory quotes is at the same level of precedence
as \verb+||+.
\item The list generation operators |..|, |..[|, |]..| are at the same
(low) precedence level as the \verb+||+ operator of logical disjunction.
\item The comma:
\restoreMicroFont with |\xinttheexpr 2^3,3^4,5^6\relax|
one obtains as output \xinttheexpr 2^3,3^4,5^6\relax{}.
\item The parentheses. The list outer brackets |[|, |]| share the same
functional precedence as parentheses. The semi-colon |;| in an |iter| or
|rseq| has the same precedence as a closing parenthesis.
\end{itemize}
\subsection{Tacit multiplication}
\label{ssec:tacit multiplication}
Tacit multiplication (insertion of a |*|) applies when the parser is currently
either scanning the digits of a number (or its decimal part or scientific
part, or hexadecimal input), or is looking for an infix operator, and:
(1.)~\emph{encounters a count or dimen or skip register or variable or an
\eTeX{} expression}, or (2.)~\emph{encounters a sub-\csa{xintexpr}ession},
or (3.)~\emph{encounters an opening parenthesis}, or (4.)~\emph{encounters a
letter (which is interpreted as signaling the start of either a variable or
a function name)}.
\begin{framed}
For example, if |x, y, z| are variables all three of |(x+y)z|, |x(y+z)|,
|(x+y)(x+z)| will create a tacit multiplication.
Furthermore starting with release
|1.2e|,\MyMarginNote[\kern\dimexpr\FrameSep+\FrameRule\relax]{Changed}
whenever tacit multiplication is applied, in all cases it \emph{always}
``ties'' more\IMPORTANT{} than normal multiplication or division, but
still less than power. Thus |x/2y| is interpreted as |x/(2y)| and
similarly for |x/2max(3,5)| but |x^2y| is still interpreted as |(x^2)*y|
and |2n!| as |2*n!|.
\begin{everbatim*}
\xintdefvar x:=30;\xintdefvar y:=5;%
\xinttheexpr (x+y)x, x/2y, x^2y, x!, 2x!, x/2max(x,y)\relax
\end{everbatim*}
The ``tie more'' rule applies to all cases of tacit multiplication. It
impacts only situations when a division was the last seen operator, as the
normal rule for the \xintexprname parsers is left-associativity in case of
equal precedence.
\begin{everbatim*}
\xinttheexpr (1+2)/(3+4)(5+6), 2/x(10), 2/10x, 3/y\xintiiexpr 5+6\relax, 1/x(y)\relax
\end{everbatim*}
Note that |y\xinttheiiexpr 5+6\relax| would have tried to use a variable
with name |y11| rather than doing |y*11|: tacit multiplication works only
in front of sub-\csbxint{expr}essions, not in front of
\csbxint{theexpr}essions which are unlocked into explicit digits.
These examples above redeclared the |x| and |y| which thus can not be used as
dummy variables anymore (but see \csbxint{unassignvar}); as this happened
inside a \LaTeX{} environment (for the frame), they will have
recovered their meanings after the frame. In the meantime we use letter
|z| for the next example. Here is an expression whose meaning is
completely modified by the ``tie more'' property of tacit multiplication:\IMPORTANT
\begin{everbatim}
\xintdeffunc e(z):=1+z(1+z/2(1+z/3(1+z/4)));
\end{everbatim}
will be parsed as |1+z*(1+z/(2*(1+z/(3*(1+z/4)))))| which is
not at all like the presumably hoped:
\begin{everbatim}
\xintdeffunc e(z):=1+z(1+z/2*(1+z/3*(1+z/4)));
\end{everbatim}
This form can also be used, alternatively:
\begin{everbatim}
\xintdeffunc e(z):=(((z/4+1)z/3+1)z/2+1)z+1;
\end{everbatim}
Attention! tacit multiplication before an opening parenthesis applies
always, but tacit multiplication after a closing parenthesis \emph{does
not} apply in front of digits: |(1+1)5| is not legal. But
|subs((1+1)x,x=5)| is, because in that case a variable is following the
closing parenthesis.
\end{framed}
\subsection{Predefined functions}
Functions are at the same top level of priority. All functions even
|?| and |!| (as prefix) require parentheses around their arguments.
\begin{snugframed}
\xintFor #1 in {num, qint, qfrac, qfloat, reduce, abs, sgn, frac, floor,
ceil, sqr, sqrt, sqrtr, factorial, binomial, pfactorial, float, round,
trunc, mod, quo, rem, gcd, lcm, max, min, `+`, `*`, ?, !, not, all,
any, xor, if, ifsgn, even, odd, first, last, reversed, len,
bool, togl}\do
{\ctexttt{#1}\xintifForLast{}{, }}
|factorial|, |binomial|, |pfactorial|, |quo|, |rem|, |even|, |odd|,
|gcd| and |lcm| will first truncate their arguments to integers; the
latter two require package \xintgcdname; |togl| requires the |etoolbox|
package; |all|, |any|, |xor|, |`+`|, |`*`|, |max|, |min|, |first|,
|last|, |reversed| and |len| are functions with arbitrarily many comma
separated arguments.
|bool|, |togl| use delimited macros to fetch their argument and the
closing parenthesis which thus must be explicit, not arising from
expansion.
The same holds for |qint|, |qfrac|, |qfloat|.\NewWith{1.2}
\end{snugframed}
\begin{description}[parsep=0pt,% pas le temps de regarder labelwidth=\leftmarginiii,
itemindent=0pt, listparindent=\leftmarginiii,
leftmargin=\leftmarginii]
\item[functions with a single (numeric) argument]
\noindent\par
\begin{description}
\item[num] truncates to the nearest integer (truncation towards zero).
\begin{everbatim*}
\xinttheexpr num(3.1415^20)\relax
\end{everbatim*}
\item[qint] skips the token by token parsing of the input. The ending
parenthesis must be physically present rather than arising from
expansion.\NewWith{1.2} The |q| stands for ``quick''. This ``function''
handles the input exactly like do the |i| macros of \xintcorename, via
\csbxint{iNum}. Hence leading signs and the leading zeroes (coming next)
will be handled appropriately but spaces will not be systematically
stripped. They should cause no harm and will be removed as soon as the
number is used with one of the basic operators. This input form \emph{does
not accept decimal part or scientific part}.
\begin{everbatim}
\def\x{....many many many ... digits}\def\y{....also many many many digits...}
\xinttheiiexpr qint(\x)*qint(\y)+qint(\y)^2\relax
\end{everbatim}
\item[qfrac] does the same as \dtt{qint} excepts that it accepts fractions,
decimal numbers, scientific numbers as they are understood by the macros of
package\NewWith{1.2} \xintfracname. Not to be used within an
|\xintiiexpr|-ession, except if hidden inside functions such as
\dtt{round} or \dtt{trunc} which produce integers from fractions.
\item[qfloat] does the same as \dtt{qfrac} and converts to a float with the
precision given by the setting of |\xintDigits|.
\item[reduce] reduces a fraction to smallest terms
\begin{everbatim*}
\xinttheexpr reduce(50!/20!/20!/10!)\relax
\end{everbatim*}
Recall that this is NOT done automatically, for example when adding fractions.
\item[abs] absolute value
\item[sgn] sign
\item[frac] fractional part
\begin{everbatim*}
\xinttheexpr frac(-355/113), frac(-1129.218921791279)\relax
\end{everbatim*}
\item[floor] floor function.
\item[ceil] ceil function.
\item[sqr] square.
\item[sqrt] in |\xintiiexpr|, truncated square root; in |\xintexpr| or
|\xintfloatexpr| this is the floating point square root, and there is an
optional second argument for the precision.
\item[sqrtr] in |\xintiiexpr| only, rounded square root.
\item[factorial] factorial function, same as previously
available post-fix |!| operator. When used in |\xintexpr| or
|\xintfloatexpr| there is an optional second argument. See discussion later.
\item[?] |?(x)| is the truth value, $1$ if non zero, $0$ if zero. Must use parentheses.
\item[!] |!(x)| is logical not, $0$ if non zero, $1$ if zero. Must use parentheses.
\item[not] logical not.
\item[even] evenness of the truncation.
\begin{everbatim*}
\xinttheexpr seq((x,even(x)), x=-5/2..[1/3]..+5/2)\relax
\end{everbatim*}
\item[odd] oddness of the truncation.
\begin{everbatim*}
\xinttheexpr seq((x,odd(x)), x=-5/2..[1/3]..+5/2)\relax
\end{everbatim*}
\end{description}
\item[functions with an alphabetical argument]
\noindent\par
\hypertarget{item:bool}{\ctexttt{bool,togl}}. |bool(name)| returns
$1$ if the \TeX{} conditional |\ifname| would act as |\iftrue| and
$0$ otherwise. This works with conditionals defined by |\newif| (in
\TeX{} or \LaTeX{}) or with primitive conditionals such as
|\ifmmode|. For example:
%
\leftedline{|\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO}|}
%
will return $\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO}$
if executed in math mode (the computation is then $100-100=0$) and
\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO} if not (the
\ctexttt{if} conditional is described below; the
\csbxint{ifboolexpr} test automatically encapsulates its first
argument in an |\xintexpr| and follows the first branch if the
result is non-zero (see \autoref{xintifboolexpr})).
The alternative syntax |25*4-\ifmmode100\else75\fi| could have been
used here, the usefulness of |bool(name)| lies in the availability
in the |\xintexpr| syntax of the logic operators of conjunction
|&&|, inclusive disjunction \verb+||+, negation |!| (or |not|), of
the multi-operands functions |all|, |any|, |xor|, of the two
branching operators |if| and |ifsgn| (see also |?| and |??|), which
allow arbitrarily complicated combinations of various |bool(name)|.
Similarly |togl(name)| returns $1$ if the \LaTeX{} package
\href{http://www.ctan.org/pkg/etoolbox}{etoolbox}%
%
%
%
\footnote{\url{http://www.ctan.org/pkg/etoolbox}}
%
has been used to define a toggle named |name|, and this toggle is
currently set to |true|. Using |togl| in an |\xintexpr..\relax|
without having loaded
\href{http://www.ctan.org/pkg/etoolbox}{etoolbox} will result in an
error from |\iftoggle| being a non-defined macro. If |etoolbox| is
loaded but |togl| is used on a name not recognized by |etoolbox|
the error message will be of the type ``ERROR: Missing |\endcsname|
inserted.'', with further information saying that |\protect| should
have not been encountered (this |\protect| comes from the expansion
of the non-expandable |etoolbox| error message).
When |bool| or |togl| is encountered by the |\xintexpr| parser, the
argument enclosed in a parenthesis pair is expanded as usual from
left to right, token by token, until the closing parenthesis is
found, but everything is taken literally, no computations are
performed. For example |togl(2+3)| will test the value of a toggle
declared to |etoolbox| with name |2+3|, and not |5|. Spaces are
gobbled in this process. It is impossible to use |togl| on such
names containing spaces, but |\iftoggle{name with spaces}{1}{0}|
will work, naturally, as its expansion will pre-empt the
|\xintexpr| scanner.
There isn't in |\xintexpr...| a |test| function available analogous
to the |test{\ifsometest}| construct from the |etoolbox| package;
but any \emph{expandable} |\ifsometest| can be inserted directly in
an |\xintexpr|-ession as |\ifsometest10| (or |\ifsometest{1}{0}|),
for example |if(\ifsometest{1}{0},YES,NO)| (see the |if| operator
below) works.
A straight |\ifsometest{YES}{NO}| would do the same more
efficiently, the point of |\ifsometest10| is to allow arbitrary
boolean combinations using the (described later) \verb+&+ and
\verb+|+ logic operators:
\verb+\ifsometest10 & \ifsomeothertest10 | \ifsomethirdtest10+,
etc... |YES| or |NO| above stand for material compatible with the
|\xintexpr| parser syntax.
See also \csbxint{ifboolexpr}, in this context.
\item[functions with one mandatory and a second but optional argument]
\noindent\par
\begin{description}
\item[round] For example
|round(-2^9/3^5,12)=|\dtt{\xinttheexpr round(-2^9/3^5,12)\relax.}
\item[trunc] For example
|trunc(-2^9/3^5,12)=|\dtt{\xinttheexpr trunc(-2^9/3^5,12)\relax.}
\item[float] For example
|float(-2^9/3^5,12)=|\dtt{\xinttheexpr float(-2^9/3^5,12)\relax.}
\item [sqrt] in \csa{xintexpr}|...\relax| and \csa{xintfloatexpr}|...\relax|
it achieves the precision given by the optional second argument. For
legacy reasons the |sqrt| function in \csa{xintiiexpr} \emph{truncates}
(to an integer), whereas |sqrt| in \csa{xintfloatexpr}|...\relax| (and in
\csa{xintexpr}|...\relax| which borrows it) \emph{rounds} (in the sense of
floating numbers). There is |sqrtr| in \csa{xintiiexpr} for
\emph{rounding} to nearest integer.
\begin{everbatim*}
\xinttheexpr sqrt(2,31)\relax\ and \xinttheiiexpr sqrt(num(2e60))\relax
\end{everbatim*}
\item[factorial] when the second optional argument\NewWith {1.2f} is made
use of inside \csa{xintexpr}|...\relax|, this switches to the use of the
float version, rather than the exact one.
\begin{everbatim*}
\xinttheexpr factorial (100,32)\relax, {\xintDigits:=32;\xintthefloatexpr
factorial (100)\relax}\newline
\xinttheexpr factorial (50)\relax\newline
\xinttheexpr factorial (50, 32)\relax
\end{everbatim*}
\end{description}
\item[functions with two arguments]
\noindent\par
\begin{description}
\item[quo] first truncates the arguments then computes the Euclidean quotient.
\item[rem] first truncates the arguments then computes the Euclidean remainder.
\item[mod] computes the modulo associated to the truncated division, same as
|/:| infix operator.
\begin{everbatim*}
\xinttheexpr mod(11/7,1/13), reduce(((11/7)//(1/13))*1/13+mod(11/7,1/13)),
mod(11/7,1/13)- (11/7)/:(1/13), (11/7)//(1/13)\relax
\end{everbatim*}
\item[binomial] computes binomial coefficients.\NewWith {1.2f} For some
obscure reason the initial version rather than returning zero for
|binomial(x,y)| with |y<0| or |x<y| deliberately raised an out-of-range
error. This has been fixed in |1.2h|. An error is raised only for
|x<0| (or if |x>99999999|.)\CHANGED{1.2h}
\begin{everbatim*}
\xinttheexpr seq(binomial(20, i), i=0..20)\relax
\end{everbatim*}
\begin{everbatim*}
\xintthefloatexpr seq(binomial(100, 50+i), i=-5..+5)\relax
\end{everbatim*}
The arguments must be (expand to) short integers.
\item[pfactorial] computes partial factorials\NewWith {1.2f} i.e.
|pfactorial(a,b)| evaluates the product |(a+1)...b|.
\begin{everbatim*}
\xinttheexpr seq(pfactorial(20, i), i=20..30)\relax
\end{everbatim*}
The arguments must (expand to) short integers. See \autoref{xintiiPFactorial}
for the behaviour if the arguments are negative.\CHANGED{1.2h}
\end{description}
\item[the if conditional (twofold way)]
\noindent\par
\ctexttt{if}|(cond,yes,no)|
checks if |cond| is true or false and takes the corresponding
branch. Any non zero number or fraction is logical true. The zero
value is logical false. Both ``branches'' are evaluated (they are
not really branches but just numbers). See also the |?| operator.
\item[the ifsgn conditional (threefold way)]
\noindent\par
\ctexttt{ifsgn}|(cond,<0,=0,>0)| checks the sign of |cond| and
proceeds correspondingly. All three are evaluated. See also the |??|
operator.
\item[functions with an arbitrary number of arguments]
\noindent\par
This argument may well be generated by one or many |a..b| or |a..[d]..b|
constructs, separated by commas.
\begin{description}
\item[all] inserts a logical |AND| in between arguments and evaluates,
\item[any] inserts a logical |OR| in between all arguments and evaluates,
\item[xor] inserts a logical |XOR| in between all arguments and evaluates,
\item[|`+`|] adds (left ticks mandatory):
\begin{everbatim*}
\xinttheexpr `+`(1,3,19), `+`(1*2,3*4,19*20)\relax
\end{everbatim*}
\item[|`*`|] multiplies (left ticks mandatory):
\begin{everbatim*}
\xinttheexpr `*`(1,3,19), `*`(1^2,3^2,19^2), `*`(1*2,3*4,19*20)\relax
\end{everbatim*}
\item[max] maximum,
\item[min] minimum,
\item[gcd] first truncates to integers then computes the |GCD|, requires \xintgcdname,
\item[lcm] first truncates to integers then computes the |LCM|, requires \xintgcdname,
\item[first] first among comma separated items, |first(list)| is like |[list][:1]|.
\begin{everbatim*}
\xinttheiiexpr first(-7..3), [-7..3][:1]\relax
\end{everbatim*}
\item[last] last among comma separated items, |last(list)| is like |[list][-1:]|.
\begin{everbatim*}
\xinttheiiexpr last(-7..3), [-7..3][-1:]\relax
\end{everbatim*}
\item[reversed] reverses the order
\begin{everbatim*}
\xinttheiiexpr reversed(123..150)\relax
\end{everbatim*}
\item[len] computes\NewWith{1.2g} the number of items in a comma separated
list. Earlier syntax was |[a,b,...,z][0]| but since |1.2g| this now returns
the first element of the list.
\begin{everbatim*}
\xinttheiiexpr len(1..50, 101..150, 1001..1050)\relax
\end{everbatim*}
\end{description}
\end{description}
\subsection{Constructs with dummy variables}
\label{ssec:dummies}
% \begin{snugframed}
The ``functions'' \xintFor #1 in {add, mul, seq, subs, rseq, iter, rrseq,
iterr} \do {\ctexttt{#1}\xintifForLast{}{, }} use some delimited
macros to fetch the |,<letter>| part, checking the correct balance of
parentheses, and allowing nesting. The |<letter>| (lowercase or
uppercase) will be followed by a |=| sign and then a comma separated
list of values or a list expression such as |a..b|, or both, which will
be treated in the normal manner to provide the values which will be in
succession assigned to the |<letter>|. This |<letter>| must not have
been assigned a value before via \csa{xintdefvar}.
The functions |rseq|, |iter|, |rrseq| and |iterr| have an additional
mandatory initial comma separated list which is separated by a
semi-colon from the expression to evaluate iteratively. This portion up
to and including the semi-colon may arise entirely from expansion
(contrarily to the |,<letter>=| part discussed above).
|seq|, |rseq|, |iter|, |rrseq|, |iterr| but
not |add|, |mul|, |subs| admit the |omit|, |abort|, and |break(..)|
keywords, possibly but not necessarily in combination with a potentially
infinite list generated by a |n++| expression.
They may be nested.
% \end{snugframed}
Dummy variables are necessarily single-character letters, and all lowercase and
uppercase Latin letters are pre-configured for that usage.
\begin{description}[parsep=0pt,% labelwidth=\leftmarginii,
itemindent=0pt, listparindent=\leftmarginiii,
leftmargin=\leftmarginii]
\item [subs] for variable substitution
\begin{everbatim*}
\xinttheexpr subs(subs(seq(x*z,x=1..10),z=y^2),y=10)\relax\newline
\end{everbatim*}%
Attention that |xz| generates an error, one must use explicitely |x*z|, else
the parser expects a variable with name |xz|.
This is useful for example when defining macros for which some argument |#1|
will be used more than once but may itself be a complicated expression or
macro, and should be evaluated only once, for matters of efficiency.
The substituted variable may be a comma separated list (this is impossible
with |seq| which will always pick one item after the other from a list).
\begin{everbatim*}
\xinttheexpr subs([x]^2,x=-123,17,32)\relax
\end{everbatim*}
See the examples related to the |3x3| determinant in the
\autoref{xintNewExpr} for an illustration of list substitution.
\item[add] addition
\begin{everbatim*}
\xinttheiiexpr add(x^3,x=1..50), add(x(x+1), x=1,3,19)\relax\newline
\end{everbatim*}%
See |`+`| for syntax without a dummy variable.
\item[mul] multiplication
\begin{everbatim*}
\xinttheiiexpr mul(x^2, x=1,3,19), mul(2n+1,n=1..10)\relax\newline
\end{everbatim*}%
See |`*`| for syntax without a dummy variable.
\item[seq] comma separated values generated according to a formula
\begin{everbatim*}
\xinttheiiexpr seq(x(x+1)(x+2)(x+3),x=1..10), `*`(seq(3x+2,x=1..10))\relax
\end{everbatim*}
\begin{everbatim*}
\xinttheiiexpr seq(seq(i^2+j^2, i=0..j), j=0..10)\relax
\end{everbatim*}
\item[rseq] recursive sequence, |@| for the previous value.
\begin{everbatim*}
\printnumber {\xintthefloatexpr subs(rseq (1; @/2+y/2@, i=1..10),y=1000)\relax }\newline
\end{everbatim*}%
Attention: in the example above |y/2@| is interpreted as
|y/(2*@)|.\IMPORTANT{} With versions |1.2c| or earlier it would have been
interpreted as |(y/2)*@|.
In case the initial stretch is a comma separated list, |@| refers at the first
iteration to the whole list. Use parentheses at each iteration to maintain
this ``nuple''. For example:
\begin{everbatim*}
\printnumber{\xintthefloatexpr rseq(1,10^6;
(sqrt([@][0]*[@][1]),([@][0]+[@][1])/2), i=1..7)\relax }
\end{everbatim*}
\item[iter] is exactly like |rseq|\CHANGED{1.2g}, except that it only prints
the last iteration. Strangely it was lacking from |1.1| release, or rather
what was available from |1.1| to |1.2f| is what is called now |iterr|
(described below).
\hypertarget{BrentSalamin}{}
The new |iter| is convenient to handle compactly higher order iterations.
We can illustrate its use with an expandable (!)
implementation of the Brent-Salamin algorithm for the computation of $\pi$:
\begin{everbatim*}
\xintDigits:= 91;
\xintdeffloatfunc BS(a, b, t, p):= (a+b)/2, sqrt(a*b), t-p(a-b)^2, \xintiiexpr 2p\relax;
\xintthefloatexpr [88] % use 3 guard digits (output value is *rounded*)
iter(1, 1/sqrt(2), 1, 1; % initial values
([@][0]-[@][1]<2[-45])? % if a-b is small enough stop iterating and ...
{break(([@][0]+[@][1])^2/[@][2])} % ... do final computation,
{BS(@)}, % else do iteration via pre-defined (for convenience) function BS.
i=1++) % This generates infinite iteration. The i is not used.
\relax
\xintDigits:=16;
\end{everbatim*}
You can try with |\xintDigits:=1001;| and |2[-501]|, but don't round to |88|
digits of course ... and better wrap the whole thing in |\message| because
it will run in the right margin (about \dtt{7.4}s on my laptop last time I tried).
\item[rrseq] recursive sequence with multiple initial terms. Say, there are
|K| of them. Then |@1|, ..., |@4| and then |@@(n)| up to |n=K| refer to the
last |K| values. Notice the difference with |rseq| for which |@| refers to
the complete list of all initial terms if there are more than one and may
thus be a ``list'' object. This is impossible with |rrseq|. This construct
is effective for scalar finite order recursions, and may be perhaps a bit
more efficient than using the |rseq| syntax with a ``list'' value.
\begin{everbatim*}
\xinttheiiexpr rrseq(0,1; @1+@2, i=2..30)\relax
\end{everbatim*}
\begin{everbatim*}
\xinttheiiexpr rseq(1; 2@, i=1..10)\relax
\end{everbatim*}
\begin{everbatim*}
\xinttheiiexpr rseq(1; 2@+1, i=1..10)\relax
\end{everbatim*}
\begin{everbatim*}
\xinttheiiexpr rseq(2; @(@+1)/2, i=1..5)\relax
\end{everbatim*}
\begin{everbatim*}
\xinttheiiexpr rrseq(0,1,2,3,4,5; @1+@2+@3+@4+@@(5)+@@(6), i=1..20)\relax
\end{everbatim*}
I implemented an |Rseq| which at all times keeps the memory of \emph{all}
previous items, but decided to drop it as the package was becoming big.
\item[iterr] same as |rrseq| but does not print any value until the last |K|.
\begin{everbatim*}
\xinttheiiexpr iterr(0,1; @1+@2, i=2..5, 6..10)\relax
% the iterated over list is allowed to have disjoint defining parts.
\end{everbatim*}
\end{description}
Recursions may be nested, with |@@@(n)| giving access to the values of the
outer recursion\dots and there is even |@@@@(n)| to access the outer outer
recursion but I never tried it!
With |seq|, |rseq|, |iter|, |rrseq|, |iterr|, \textbf{but not} with |subs|,
|add|, |mul|, one has:
\begin{description}
\item[abort] stop here and now.
\item[omit] omit this value.
\item[break] |break(stuff)| to abort and have |stuff| as last value.
\item[n++] serves to generate a potentially infinite list. The |n++| construct
in conjunction with an |abort| or |break| is often more efficient, because
in other cases the list to iterate over is first completely constructed.
\begin{everbatim*}
\xinttheiiexpr iter(1;(@>10^40)?{break(@)}{2@},i=1++)\relax
\end{everbatim*}
is the smallest power of 2 with at least fourty one digits.
Note that |n++| can not work in the format |i=10,17,30++|, only |<start>++|
nothing before.
\begin{everbatim*}
First Fibonacci number at least |2^31| and its index
% we use iterr to refer via @1 and @2 to the previous and previous to previous.
\xinttheiiexpr iterr(0,1; (@1>=2^31)?{break(i)}{@2+@1}, i=1++)\relax
\end{everbatim*}
\end{description}
Some additional examples are to be found in \autoref{ssec:moredummies}.
\subsection{User defined variables}
\label{xintdefvar}
\label{xintdefiivar}
\label{xintdeffloatvar}
\label{xintunassignvar}
Since release |1.1| it is possible to make an assignment to a variable name
and let it be known to the parsers of \xintexprname.
\begin{everbatim*}
\xintdefvar Pi:=3.141592653589793238462643;
\xintthefloatexpr Pi^100\relax
\xintdefvar x_1 := 10;\xintdefvar x_2 := 20;\xintdefvar y@3 := 30;
\quad $x_1\cdot x_2\cdot y@3+1=\xinttheiiexpr x_1*x_2*y@3+1\relax$.
\end{everbatim*}
Legal variable names are composed of letters, digits, |@| and |_| signs.
They can not start with a digit. They may start with |@| or |_|. Currently
|@|, |@1|, |@2|, |@3|, and |@4| are reserved because they have special
meanings for use in iterations. The |@@|, |@@@|, |@@@@| are also reserved but
are technically functions, not variables. Thus a user may possibly use |@@| as
a variable name, but if it is followed by parentheses, the function
interpretation will be applied, rather than the variable interpretation
followed by a tacit multiplication.
|x_1x| is a licit variable name, as well as |x_1x_| and |x_1x_2| and |x_1x_2y|
etc... hence we can not rely on tacit multiplication being applied to
something like |x_1x_2|; the parser goes not go to the effort of tracing back
its steps. Hence in such cases we have to insert explicit |*| infix operators
(one often falls into this trap when playing with variables and counting too
much on the divinatory talents of \xintexprname...).
Single letter names |a..z| and |A..Z| are pre-declared by the package for use
as special type of variables called ``dummy variables''. It is allowed to
overwrite their original meanings and assign them values.
The assignments are done with \csa{xintdefvar}, \csa{xintdefiivar}, or with
\csa{xintdeffloatvar}. The variable will be computed using respectively
\csbxint{expr}, \csbxint{iiexpr} or \csbxint{floatexpr}. Once defined, it can
be used in the other parsers, except naturally that in \csa{xintiiexpr} only
integers are accepted.
When defining a variable with \csa{xintdeffloatvar}, it is important that
reduction to \csbxint{theDigits} digits of precision happens inside
\csa{xintfloatexpr} only if an operation is executed. Thus, for a variable
declaration with no operations, the value is recorded with all its digits.
\begin{everbatim*}
\xintdeffloatvar e:=2.7182818284590452353602874713526624977572470936999595749669676;%
\xinttheexpr e\relax\newline % shows the recorded value
\xintthefloatexpr e\relax\newline % output rounds
\xintthefloatexpr 1+e\relax\newline % the rounding was done by addition (trust me...)
\xintdeffloatvar e:=float(2.7182818284590452353602874713526624977572470936999595749669676);%
\xinttheexpr e\relax\par % use of float forced immediate rounding
\end{everbatim*}
In the next examples we examine the effect of cumulated float operations on
rounding errors:
\begin{everbatim*}
\xintdefvar e_1:=add(1/i!, i=0..10);% exact sum
\xintdeffloatvar e_2:=add(1/i!, i=0..10);% float sum
\xintthefloatexpr e_1, e_2\relax\newline
\xintdefvar e_3:=e_1+add(1/i!, i=11..20);% exact sum
\xintdeffloatvar e_4:=e_2+add(1/i!, i=11..20);% float sum
\xintthefloatexpr e_3, e_4\relax\newline
\xintdeffloatvar e:=2.7182818284590452353602874713526624977572470936999595749669676;%
\xintDigits:=24;
\xintthefloatexpr[16] e, e^1000, e^1000000\relax (e rounded to 24 digits first)\newline
\xintDigits:=16;
\xintthefloatexpr e, e^1000, e^1000000\relax (e rounded to 16 digits first)\par
\end{everbatim*}
With |\xintverbosetrue| the values of the assigned variables will be written
to the log. For example like this (the line numbers here are artificial):
\begin{everbatim}
Package xintexpr Info: (on line 2875)
Variable "e" defined with value 2718281828459045235360287471352662497757247
0936999595749669676[-61].
Package xintexpr Info: (on line 2879)
Variable "e" defined with value 2718281828459045[-15].
Package xintexpr Info: (on line 2886)
Variable "e_1" defined with value 9864101/3628800[0].
Package xintexpr Info: (on line 2887)
Variable "e_2" defined with value 2718281801146385[-15].
Package xintexpr Info: (on line 2889)
Variable "e_3" defined with value 6613313319248080001/2432902008176640000[0
].
Package xintexpr Info: (on line 2890)
Variable "e_4" defined with value 2718281828459046[-15].
Package xintexpr Info: (on line 2892)
Variable "e" defined with value 2718281828459045235360287471352662497757247
0936999595749669676[-61].
\end{everbatim}
Variable declarations are local. One can not really ``unassign'' a
declared variable, but \csa{xintunassignvar} redefines it to insert a zero
and raise a \TeX{} ``undefined macro'' error.
Also, using
\csa{xintunassignvar}\IMPORTANT{} on a \emph{letter} will let it recover fully its
original meaning as dummy variable.
\begin{everbatim*}
\xintFor #1 in {e_1, e_2, e_3, e_4, e} \do {\xintunassignvar {#1}}
\end{everbatim*}
\subsection{User defined functions}
\label{xintdeffunc}
\label{xintdefiifunc}
\label{xintdeffloatfunc}
\label{xintverbosetrue}
\label{xintverbosefalse}
\label{ifxintverbose}
Since release |1.2c| it is possible to declare functions:
\begin{everbatim*}
\xintdeffunc
Rump(x,y):=1335 y^6/4 + x^2 (11 x^2 y^2 - y^6 - 121 y^4 - 2) + 11 y^8/2 + x/2y;
\end{everbatim*}(notice the numerous tacit multiplications in this expression;
and that |x/2y| is interpreted as |x/(2y)|.)
\begin{framed}
The (dummy) variables used in the function declaration are necessarily single
letters (lowercase or uppercase) which have \emph{not} been re-declared via
|\xintdefvar| as assigned variables. The choice of the letters is entirely
up to the user and has nil influence on the actual function, naturally.
A function can have at most nine variables.
%
% The names of the macros \csa{xintdeffunc}, \csa{xintdefiifunc},
% \csa{xintdeffloatfunc} (and those for variables) as well as their syntax
% (with |:=| and an ending |;|) will be set definitely only in next release.
\footnotemark
A function must be defined for a specific parser, using either
|\xintdeffunc|, |\xintdefiifunc| or |\xintdeffloatfunc|.
\end{framed}
\footnotetext{with the current syntax, the |;| as used for |iterr|, |rseq|,
|rrseq| must be hidden as |{;}| to not be confused with the |;| ending the
declaration.}
Let's try the famous \textsc{Rump} test:
\begin{everbatim*}
\xinttheexpr Rump(77617,33096)\relax.
\end{everbatim*}
Nothing problematic for an \emph{exact} evaluation, naturally !
A function may be declared either via \csa{xintdeffunc}, \csa{xintdefiifunc},
\csa{xintdeffloatfunc}. It will then be known \emph{only} to the parser which
was used for its definition.
Thus to test the \textsc{Rump} polynomial (it is not quite a polynomial with
its |x/2y| final term) with floats, we \emph{must} also
declare |Rump| as a function to be used there:
\begin{everbatim*}
\xintdeffloatfunc
Rump(x,y):=333.75 y^6 + x^2 (11 x^2 y^2 - y^6 - 121 y^4 - 2) + 5.5 y^8 + x/2y;
\end{everbatim*}
(I used coefficients |333.75| and |5.5| rather than fractions only because this
is how I saw the polynomial defined in one computer class reference found on
internet; and for float operations this may matter on the rounding).
The numbers are scanned with the current precision, hence as here it is
\dtt{16}, they are scanned exactly in this case. We can then vary the
precision for the evaluation.
\begin{everbatim*}
\def\CR{\cr}
\halign
{\tabskip1ex
\hfil\bfseries#&\xintDigits:=\xintiloopindex;\xintthefloatexpr Rump(77617,33096)#\cr
\xintiloop [8+1]
\xintiloopindex &\relax\CR
\ifnum\xintiloopindex<40 \repeat
}
\end{everbatim*}
It is licit to overload a variable name (all Latin letters are predefined as
dummy variables) with a function name and vice versa. The parsers will decide
from the context if the function or variable interpretation must be used
(dropping various cases of tacit multiplication as normally applied).
\begin{everbatim*}
\xintdefiifunc f(x):=x^3;
\xinttheiiexpr add(f(f),f=100..120)\relax\newline
\xintdeffunc f(x,y):=x^2+y^2;
\xinttheexpr mul(f(f(f,f),f(f,f)),f=1..10)\relax
\end{everbatim*}
The mechanism for functions is identical with the one underlying the
\csbxint{NewExpr} command. A function once declared is a first class citizen,
its expression is entirely parsed and converted into a big nested \fexpan
dable macro. When used its action is via this defined macro. For example
\begin{everbatim*}
\xintdeffunc
e(z):=(((((((((z/10+1)z/9+1)z/8+1)z/7+1)z/6+1)z/5+1)z/4+1)z/3+1)z/2+1)z+1;
\end{everbatim*}
creates a macro whose meaning one can find in the log file, after
|\xintverbosetrue|. Here it is:
\begin{everbatim}
Function e for \xintexpr parser associated to \XINT_expr_userfunc_e with me
aning macro:#1,->\xintAdd {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\x
intDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\
xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {
\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {#1}{10}}{1}}{#1}}{9
}}{1}}{#1}}{8}}{1}}{#1}}{7}}{1}}{#1}}{6}}{1}}{#1}}{5}}{1}}{#1}}{4}}{1}}{#1}}{3}
}{1}}{#1}}{2}}{1}}{#1}}{1}
\end{everbatim}
This has the same limitations as the \csbxint{NewExpr} command. The main one
is that dummy variables are usable only to the extent that their values are
numerical. For example |\xintdeffunc f(x):=add(i^2,i=1..x);| is not possible.
See \autoref{sssec:limitations} and the next subsection.
In this example one could use the alternative syntax with list
operations:\footnote{It turns out |`+`(seq(i^2, i=1..x))| would work here, but
this isn't always the case with |seq| constructs.}
\begin{everbatim*}
\xintdeffunc f(x):=`+`([1..x]^2);\xinttheexpr seq(f(x), x=1..20)\relax
\end{everbatim*}
Side remark: as the |seq(f(x), x=1..10)| does many times the same
computations, an |rseq| here would be more efficient:\footnote{Note that
|omit| and |abort| are not usable in |add| or |mul| (currently).}
\begin{everbatim*}
\xinttheexpr rseq(1; (x>20)?{abort}{@+x^2}, x=2++)\relax
\end{everbatim*}
On the other hand a construct like the following has no issue, as the values
iterated over do not depend upon the function parameters:
\begin{everbatim*}
\xintdeffunc f(x):=iter(1{;} @*x/i+1, i=10..1);% one must hide the first semi-colon !
\xinttheexpr e(1), f(1)\relax
\end{everbatim*}
With |\xintverbosetrue| the meanings of the
functions (or rather their associated macros) will be written to the log. For
example the first |Rump| declaration above generates this in the log file:
\begin{everbatim}
Function Rump for \xintexpr parser associated to \XINT_expr_userfunc_Rump w
ith meaning macro:#1,#2,->\xintAdd {\xintAdd {\xintAdd {\xintDiv {\xintMul {133
5}{\xintPow {#2}{6}}}{4}}{\xintMul {\xintPow {#1}{2}}{\xintSub {\xintSub {\xint
Sub {\xintMul {11}{\xintMul {\xintPow {#1}{2}}{\xintPow {#2}{2}}}}{\xintPow {#2
}{6}}}{\xintMul {121}{\xintPow {#2}{4}}}}{2}}}}{\xintDiv {\xintMul {11}{\xintPo
w {#2}{8}}}{2}}}{\xintDiv {#1}{\xintMul {2}{#2}}}
\end{everbatim}
and the declaration |\xintdeffunc f(x):=iter(1{;} @*x/i+1, i=10..1);| generates:
\begin{everbatim}
Function f for \xintexpr parser associated to \XINT_expr_userfunc_f with me
aning macro:#1,->\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\x
intAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\
xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {
\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul
{1}{#1}}{10/1[0]}}{1}}{#1}}{9/1[0]}}{1}}{#1}}{8/1[0]}}{1}}{#1}}{7/1[0]}}{1}}{#1
}}{6/1[0]}}{1}}{#1}}{5/1[0]}}{1}}{#1}}{4/1[0]}}{1}}{#1}}{3/1[0]}}{1}}{#1}}{2/1[
0]}}{1}}{#1}}{1/1[0]}}{1}
\end{everbatim}
Starting with |1.2d| the definitions made by \csbxint{NewExpr} have local
scope, hence this is also the case with the definitions made by
\csbxint{deffunc}.\IMPORTANT{} One can not ``undeclare'' a function, but
naturally one can provide a new definition for it.
It is possible to define functions which expand to comma-separated values, for
example the declarations:
\begin{everbatim*}
\xintdeffunc f(x):= x, x^2, x^3, x^x;
\xintdeffunc g(x):= x^[0..x];% x^[1, 2, 3, x] would be like f above.
\end{everbatim*}
will generate
\begin{everbatim}
Function f for \xintexpr parser associated to \XINT_expr_userfunc_f with me
aning macro:#1,->#1,\xintPow {#1}{2},\xintPow {#1}{3},\xintPow {#1}{#1}
Function g for \xintexpr parser associated to \XINT_expr_userfunc_g with me
aning macro:#1,->\xintApply::csv {\xintPow {#1}}{\xintSeq::csv {0}{#1}}
\end{everbatim}
and we can check that they work:
\begin{everbatim*}
\xinttheexpr f(10)\relax; \xinttheexpr g(10)\relax
\end{everbatim*}
N.B.: we declared in this section |e|, |f|, |g| as functions. Except naturally
if the function declarations are done in a group or a \LaTeX{} environment
whose scope has ended, they can not be completely undone, and if |e|, |f|, or
|g| are used as dummy variables the tacit multiplication in front of
parentheses will not be applied, it is their function interpretation which will
prevail. However, with an explicit |*| in front of the opening parenthesis, it
does work:
\begin{everbatim*}
\xinttheexpr add(f*(f+f), f= 1..10)\relax % f is used as variable, not as a function.
\end{everbatim*}
\subsection{\csbh{xintNewFunction}}
\label{xintNewFunction}
The syntax is analogous to the one of \csbxint{NewExpr} but achieves something
completely different.\NewWith{1.2h} Here is an example:
\begin{everbatim*}
\xintNewFunction {foo}[3]{add(mul(x+i, i=#1..#2),x=1..#3)}
\end{everbatim*}
We now have a genuine function |foo( , , )| of three variables which we can
use fully in the three parsers, be it with numerical arguments or variables or
whatever.
\begin{everbatim*}
\xinttheexpr seq(foo(0, 3, j), j= 1..10)\relax
\end{everbatim*}
However this construct is only syntactic sugar to benefit from functional
notation. Each time the function |foo| will be encountered the corresponding
expression will be inserted as a sub-expression (of the same type as the
surrounding one), the macro parameters having been replaced with the (already
evaluated) function arguments, and the parser will then parse the expression.
It is very much like a macro substitution, but using functional notation.
\begin{everbatim}
Package xintexpr Info: (on line 3151)
Function foo for the expression parsers is associated to \XINT_expr_macrofu
nc_foo with meaning macro:#1,#2,#3,->add(mul(x+i, i=\XINT_expr_wrapit {#1}..\XI
NT_expr_wrapit {#2}),x=1..\XINT_expr_wrapit {#3})
\end{everbatim}
This is thus very different from a function defined via |\xintdeffunc| which
immediately expands to some (possibly very complicated) nesting of various
macro calls, short-circuiting the parser. But (see \autoref{sssec:limitations})
it is not currently possible to define a |foo| function like the one above via
|\xintdeffunc|.
One can declare a function |foo| with |[0]| arguments but it must be used
as |foo(nil)|, as |foo()| with no argument would generate an error.
\subsection{List operations}
\label{ssec:lists}
By \emph{list} we hereby mean simply comma-separated values, for example |3,
-7, 1e5|. This section describes some syntax which allows to manipulate such
lists, for example |[3, -7, 1e5][1]| extracts |-7| (we follow the Python
convention of enumerating starting at zero; see the frame next).
In the context of dummy variables, lists can be used in substitutions:
\begin{everbatim*}
\xinttheiiexpr subs(`+`(L), L = 1, 3, 5, 7, 9)\relax\newline
\end{everbatim*}
and also the |rseq| and |iter| constructs allow |@| to refer to a list:
\begin{everbatim*}
\xinttheiiexpr iter(0, 1; ([@][1], [@][0]+[@][1]), i=1..10)\relax\newline
\end{everbatim*}
where each step constructs a new list with two entries.
However, despite appearances there is not really internally a notion of a
\emph{list type} and it is currently impossible to create,
manipulate, or return on output a \emph{list of lists}. There is a special
reserved variable |nil| which stands for the empty list: for example |len()|
is not legal but |len(nil)| works.
The syntax which is explained next includes in particular what are called
\emph{list itemwise operators} such as:
\begin{everbatim*}
\xinttheiiexpr 37+[13,100,1000]\relax\newline
\end{everbatim*}%
This part of the syntax is considered provisory, for the reason that its
presence might make more difficult some extensions in the future. On the other
hand the Python-like slicing syntax should not change.
\begin{framed}
\emph{A backwards incompatible change.}\IMPORTANT{}
\medskip
Up to release |1.2f| inclusive, the item accessor |[list][n]| returned the
|n|th element of a list. The Python-like slices |[list][a:b]| on the other
hand act exactly as in Python where list items are enumerated starting at
zero. For example |[list][:5]| or equivalently |[list][0:5]| have the effect
to keep only the first five elements. Thus |[list][n]| which returned the
|n|th element was akin to |[list][n-1:n]| whereas in Python which enumerates
from zero it would be |[list][n:n+1]|.
One reason for that choice was that |[list][0]| allowed access to the length,
and there was thus no need to add a new function to the list of recognized
keywords.
|1.2g|\CHANGED{1.2g} does the backwards incompatible change to adhere more
fully to Python conventions and now |[list][1]| picks the \emph{second}
element of the list and |[list][0]| the \emph{first}. There is |len(list)| for
the length.
The reason for the change is that the author has become more accustomed to
Python than he was when he first introduced list operations to \xintexprname,
and the difference was becoming distracting.
\end{framed}
\begin{itemize}
\item |a..b| constructs the \textbf{small} integers from the ceil $\lceil
a\rceil$ to the floor
$\lfloor b\rfloor$ (possibly a decreasing sequence): one has to be careful
if using this for algorithms that |1..0| for example is not empty or |1|
but expands to |1, 0|. Again, |a..b| \emph{can not} be used with |a| and
|b| greater than $2^{31}-1$. Also, only about at most \dtt{5000} integers
can be generated (this depends upon some \TeX{} memory settings).
The |..| has lower precedence than the arithmetic operations.
\begin{everbatim*}
\xinttheexpr 1.5+0.4..2.3+1.1\relax; \xinttheexpr 1.9..3.4\relax; \xinttheexpr 2..3\relax
\end{everbatim*}
\item |a..[d]..b| allows to generate big integers, or also fractions, it
proceeds with step (non necessarily integral nor positive) |d|. It does
\emph{not} replace |a| by its ceil, nor |b| by its floor. The generated
list is empty if |b-a| and |d| are of opposite signs; if |d=0| or if |a=b|
the list expands to single element |a|.
\begin{everbatim*}
\xinttheexpr 1.5..[1.01]..11.23\relax
\end{everbatim*}
\item |[list][n]| extracts the |n+1|th element if |n>=0|.\CHANGED{1.2g} If
|n<0| it extracts from the tail. List items are numbered as in Python.
|len(list)| computes the number of items of the list.
\begin{everbatim*}
\xinttheiexpr \empty[0..10][6], len(0..10), [0..10][-1], [0..10][23*18-22*19]\relax\
(and 23*18-22*19 has value \the\numexpr 23*18-22*19\relax).
\end{everbatim*}
See the next frame for why the example above has |\empty| token at start.
As shown, it is perfectly legal to do operations in the index parameter, which
will be handled by the parser as everything else. The same remark applies to
the next items.
\item |[list][:n]| extracts the first |n| elements if |n>0|, or suppresses
the last \verb+|n|+ elements if |n<0|.
\begin{everbatim*}
\xinttheiiexpr [0..10][:6]\relax\ and \xinttheiiexpr [0..10][:-6]\relax
\end{everbatim*}
\item |[list][n:]| suppresses the first |n| elements if |n>0|, or extracts
the last \verb+|n|+ elements if |n<0|.
\begin{everbatim*}
\xinttheiiexpr [0..10][6:]\relax\ and \xinttheiiexpr [0..10][-6:]\relax
\end{everbatim*}
\item More generally, |[list][a:b]| works according to the Python ``slicing''
rules (inclusive of negative indices). Notice though that there is no
optional third argument for the step, which always defaults to |+1|.
\begin{everbatim*}
\xinttheiiexpr [1..20][6:13]\relax\ = \xinttheiiexpr [1..20][6-20:13-20]\relax
\end{everbatim*}
\item It is naturally possible to nest these things:
\begin{everbatim*}
\xinttheexpr [[1..50][13:37]][10:-10]\relax
\end{everbatim*}
\item itemwise operations either on the left or the right are possible:
\begin{everbatim*}
\xinttheiiexpr 123*[1..10]^2\relax
\end{everbatim*}
\begin{snugframed}
List operations are implemented using square brackets, but the |\xintiexpr|
and |\xintfloatexpr| parsers also check to see if an optional parameter
within brackets is specified before the start of the expression. To avoid the
resulting confusion if this |[| actually serves to delimit
comma separated values for list operations, one can either:\IMPORTANT{}
\begin{itemize}
\item insert something before the bracket such as |\empty| token,
\begin{everbatim*}
\xinttheiexpr \empty [1,3,6,99,100,200][2:4]\relax
\end{everbatim*}
\item use parentheses:
\begin{everbatim*}
\xinttheiexpr ([1,3,6,99,100,200][2:4])\relax
\end{everbatim*}
\end{itemize}
Notice though that |([1,3,6,99,100,200])[2:4]| would not work: it is
mandatory for |][| and |][:| not to be interspersed with parentheses. Spaces
are perfectly legal:
\begin{everbatim*}
\xinttheiexpr \empty[1..10 ] [ : 7 ]\relax
\end{everbatim*}
Similarly all the |+[|, |*[|, \dots and |]**|, |]/|, \dots operators admit
spaces but nothing else between their constituent characters.
\begin{everbatim*}
\xinttheiexpr \empty [ 1 . . 1 0 ] * * 1 1 \relax
\end{everbatim*}
\end{snugframed}
In an other vein, the parser will be confused by |1..[a,b,c][1]|, and one must
write |1..([a,b,c][1])|. And things such as |[100,300,500,700][2]//11| or
|[100,300,500,700][2]/11| are syntax errors and one must use parentheses, as
in |([100,300,500,700][2])/11|.
\end{itemize}
\subsection{Analogies and differences of \csbh{xintiiexpr} with \csbh{numexpr}}
\csbxint{iiexpr}|..\relax| is a parser of expressions knowing only (big)
integers. There are, besides the enlarged range of allowable inputs, some
important differences of syntax between |\numexpr| and |\xintiiexpr| and
variants:
\begin{itemize}
\item Contrarily to |\numexpr|, the |\xintiiexpr| parser will stop expanding
only after having encountered (and swallowed) a \emph{mandatory} |\relax|
token.
\item In particular, spaces between digits (and not only around infix
operators or parentheses) do not stop |\xintiiexpr|, contrarily to the
situation with |numexpr|: |\the\numexpr 7 + 3 5\relax| expands (in one step)
to \dtt{\detokenize\expandafter{\the\numexpr 7 + 3 5\relax}\unskip}, whereas
|\xintthe\xintiiexpr 7 + 3 5\relax| expands (in two steps) to
\dtt{\detokenize\expandafter\expandafter\expandafter {\xintthe\xintiiexpr 7
+ 3 5\relax}}.
\item Inside an |\edef|, expressions |\xintiiexpr...\relax| get fully
evaluated, but to a private format which needs the prefix \csbxint{the} to
get printed or used as arguments to some macros; on the other hand
expansion of |\numexpr| in an |\edef| occurs only if prefixed with |\the|
or |\number| (or |\romannumeral|, or the expression is included in a
bigger |\numexpr| which will be the one to have to be prefixed\dots .)
\item |\the\numexpr| or |\number\numexpr| expands in one step, but
|\xintthe\xintiiexpr| needs two steps.
\item The \csbxint{the} prefix should not be applied to a sub
|\xintiiexpr|ession, as this forces the parsers to gather again one by one
the corresponding digits.
\item Also worth mentioning is the fact that |\numexpr -(1)\relax| is illegal.
But |\xintiiexpr -(1)\relax| is perfectly legal and gives the expected
result (what else ?).
\end{itemize}
\section{The \xintname bundle}
\subsection{Characteristics}
\begin{framed}
The main characteristics are:
\begin{enumerate}
\item exact algebra on arbitrarily big numbers, integers as well as
fractions,
\item floating point variants with user-chosen precision,
\item implemented via macros compatible with expansion-only context,
\item and with a parser of infix operations implementing features such as
dummy variables, and coming in various incarnations depending on the kind
of computation desired: purely on integers, on integers and fractions, or
on floating point numbers.
\end{enumerate}
`Arbitrarily big' currently means with less than about \dtt{19950} digits: the
maximal
number of digits for addition is at \dtt{19968} digits,
and it is \dtt{19959} for multiplication.
\end{framed}
Integers with only $10$ digits and starting with a $3$ already exceed the
\TeX{} bound; and \TeX{} does not have a native processing of floating point
numbers (multiplication by a decimal number of a dimension register is allowed
--- this is used for example by the
\href{http://mirror.ctan.org/graphics/pgf/base}{pgf} basic math engine.)
\TeX{} elementary operations on numbers are done via the non-expandable
\emph{\char92advance, \char92multiply, \emph{and} \char92divide} assignments.
This was changed with \eTeX{}'s |\numexpr| which does expandable computations
using standard infix notations with \TeX{} integers. But \eTeX{} did not
modify the \TeX{} bound on acceptable integers, and did not add floating point
support.
The \href{http://www.ctan.org/pkg/bigintcalc}{bigintcalc} package by
\textsc{Heiko Oberdiek} provided expandable macros (using some of |\numexpr|
possibilities, when available) on arbitrarily big integers, beyond the \TeX{}
bound.%
%
\footnote{This package does not provide a parser of expressions on big
integers like \csbxint{iiexpr}|...\relax|. One can use package
\href{http://ctan.org/pkg/bnumexpr}{bnumexpr} to associate the |bigintcalc|
macros with an expression parser.}
%
The present package does this again, using more of |\numexpr| (\xintname
requires the \eTeX{} extensions) for higher speed, and also on fractions, not
only integers. Arbitrary precision floating points operations are a derivative,
and not the initial design goal.%
%
\footnote{currently (|1.08|), the only non-elementary operation
implemented for floating point numbers is the square-root extraction;
no signed infinities, signed zeroes, |NaN|'s, error traps\dots, have
been implemented, only the notion of `scientific notation with a given
number of significant figures'.}%
%
${}^{\text{,\,}}$%
%
\footnote{multiplication of two floats with |P=\xinttheDigits| digits is
first done exactly then rounded to |P| digits, rather than using a
specially tailored multiplication for floating point numbers which
would be more efficient (it is a waste to evaluate fully the
multiplication result with |2P| or |2P-1| digits.)}
The \LaTeX3 project has implemented expandably floating-point computations with
16 significant figures
(\href{http://www.ctan.org/pkg/l3kernel}{l3fp}), including
special functions such as exp, log, sine and cosine.\footnote{at the time of writing (2014/10/28) the
\href{http://www.ctan.org/pkg/l3kernel}{l3fp} (exactly represented) floating
point numbers have their exponents limited to $\pm$\dtt{9999}.}
%
More directly related to the \xintname bundle, there is the promising new
version of the \liiibigint{} package. It was still in development a.t.t.o.w
(2015/10/09, no division yet) and is part of the experimental trunk of the
\href{http://latex-project.org}{\LaTeX3 Project}. It is devoted to expandable
computations on big integers with an associated expression parser. Its author
(Bruno \textsc{Le Floch}) succeeded brilliantly into implementing expandably
the Karatsuba multiplication algorithm and he achieves \emph{sub-quadratic
growth for the computation time}. This shows up very clearly with numbers
having more than one thousand digits (up to the maximum which a.t.t.o.w was at
$8192$ digits).
I report here briefly on a quick comparison, although as \liiibigint{} is work
in progress, the reported results could well have to be modified soon. The
test was on a comparison of |\bigint_eval:n {#1*#2}| from the \liiibigint{} as
available in September 2015, on one hand, and on the other hand
|\xinttheiiexpr #1*#2\relax| from \xintexprname 1.2 (rather than directly
|\xintiiMul|, to be fairer to the parsing time induced by use of
|\bigint_eval:n|) and the computations were done with
|#1=#2=9999888877999988877...repeated...|. I observed:
\begin{itemize}
\item \csbxint{iiexpr}'s multiplication appears slightly faster (about |1.5x|
or |2x| to give an average order of magnitude) up to about
$900$ digits,
\item at $1000$ digits, \liiibigint{} runs between |15%| and |25%| faster,
\item then its sub-quadratic growth shows up, and at $8000$ digits I observed
it to be about |7.5x--9x| faster (I got quite varying results depending on
which computer the trial was conducted). Its computation time increased from
$1000$ digits to $8000$ digits by a factor smaller than |30|, whereas for
\csbxint{iiexpr} it was a factor only slightly inferior to |200| (|225| on
my laptop) ... Karatsuba multiplication brilliantly pays off !
\item One observes the transition at the powers of two for the \liiibigint{}
algorithm, for example I observed \liiibigint{} to be |3.5x--4x| faster at
$4000$ digits but only |3x--3.5x| faster at $5000$ digits.
\end{itemize}
Once one accepts a small overhead, one can on the basis of the lengths decide
for the best algorithm to use, and it is tempting viewing the above to imagine
that some mixed approach could combine the best of both. But again all this is
a bit premature as both packages may still evolve further.
Anyhow, all this being said, even the superior multiplication implementation
from \liiibigint{} takes of the order of seconds on my laptop for a single
multiplication of two $5000$-digits numbers. Hence it is not possible to do
routinely such computations in a document. I have long been thinking that
without the expandability constraint much higher speeds could be achieved, but
perhaps I have not given enough thought to sustain that optimistic
stance.\footnote{The \href{http://www.ctan.org/pkg/apnum}{apnum} package
implements (non-expandably) arbitrary precision fixed point algebra and (v1.6)
functions exp, log, sqrt, the trigonometrical direct and inverse functions.}
I remain of the opinion that if one really wants to do computations with
\emph{thousands} of digits, one should drop the expandability requirement.
Indeed, as clearly demonstrated long ago by the
\href{http://www.ctan.org/pkg/pi}{pi computing file} by \textsc{D. Roegel} one
can program \TeX{} to compute with many digits at a much higher speed than
what \xintname achieves: but, direct access to memory storage in one form or
another seems a necessity for this kind of speed and one has to renounce at
the complete expandability.%
%
\footnote{2015/09/15: as I said the latest developments on the \liiibigint{}
side do not really modify this conclusion, because the computations remain
extremely slow compared to what one can do in other programming structures.
Another remark one could do is that it would be tremendously easier to
enhance \eTeX{} than it is to embark into writing hundreds of lines of
sometimes very clever \TeX{} macro programming.}
%
\footnote{The Lua\TeX{} project possibly makes endeavours such as
\xintname appear even more insane that they are, in truth.}
\subsection{Floating point evaluations}
\label{ssec:floatingpoint}
Floating point macros are provided by package \xintfracname to work with a
given arbitrary precision |P|. The default value is $P=16$ meaning that the
significands of the produced (non-zero) numbers have $16$ decimal
digits.\footnote{Currently in the cases when the rounding to nearest goes to
the next power of ten, the result is |10.0....0eN| with |P-1| zeroes after
decimal mark, hence a total of |P+1|, not |P|, digits.} The syntax to set
the precision to |P| is
%
\centeredline{|\xintDigits:=P;|}
%
The value is local to the group or environment (if using \LaTeX). To query the
current value use \csbxint{theDigits}.
Most floating point macros accept an optional first argument |[P]| which then
sets the target precision and replaces the |\xintDigits| assigned
value.\footnote{the |[P]| must be repeated for the macro arguments, if
the latter are also \xintfracname macros with arguments of their own.}
\csbxint{floatexpr}|...\relax| also admits an optional argument |[Q]| but it
has an altogether different meaning: the computations are always done with the
prevailing |\xinttheDigits| precision and the optional argument says to round
the final result to |Q| digits of precision. This makes sense only if
|Q<\xinttheDigits| and is intended to clean up the result from dubious last
digits.
{\footnotesize
The maximal allowed value for |P| in a |\xintDigits:=P;| assignment is
\dtt{32767}. It was even possible earlier to use bigger |P|'s as optional
argument to \csbxint{Float} for a one-short conversion\MyMarginNote{Changed
with 1.2} to a gigantic float. However since release |1.2| this can't work
in complete generality: a fractional input will trigger internally the
division macro which can't handle arguments of more than about \dtt{19900}
digits. For example (tested 2015/11/07 with |1.2b|) |\message{\xintFloat
[19942]{1/7}}| works but not |\message{\xintFloat [19943]{1/7}}|. On the
other hand |\xintFloat [50000]{1}| does work (slowly..), but there isn't much
one can do afterwards with it...\par}
More reasonably, working with significands of $24$, $32$, $48$, $64$, or even
$80$ digits is well within the reach of the package.
\begin{framed}
% Floating point multiplication of two numbers with |P| digits of precision
% evaluates \emph{exactly} the exact product with |2P| or |2P-1| digits,
% before rounding to |P| digits: obviously this is very wasteful when |P| is
% large. But \xintname is initially an exact algebraic operator, not a
% floating point one with a fixed maximal size for operands, and the author
% hasn't yet had the opportunity to re-examine that point.
The |IEEE 754|\footnotemark\ requirement of \emph{correct rounding} for
addition, subtraction, multiplication, division and square root is achieved
(in arbitrary precision) by the macros of \xintfracname hence also
by the infix operators |+|, |-|, |*|, |/|
and |^| (which is synonym of |**|): this
means that for operands given with at most |P| significant digits (and
arbitrary exponents) the output coincides exactly with the rounding of an
exact evaluation (baring overflow or underflow).
The rounding mode is ``round to nearest, ties away from zero''.
It is not customizable.
Currently \xintfracname has no notion of |NaN|s or signed infinities or signed
zeroes, but this is intended for the future.
\end{framed}
\footnotetext{The |IEEE 754-1985| standard was for hardware implementations of
binary floating-point arithmetic with a specific value for the precision
($24$ bits for single precision, $53$ bits for double precision). The newer
{\texttt{IEEE 754-2008}}
(\url{https://en.wikipedia.org/wiki/IEEE_floating_point}) normalizes five
basic formats, three binaries and two decimals ($16$ and $34$ decimal
digits) and discusses extended formats with higher precision. These
standards are only indirectly relevant to libraries like \xintname dealing
with arbitrary precision.}
Currently, the only non-elementary operation is the square root. The
elementary transcendantal functions are not yet implemented. The power
function accepts integer and half-integer exponents.\footnote{Half-integer
exponents work only inside \csbxint{floatexpr}|...\relax| expressions, not
directly via the \csbxint{FloatPower} macro.}
The maximal theoretically allowed exponent is currently set at
\dtt{\number"7FFFFFFF} (the minimal exponent is its opposite) which is the
maximal number handled by \TeX. But this means that overflow or underflow are
detected only via low-level |\numexpr| arithmetic overflows which are
basically un-recoverable. Besides there are some border effects as the
routines need to add or subtract lengths of numbers from exponents, possibly
triggering the low-level overflows. In the future not only the Precision but
also the maximal and minimal exponents |Emin| and |Emax| will be specifiable
by the user.
\xintfracname is confronted with the problem that its float macros have to
handle inputs which not only may have much more digits than the target float
precision, but may even be fractions (which in a way means infinite
precision). As fractions should be handled as first class citizens, the float
macros should give the same result independently of whether an
argument is given as |A/B| or as |C/D| as long as |A/B=C/D| as rational numbers.
This was briefly the case when \xintfracname was first released, but very
shortly thereafter the fraction-to-float parsing (via \csbxint{Float}) was
modified for speed and as a result, currently this is not the case.%
%
\IMPORTANT{}\footnote{The author
had forgotten that the initial situation had been quickly modified, and for
some time this documentation wrongly asserted that the \xintfracname basic
floating point operations produced a value depending solely on the inputs as
abstract fractions.}
%
Next major release of \xintname packages will adopt a definitive model for
floats, and it will have the property above of handling fractions
intrinsically. Most probably this will go via first correctly rounding the
inputs (inclusive of arbitrary fractions) to the target precision.
The current situation is that for a fraction $A/B\cdot 10^N$ its numerator and
denominator are each first \emph{truncated} (not rounded, but that would not
change the issue) to |P+2| digits of precision if |P| is the asked-for
precision. Imagine that the original fraction was close to a boundary value
between rounding up or rounding down to a |P|-float. Changing even a tiny bit
the numerator and denominator moves the fraction, and as a result the rounding
to a |P|-float may be altered.
If $B=1$ there is no issue because
truncating to |P+2| digits then rounding to nearest |P|-float is like rounding
directly to nearest |P|-float (that would not have applied if we had first
rounded, not truncated, to a |P+2|-float). For $A=1$ on the contrary
the issue is already there. Here is an illustration of the problem:
\begin{everbatim*}
Precision: \xinttheDigits\par
\xintFloat {1/1858798855725191} ("reduced" fraction)\par
\xintFloat {5379818246175219/10000000000000000980336298241829} ("big" fraction)\par
We check that the fractions are identical:\par
\xinttheexpr 1/1858798855725191 - 5379818246175219/10000000000000000980336298241829\relax\par
And we also examine more digits of the decimal expansion:\par
\xinttheexpr trunc(1/1858798855725191, 48)\relax\dots\par
But truncating the denominator of the "big" fraction to 18 digits leads to:\par
\xinttheexpr trunc(5379818246175219/10000000000000000900000000000000, 48)\relax\dots\par
The two values rounded to 16 significant places differ.\par
\end{everbatim*}
Here is a summary of the situation regarding floats which was prevailing from
release |1.08a| to release |1.2e|. Next, we will explain the new situation
since |1.2f|.
\begin{itemize}
\item As explained above the |\xintFloat| macro which converts an input to a
P-float does the following in case of fraction $A/B[N]$: it truncates both
$A$ and $B$ to P+2 digits say $A'$ and $B'$ then computed the correct
rounding of $A'/B'$ to P digits. (not changed in |1.2f| and |1.2g|)
\item The |\xintFloatAdd|, |\xintFloatSub|, |\xintFloatMul|, |\xintFloatDiv|
routines each first rounded their inputs to P+2 digits (thus
applying the previous item, but with P replaced by P+2).
\item The |\xintFloatPow| and |\xintFloatPower| routines rounded their inputs
to Q > P+2 digits, with Q a temporary increased precision for intermediate
computations, then they rounded the end result to the asked-for P digits (in
the case of a negative exponent the final rounding was applied to something
of the |1/C| shape, up to powers of ten naturally).
\item The multiplication and division produced the correctly rounded value
from the (P+2)-rounded inputs. Thus, not only did these
routines produce the correctly rounded result for P-digits inputs, they
actually achieved it for (P+2)-digits inputs (again, for fractional inputs,
the initial rounding viciates any hope of having the final result be the
correctly rounded exact one).
\item For addition and subtraction having now to deal with $A.10^M\pm B.10^N$,
with $A$ and $B$ having (P+2) digits, the rule was that if $M-N\geqslant
P+4$, then $B$ was dropped altogether, if $N-M\geqslant P+4$ then $A$ was
dropped, else the operation was done exactly then rounded to P digits. But
in those cases where one of the summands was dropped, correct rounding was not
guaranteed, because say $A$ having P+2 digits could be at a
mid-point between two P-floats, thus neglecting $B$ (however small it may
be) could viciate the final rounding. Also, when adding $B=0$ to $A$, as $A$
is already the P+2 rounded original input, the final P-digit value could
end up not being the correct rounding of the original input (rounding to
nearest is not transitive; this is independent of the issues of handling
fractions as mentioned above).
\end{itemize}
For |1.2f| I have decided that the two digits added on input to the
asked-for precision by the
four basic operations do not make much sense after all.\IMPORTANT{} Especially
as since |1.2| the basic core operations are handled by blocks of eight
digits, this procedure was adding a systematic overhead for inputs already of
the default 16-digits precision, forcing computations as if for 24 digits.
Besides, when used in \cs{xintfloatexpr}, most of the time the inputs will
already be results of earlier computations hence have P digits. It appears
wasteful to extend them by two zeros prior to each operation.
Thus, |1.2f| adopts the policy that the inputs will always be rounded first to
P-floats, not (P+2)-floats.\CHANGED{1.2f} This does not change the behaviour
for inputs being already P-floats. All four operations then and now produce
the correctly rounded value. For coherence also the square root and the power
macros now first round their argument to a P-float.%
%
\footnote{The power macros do not aim at correct rounding, currently. But the
change fixes the issue that there was a possible difference between the
evaluation of |x*x| and |x^2| or |1/x| vs |x^-1| in the \csbxint{floatexpr}
parser due to the fact that in the latter cases |x| was initially rounded
to P+3 digits but in the former cases only to P+2 digits.}
%
Also,\NewWith {1.2f} |1.2f| has implemented \emph{correct rounding} (in
arbitrary precision) for the square root extraction.
What is yet lacking from |1.2f| (now |1.2g|) is the improved handling via
\csbxint{Float} of fractions to achieve independence from the chosen
representatives (which currently only applies if numerators and denominators
are of lengths at most the target precision plus two -- the exponent is
arbitrary).
Next major release will decide if this initial rounding of the inputs is kept;
the more ambitious model would be for the basic operations to compute the
correct rounding of the value corresponding to the original inputs, whatever
their original lengths\footnote{The |MPFR| library
\url{http://www.mpfr.org/} implements this ...}, or nature\footnote{... but it
does not know fractions!}. This is definitely feasible as \xintfracname
knows how to compute exactly, but the question is how efficiently though. I
don't think that this will be the choice made.
\subsection{Expansion matters}
\subsubsection{Generalities about expandability in \TeX}
\TeX{} is a macro language, and ``expansion'' is thus a crucial aspect, which
will be quite unfamiliar to most everyone with standard knowledge of the usual
programming languages. The whole of \xintname is about \emph{expandably}
implementing arithmetic computations. What does that mean ?
\LaTeX{} users are familiar with counters, and its command |\setcounter|. The
first argument is the name of the counter, the second argument is a number (in
the TeX sense of being acceptable in |\count| assignments), or more generally
something which will expand to a number. For example:
\begin{everbatim}
\newcounter{Foo}
\newcommand{\Bar}{17}
\setcounter{Foo}{\Bar}
\addtocounter{Foo}{\Bar}
\arabic{Foo}
\end{everbatim}
works and produces |34|. But imagine we have some macro |\Double| which
accepts a numerical string of digits, and outputs its double as a string of
digits (or perhaps some count with this value). Can we do this:
\begin{everbatim}
\setcounter{Foo}{\Double{\Bar}} ?
\end{everbatim}
The answer depends on the \emph{expandability} of |\Double|. Perhaps |\Double|
will do a |\newcommand| internally? or perhaps it used the \TeX{} primitives
|\advance| or |\multiply|? then it is \emph{not} expandable in this
context where \TeX{} is seeking to do a number assignment (which is
to what the \LaTeX{} |\setcounter| boils down in the end). This does not mean
that expansion does not apply, but something completely different: expansion
produces ``tokens'' which \TeX{} does not accept in such a context of
assigning a value to a |\count|.
Some users of \LaTeX{} know about the \TeX{} primitive |\edef|. Another way to
test expandability of |\Double| is to try |\edef\test{\Double{\Bar}}|: the
criterion is that |\Double| will expand, do its stuff, and clean up everything
and only leave the result of its action on |\Bar|. Thus typically if |\Double|
does a |\newcommand| (or rather a |\def|), then this will not be the case. The
|\newcommand| or |\def| simply does \emph{not} get executed inside an |\edef|!
This is not completely equivalent to the earlier context, because when \TeX{}
seeks to build a number it has additional special constructs, like |"| to
prefix hexadecimal inputs, and thus the behavior is not exactly the same in an
|\edef|, but I am just trying to give a gist here of what happens.
The little paradox is that \TeX{} from the start always required expandability
when doing assignments to count registers, or dimen registers, ..., but basic
arithmetic was provided via |\advance|, |\multiply|, and |\divide| primitives
which are \emph{not} expandable.%
%
\footnote{This is not to say that expandable arithmetic was not possible, it
is possible and has been done via the recording of the carries of digit
arithmetic in many macros and usage of some tools provided by the \TeX{}
language, but this is very cumbersome and slow (even in the \TeX{}
context).}
%
For example, something like
\begin{everbatim}
\setcounter{Foo}{\count0=\Bar\relax \multiply\count0 by 2
\advance\count0 by 15 \the\count0 }
\end{everbatim}
although not creating errors produces only non-sense.
Since 1999, \eTeX{} has extended \TeX{} with expandable arithmetic. Thus
nowadays%
%
\footnote{I do not discuss here the \href{http://www.ctan.org/pkg/calc}{calc}
package. It does surgery inside |\setcounter| to make
|\setcounter{Foo}{2*\Bar+15}| possible, but its parser is not expandable and
is functional only inside macros |calc| knows about.} one would simply do
\begin{everbatim}
\setcounter{Foo}{\numexpr 2*\Bar+15\relax}
\end{everbatim}
But we can not do, for example, |98765*67890| inside |\numexpr|, because the
result \xintiiMul{98765}{67890} exceeds the \TeX{} bound of \number"7FFFFFFF.
\subsubsection{Full expansion of the first token}
\label{ssec:expansions}
The whole business of \xintname is to build upon |\numexpr| and handle
arbitrarily large numbers. Each basic operation is thus done via a macro:
\csbxint{iiAdd}, \csbxint{iiSub}, \csbxint{iiMul}, \csbxint{iiDivision}. In
order to handle more complex operations, it must be possible to nest these
macros.%
%
\footnote{Actually this would not be really needed if the goal was only
to implement the parsing of expressions: as the expression is scanned from
left to right, there is only at any given time one operation to be done, hence
it is not really absolutely mandatory for the macros implementing the basic
operations to be nestable. This is however the path followed initially by
\xintname.}
%
But we saw already that an expandable macro can not do a |\newcommand| or
|\def|, and it can't do either an |\edef|. But the macro must expand its
arguments to find the digits it is supposed to manipulate. \TeX{} provides a
tool to do the job of (expandable !) repeated expansion of the first token
found until hitting something non expandable, such as a digit, a |\def| token,
a brace, a |\count| token, etc... is found. A space token also will stop the
expansion (and be swallowed, contrarily to the non-expandable tokens).
By convention in this manual \fexpan sion (``full expansion'' or ``full first
expansion'') will be this \TeX{} process of expanding repeatedly the first
token seen. For those familiar with \LaTeX3 (which is not used by \xintname)
this is what is called in its documentation full expansion (whereas expansion
inside |\edef| would be described I think as ``exhaustive'' expansion).
Most of the package macros, and all those dealing with computations%
%
\footnote{except \csbxint{XTrunc}.},
%
are expandable in the strong sense that they expand to their final result via
this \fexpan sion. This will be signaled in their descriptions via a
\etype{}star in the margin.
These macros not only have this property of \fexpan dability, they all begin
by first applying \fexpan sion to their arguments. Again from \LaTeX3's
conventions this will be signaled by a%
%
\ntype{{\setbox0 \hbox{\Ff}\hbox to \wd0 {\hss f\hss}}}
%
margin annotation next to the description of the arguments.
\subsubsection{Summary of important expandability aspects}
\begin{enumerate}
\item the macros \fexpan d their arguments, this means that they expand the
first token seen (for each argument), then expand, etc..., until something
un-expandable such as a\strut{} digit or a brace is hit against. This
example
%
\leftedline{|\def\x{98765}\def\y{43210}| |\xintiiAdd {\x}{\x\y}|}
%
is \emph{not} a legal construct, as the |\y| will remain untouched by
expansion and not get converted into the digits which are expected by the
sub-routines of |\xintiiAdd|. It is a |\numexpr| which will expand it and an
arithmetic overflow will arise as |9876543210| exceeds the \TeX{} bounds.
The same would hold for |\xintAdd|.
\begingroup\slshape
To the contrary \csbxint{theiiexpr} and others have no issues with
things such as |\xinttheiiexpr \x+\x\y\relax|.\hfill
\endgroup
\item\label{fn:expansions} using |\if...\fi| constructs \emph{inside} the
package macro arguments requires suitably mastering \TeX niques
(|\expandafter|'s and/or swapping techniques) to ensure that the \fexpan sion
will indeed absorb the \csa{else} or closing \csa{fi}, else some error will
arise in further processing. Therefore it is highly recommended to use the
package provided conditionals such as \csbxint{ifEq}, \csbxint{ifGt},
\csbxint{ifSgn}, \csbxint{ifOdd}\dots, or, for \LaTeX{} users and when dealing
with short integers the
\href{http://www.ctan.org/pkg/etoolbox}{etoolbox}%
%
\footnote{\url{http://www.ctan.org/pkg/etoolbox}}
expandable conditionals (for small integers only) such as \texttt{\char92
ifnumequal}, \texttt{\char92 ifnumgreater}, \dots . Use of
\emph{non-expandable} things such as \csa{ifthenelse} is impossible inside the
arguments of \xintname macros.
\begingroup\slshape
One can use naive |\if..\fi| things inside an \csbxint{theexpr}-ession
and cousins, as long as the test is
expandable, for example\upshape
%
\leftedline{|\xinttheiexpr\ifnum3>2 143\else 33\fi
0^2\relax|$\to$\dtt{\xinttheiexpr \ifnum3>2 143\else 33\fi 0^2\relax
=1430\char`\^2}}
%
\endgroup
\item after the definition |\def\x {12}|, one can not use
{\color{blue}|-\x|} as input to one of the package macros: the \fexpan sion
will act only on the minus sign, hence do nothing. The only way is to use the
\csbxint{Opp} macro, or perhaps here rather \csbxint{iOpp} which does
maintains integer format on output, as they replace a number with
its opposite.
\begingroup\slshape
Again, this is otherwise inside an \csbxint{theexpr}-ession or
\csbxint{thefloatexpr}-ession. There, the
minus sign may prefix macros which will expand to numbers (or parentheses
etc...)
\endgroup
\def\x {12}%
\def\AplusBC #1#2#3{\xintAdd {#1}{\xintMul {#2}{#3}}}%
\item \label{item:xpxp} With the definition
%
\leftedline{|\def\AplusBC #1#2#3{\xintAdd {#1}{\xintMul {#2}{#3}}}|}
%
one obtains an
expandable macro producing the expected result, not in two, but rather in
three steps: a first expansion is consumed by the macro expanding to its
definition. As the package macros expand their arguments until no more is
possible (regarding what comes first), this |\AplusBC| may be used inside
them: {|\xintAdd {\AplusBC {1}{2}{3}}{4}|} does work and returns
\dtt{\xintAdd {\AplusBC {1}{2}{3}}{4}}.
If, for some reason, it is important to create a macro expanding in two steps
to its final value, one may either do:
%
\smallskip
%
\leftedline {|\def\AplusBC #1#2#3{\romannumeral-`0\xintAdd {#1}{\xintMul
{#2}{#3}}}|}
%
or use the \emph{lowercase} form of \csa{xintAdd}:
%
\smallskip
%
\leftedline {|\def\AplusBC #1#2#3{\romannumeral0\xintadd {#1}{\xintMul
{#2}{#3}}}|}
and then \csa{AplusBC} will share the same properties as do the
other \xintname `primitive' macros.
\item
The |\romannumeral0| and |\romannumeral-`0| things above look like an invitation
to hacker's territory; if it is not important that the macro expands in two
steps only, there is no reason to follow these guidelines. Just chain
arbitrarily the package macros, and the new ones will be completely expandable
and usable one within the other.
Since release |1.07| the \csbxint{NewExpr} command automatizes the creation of
such expandable macros:
%
\leftedline{|\xintNewExpr\AplusBC[3]{#1+#2*#3}|}
%
creates the |\AplusBC| macro doing the above and expanding in two expansion
steps.
\item In the expression parsers of \xintexprname such as
\csbxint{expr}|..\relax|, \csbxint{floatexpr}|..\relax| the contents are
expanded completely from left to right until the ending |\relax| is found
and swallowed, and spaces and even (to some extent) catcodes do not matter.
\item For all variants, prefixing with \csbxint{the} allows to print the
result or use it in other contexts. Shortcuts \csbxint{theexpr},
\csbxint{thefloatexpr}, \csbxint{theiiexpr}, \dots\ are available.
\end{enumerate}
\subsection{User interface}
\label{ssec:userinterface}
The next sections will explain the various inputs which are recognized by the
package macros and the format for their outputs. Inputs have mainly five
possible shapes:
\begin{enumerate}
\item expressions which will end up inside a |\numexpr..\relax|,
\item long integers in the strict format (no |+|, no leading zeroes, a count
register or variable must be prefixed by |\the| or |\number|)
\item long integers in the general format allowing both |-| and |+| signs, then
leading zeroes, and a count register or variable without prefix is allowed,
\item fractions with numerators and denominators as in the
previous item, or also decimal numbers, possibly in scientific notation (with
a lowercase |e|), and
also optionally the semi-private |A/B[N]| format,
\item and finally expandable material understood by the |\xintexpr| parser.
\end{enumerate}
Outputs are mostly of the following types:
\begin{enumerate}
\item long integers in the strict format,
\item fractions in the |A/B[N]| format where |A| and |B| are both strict long
integers, and |B| is positive,
\item numbers in scientific format (with a lowercase |e|),
\item the private |\xintexpr| format which needs the |\xintthe| prefix in order
to end up on the printed page (or get expanded in the log)
or be used as argument to the package macros.
\end{enumerate}
\subsection{No declaration of variables for macros}
There is no notion of a \emph{declaration of a variable}, which would be
needed to use the arithmetic macros.%
To do a computation and assign its result to some macro |\z|, the user will employ the |\def|, |\edef|, or |\newcommand| (in \LaTeX)
as usual, keeping in mind that two expansion steps are needed, thus |\edef|
is initially the main tool:
%
\begin{everbatim*}
\def\x{1729728} \def\y{352827927} \edef\z{\xintiiMul {\x}{\y}}
\meaning\z
\end{everbatim*}
As an alternative to |\edef| the package provides |\oodef| which expands
exactly twice the replacement text, and |\fdef| which applies \fexpan sion to
the replacement text during the definition.
\begin{everbatim*}
\def\x{1729728} \def\y{352827927} \oodef\w {\xintiiMul\x\y} \fdef\z{\xintiiMul {\x}{\y}}
\meaning\w, \meaning\z
\end{everbatim*}
In practice |\oodef| is slower than |\edef|, except for computations ending in
very big final replacement texts (thousands of digits). On the other hand
|\fdef|\IMPORTANT{} appears to be slightly faster than |\edef| already in the
case of expansions leading to only a few dozen digits.
\xintexprname does provide an interface to declare and assign values to
identifiers which can then be used in expressions: \autoref{xintdefvar}.
\subsection {Input formats}\label{sec:inputs}
Some macro arguments are by nature `short' integers,\ntype{\numx} \emph{i.e.}
less than (or equal to) in absolute value \np{\number "7FFFFFFF}. This is
generally the case for arguments which serve to count or index something. They
will be embedded in a |\numexpr..\relax| hence on input one may even use count
registers or variables and expressions with infix operators. Notice though that
|-(..stuff..)| is surprisingly not legal in the |\numexpr| syntax!
But \xintname is mainly devoted to big numbers;
the allowed input formats for `long numbers' and `fractions' are:
\begin{enumerate}
\item the strict format\ntype{f} is for some macros of \xintname which only
\fexpan d their arguments. After this \fexpan sion the input should be a
string of digits, optionally preceded by a unique minus sign. The first
digit can be zero only if the number is zero. A plus sign is not accepted.
|-0| is not legal in the strict format. A count register can serve as
argument of such a macro only if prefixed by |\the| or |\number|. Macros of
\xintname such as \csbxint{iiAdd} with a double |ii| require this `strict'
format for the inputs. The macros such as \csbxint{iAdd} with a single |i|
will apply the \csbxint{Num} normalizer described in the next item.
\item the macro \csbxint{Num} normalizes into strict format an input having
arbitrarily many minus and plus signs, followed by a string of zeroes, then
digits:%
%
\leftedline{|\xintNum
{+-+-+----++-++----00000000009876543210}|\dtt{=\xintNum
{+-+-+----++-++----0000000009876543210}}}
%
The extended integer format\ntype{\Numf} is thus for the arithmetic macros
of \xintname which automatically parse their arguments via this
\csbxint{Num}.%
%
\footnote{A
\LaTeX{} |\value{countername}| is accepted as macro
argument.}
\item the fraction format\ntype{\Ff} is what is expected on input by the
macros of \xintfracname. It has two variants:
\begin{description}
\item[general:] these are inputs of the shape |A.BeC/D.EeF|. Example:
\begin{everbatim*}
\noindent\xintRaw{+--0367.8920280e17/-++278.289287e-15}\newline
\xintRaw{+--+1253.2782e++--3/---0087.123e---5}\par
\end{everbatim*}
Notice that the input process does not reduce fractions to smallest terms.
Here are the rules of the format:\footnote{Earlier releases were slightly
more strict, the optional decimal parts |B|, |E| were not individually
\fexpan ded.}
\begin{itemize}
\item everything is optional, absent numbers are treated as zero, here are
some extreme cases:
\begin{everbatim*}
\xintRaw{}, \xintRaw{.}, \xintRaw{./1.e}, \xintRaw{-.e}, \xintRaw{e/-1}
\end{everbatim*}
\item |AB| and |DE| may start with pluses and minuses, then leading
zeroes, then digits.
\item |C| and |F| will be given to |\numexpr| and can be anything
recognized as such and not provoking arithmetic overflow (the lengths of
|B| and |E| will also intervene to build the final exponent naturally
which must obey the \TeX{} bound).
\item the |/|, |.| (numerator and/or denominator) and |e|
(numerator and/or denominator) are all optional components.
\item each of |A|, |B|, |C|, |D|, |E| and |F| may arise from \fexpan sion
of a macro.
\item the whole thing may arise from \fexpan sion, however the |/|, |.|,
and |e| should all come from this initial expansion. The |e| of
scientific notation is mandatorily lowercased.
\end{itemize}
\item[restricted:] these are inputs either of the shape |A[N]| or |A/B[N]|
(representing the fraction |A/B| times |10^N|) where the whole thing or
each of |A|, |B|, |N| (but then not |/| or |[|) may arise from \fexpan
sion, |A| (after expansion) \emph{must} have a unique optional minus sign
and no leading zeroes, |B| (after expansion) if present \emph{must} be a
positive integer with no signs and no leading zeroes, |[N]| if present
will be given to |\numexpr|. This format is parsed with smaller
overhead than the general one, thus allowing more efficient nesting of
macros as it is the one used on output (except for the floating macros).
Any deviation from the rules above will result in errors.\footnote{With
releases earlier than |1.2| the |N| had to be necessarily
given as explicit digits, not some macro or expression expanded in
|\numexpr|. From |1.2| to |1.2e| an empty |N| was allowed, but |1.2f|
removed that.}
\end{description}
Notice that |*|, |+| and |-| contrarily to the |/| (which is treated simply
as a kind of delimiter) are not acceptable within arguments of this
type\ntype{\Ff}
(see however \autoref{sec:useofcount} for some exceptions).
\item the \hyperref[xintexpr]{expression format} is for inclusion in an
\csbxint{expr}|...\relax|, it uses infix notations, function names, complete
expansion, recognizes decimal and scientific numbers, and is described in
\autoref{sec:xintexprsyntax} and \autoref{ssec:syntax}.%
%
\footnote{Starting with release |1.2|, the isolated dot |"."| is not legal
anymore in expressions: there must be digits either before or after.}
\end{enumerate}
Generally speaking, there should be no spaces among the digits in the inputs
(in arguments to the package macros). Although most would be harmless in most
macros, there are some cases where spaces could break havoc.%
\footnote{The \csbxint{Num} macro does not remove spaces between digits beyond
the first non zero ones; however this should not really alter the subsequent
functioning of the arithmetic macros, and besides, since \xintcorename 1.2
there is an initial parsing of the entire number, during which spaces will
be gobbled. However I have not done a complete review of the legacy code to
be certain of all possibilities after |1.2| release. One thing to be aware
of is that \csa{numexpr} stops on spaces between digits (although it
provokes an expansion to see if an infix operator follows); the exponent for
\csbxint{iiPow} or the argument of the factorial \csbxint{iFac} are only
subjected to such a \csa{numexpr} (there are a few other macros with such
input types in \xintname). If the input is given as, say |1 2\x| where
\csa{x} is a macro, the macro \csa{x} will not be expanded by the
\csa{numexpr}, and this will surely cause problems afterwards. Perhaps a
later \xintname will force \csa{numexpr} to expand beyond spaces, but I
decided that was not really worth the effort. Another immediate cause of
problems is an input of the type |\xintiiAdd{<space>\x}{\y}|, because the
space will stop the initial expansion; this will most certainly cause an
arithmetic overflow later when the \csa{x} will be expanded in a
\csa{numexpr}. Thus in conclusion, damages due to spaces are unlikely if
only explicit digits are involved in the inputs, or arguments are single
macros with no preceding space.}
So the best is to avoid them entirely.
This is entirely otherwise inside an |\xintexpr|-ession, where spaces are
ignored (except when they occur inside arguments to some macros, thus
escaping the |\xintexpr| parser). See the \hyperref[sec:expr]{documentation}.
Arithmetic macros of \xintname which parse their arguments automatically through
\csbxint{Num} are signaled by a special
symbol%\ntype{\Numf{\unskip\kern\dimexpr\FrameSep+\FrameRule\relax}}
\ntype{\Numf} in the margin. This symbol also means that these arguments may
contain to some extent infix algebra with count registers, see the section
\hyperref[sec:useofcount]{Use of count registers}.
With \xintfracname loaded the symbol \smash{\Numf} means that a fraction is
accepted if it is a whole number in disguise; and for macros accepting the
full fraction format with no restriction there is the corresponding symbol
in the margin\ntype{\Ff}.
%
There are also some slighly more obscure expansion types: in particular, the
\csbxint{ApplyInline} and \csbxint{For*} macros from \xinttoolsname apply a
special iterated \fexpan sion, which gobbles spaces, to the non-braced items
(braced items are submitted to no expansion because the opening brace stops
it) coming from their list argument; this is denoted by a special
symbol\ntype{{\lowast f}} in the margin. Some other macros such as
\csbxint{Sum} from \xintfracname first do an \fexpan sion, then treat each
found (braced or not) item (skipping spaces between such items) via the
general fraction input parsing, this is signaled as
here\ntype{f{$\to$}{\lowast\Ff}} in the margin where the signification of the
\lowast{} is thus a bit different from the previous case.
A few macros from \xinttoolsname do not expand, or expand only once their
argument\ntype{n{{\color{black}\upshape, resp.}} o}. This is also
signaled in the margin with notations \`a la \LaTeX3.
As the computations are done by \fexpan dable macros which \fexpan d their
argument they may be chained up to arbitrary depths and still produce expandable
macros.
Conversely, wherever the package expects on input a ``big'' integers, or a
``fraction'', \fexpan sion of the argument \emph{must result in a complete
expansion} for this argument to be acceptable.%
%
\footnote{this is not quite as
stringent as claimed here, see \autoref{sec:useofcount} for more details.}
The
main exception is inside \csbxint{expr}|...\relax| where everything will be
expanded from left to right, completely.
\subsection{Output formats}
Package \xintcorename provides macros \csbxint{iiAdd}, \csbxint{iiSub},
\csbxint{iiMul}, \csbxint{iiPow}, which only \fexpan d their arguments and
\csbxint{iAdd}, \csbxint{iSub}, \csbxint{iMul}, \csbxint{iPow} which
normalize them first to strict format, thus have a bit of overhead. These
macros always produce integers on output.
With \xintfracname loaded \csbxint{iiAdd}, \csbxint{iiSub}, \csbxint{iiMul},
... are not modified, and \csbxint{iAdd}, \csbxint{iSub}, \csbxint{iMul}, ...
are only extended to the extent of accepting fraction inputs but they will be
truncated to integers.%
%
\footnote{the power function does not accept a fractional exponent. Or rather,
does not expect, and errors will result if one is provided.}
%
The output will be an integer.
\begin{framed}
The fraction handling macros from \xintfracname are called \csbxint{Add},
\csbxint{Sub}, \csbxint{Mul}, etc... they are \emph{not} defined in the
absence of \xintfracname.\MyMarginNote[\kern\dimexpr\FrameSep+\FrameRule\relax]{Changed!}
They produce on output a fractional number |f=A/B[n]| (which stands for
|(A/B)|$\times$|10^n|) where |A| and |B| are integers, with |B| positive,
and |n| is a ``short'' integer (\emph{i.e} less in absolute value than
\dtt{\number"7FFFFFFF}.)
The output fraction is not reduced to smallest terms. The |A| and |B| may
end in zeroes (\emph{i.e}, |n| does not represent all powers of ten). The
denominator |B| is always strictly positive. There is no |+| sign on output
but only possibly a |-| at the numerator. The output will be expressed as
a fraction even if the inputs are both integers.
\end{framed}
\begin{itemize}
\item A macro \csbxint{Frac} is provided for the typesetting (math-mode
only) of such a `raw' output. The command \csbxint{Frac} is not accepted as
input to the package macros, it is for typesetting only (in math mode).
\item \csbxint{Raw} prints the fraction directly as its internal
representation |A/B[n]|.
\begin{everbatim*}
$\xintRaw{273.3734e5/3395.7200e-2}=\xintFrac {273.3734e5/3395.7200e-2}$
\end{everbatim*}
\item \csbxint{PRaw} does the same but without printing the |[n]| if |n=0| and
without printing |/1| if |B=1|.
\item \csbxint{Irr} reduces the fraction to its irreducible form |C/D|
(without a trailing |[0]|), and it prints the |D| even if |D=1|.
\begin{everbatim*}
$\xintIrr{273.3734e5/3395.7200e-2}$
\end{everbatim*}
\item \csbxint{Num} from package \xintname becomes when \xintfracname is
loaded a synonym to its macro \csbxint{TTrunc} (same as
\csbxint{iTrunc}|{0}|) which truncates to the nearest integer.
\item See also the documentations of \csbxint{Trunc}, \csbxint{iTrunc},
\csbxint{XTrunc}, \csbxint{Round}, \csbxint{iRound} and \csbxint{Float}.
\item The \csbxint{iAdd}, \csbxint{iSub}, \csbxint{iMul}, \csbxint{iPow}
macros and some others accept fractions on input which they truncate via
\csbxint{TTrunc}. On output they still produce an integer with no fraction
slash nor trailing |[n]|.
\item The \csbxint{iiAdd}, \csbxint{iiSub}, \csbxint{iiMul}, \csbxint{iiPow},
and others with `\textcolor{blue}{ii}' in their names accept on input only
integers in the strict format. They skip the overhead of the \csbxint{Num}
parsing and naturally they output integers, with no fraction slash nor
trailing |[n]|.
\end{itemize}
Some macros return a token list of two or more numbers or fractions; they are
then each enclosed in braces. Examples are \csbxint{iiDivision} which gives
first the quotient and then the remainder of euclidean division,
\csbxint{Bezout} from the \xintgcdname package which outputs five numbers,
\csbxint{FtoCv} from the \xintcfracname package which returns the list of the
convergents of a fraction, ... \autoref{sec:assign} and \autoref{sec:utils}
mention utilities, expandable or not, to cope with such outputs.
Another type of multiple number output is when using commas inside
\csbxint{expr}|..\relax|:
%
\leftedline{|\xinttheiexpr 10!,2^20,lcm(1000,725)\relax|%
$\to$\dtt{\xinttheiexpr 10!,2^20,lcm(1000,725)\relax}}
This returns a comma separated list, with a space after each comma.
\subsection{Use of count registers}\label{sec:useofcount}
Inside |\xintexpr..\relax| and its variants, a count register or count control
sequence is automatically unpacked using |\number|, with tacit multiplication:
|1.23\counta| is like |1.23*\number\counta|. There
is a subtle difference between count \emph{registers} and count
\emph{variables}. In |1.23*\counta| the unpacked |\counta| variable defines a
complete operand thus |1.23*\counta 7| is a syntax error. But |1.23*\count0|
just replaces |\count0| by |\number\count0| hence |1.23*\count0 7| is like
|1.23*57| if |\count0| contains the integer value |5|.
Regarding now the package macros, there is first the case of arguments having to
be short integers: this means that they are fed to a |\numexpr...\relax|, hence
submitted to a \emph{complete expansion} which must deliver an integer, and
count registers and even algebraic expressions with them like
|\mycountA+\mycountB*17-\mycountC/12+\mycountD| are admissible arguments (the
slash stands here for the rounded integer division done by |\numexpr|). This
applies in particular to the number of digits to truncate or round with, to the
indices of a series partial sum, \dots
The macros allowing the extended format for long numbers or dealing with
fractions will \emph{to some extent} allow the direct use of count
registers and even infix algebra inside their arguments: a count
register |\mycountA| or |\count 255| is admissible as numerator or also as
denominator, with no need to be prefixed by |\the| or |\number|. It is possible
to have as argument an algebraic expression as would be acceptable by a
|\numexpr...\relax|, under this condition: \emph{each of the numerator and
denominator is expressed with at most \emph{eight}
tokens}.%
%
\footnote{Attention! there is no problem with a \LaTeX{}
\csa{value}\texttt{\{countername\}} if if comes first, but if it comes later
in the input it will not get expanded, and braces around the name will be
removed and chaos\IMPORTANT{} will ensue inside a \csa{numexpr}. One should
enclose the whole input in \csa{the}\csa{numexpr}|...|\csa{relax} in such
cases.}
%
The slash for rounded division in a |\numexpr| should be written with
braces |{/}| to not be confused with the \xintfracname delimiter between
numerator and denominator (braces will be removed internally). Example:
|\mycountA+\mycountB{/}17/1+\mycountA*\mycountB|, or |\count 0+\count
2{/}17/1+\count 0*\count 2|, but in the latter case the numerator has the
maximal allowed number of tokens (the braced slash counts for only one).
%
\leftedline{|\cnta 10 \cntb 35 \xintRaw
{\cnta+\cntb{/}17/1+\cnta*\cntb}|\dtt{->\cnta 10 \cntb 35 \xintRaw
{\cnta+\cntb{/}17/1+\cnta*\cntb}}}
%
For longer algebraic expressions using
count registers, there are two possibilities:
\begin{enumerate}
\item encompass each of the numerator and denominator in |\the\numexpr...\relax|,
\item encompass each of the numerator and denominator in |\numexpr {...}\relax|.
\end{enumerate}
\everb|@
\cnta 100 \cntb 10 \cntc 1
\xintPRaw {\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc+
2*\cnta*\cntb+2*\cnta*\cntc+2*\cntb*\cntc}\relax/%
\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc}\relax }
|
\cnta 100 \cntb 10 \cntc 1
%
\leftedline{\dtt{\xintPRaw {\numexpr
{\cnta*\cnta+\cntb*\cntb+\cntc*\cntc+
2*\cnta*\cntb+2*\cnta*\cntc+2*\cntb*\cntc}\relax/%
\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc}\relax }}}
%
The braces would not be accepted
as regular
|\numexpr|-syntax: and indeed, they
are removed at some point in the processing.
\subsection{Dimensions}
\label{sec:Dimensions}
\meta{dimen} variables can be converted into (short) integers suitable for the
\xintname macros by prefixing them with |\number|. This transforms a dimension
into an explicit short integer which is its value in terms of the |sp| unit
($1/65536$\,|pt|).
When |\number| is applied to a \meta{glue} variable, the stretch and shrink
components are lost.
For \LaTeX{} users: a length is a \meta{glue} variable, prefixing a
length command defined by \csa{newlength} with \csa{number} will thus discard
the |plus| and |minus| glue components and return the dimension component as
described above, and usable in the \xintname bundle macros.
This conversion is done automatically inside an
|\xintexpr|-essions, with tacit multiplication implied if prefixed by some
(integral or decimal) number.
One may thus compute areas or volumes with no limitations, in units of |sp^2|
respectively |sp^3|, do arithmetic with them, compare them, etc..., and possibly
express some final result back in another unit, with the suitable conversion
factor and a rounding to a given number of decimal places.
A \hyperref[tableofdimensions]{table of dimensions} illustrates that the
internal values used by \TeX{} do not correspond always to the closest rounding.
For example a millimeter exact value in terms of |sp| units is
\dtt{72.27/10/2.54*65536=\xinttheexpr trunc(72.27/10/2.54*65536,3)\relax
...} and \TeX{} uses internally \dtt{\number\dimexpr 1mm\relax}|sp| (it
thus appears that \TeX{} truncates to get an integral multiple of the |sp|
unit).
\begin{figure*}[ht!]
\phantomsection\label{tableofdimensions}
\begingroup\let\ignorespaces\empty
\let\unskip\empty
\def\T{\expandafter\TT\number\dimexpr}
\def\TT#1!{\gdef\tempT{#1}}
\def\E{\expandafter\expandafter\expandafter
\EE\xintexpr reduce(}
\def\EE#1!{\gdef\tempE{#1}}
\centeredline{\begin{tabular}{%
>{\bfseries\strut}c%
c%
>{\E}c<{)\relax!}@{}%
>{\xintthe\tempE}r@{${}={}$}%
>{\xinttheexpr trunc(\tempE,3)\relax...}l%
>{\T}c<{!}@{}%
>{\tempT}r%
>{\xinttheexpr round(100*(\tempT-\tempE)/\tempE,4)\relax\%}c}
\hline
Unit&%
definition&%
\omit &%
\multicolumn{2}{c}{Exact value in \texttt{sp} units\strut}&%
\omit &%
\omit\parbox{2cm}{\centering\strut\TeX's value in \texttt{sp} units\strut}&%
\omit\parbox{2cm}{\centering\strut Relative error\strut}\\\hline
cm&0.01 m&72.27/2.54*65536&&&1cm&&\\
mm&0.001 m&72.27/10/2.54*65536&&&1mm&&\\
in&2.54 cm&72.27*65536&&&1in&&\\
pc&12 pt&12*65536&&&1pc&&\\
pt&1/72.27 in&65536&&&1pt&&\\
bp&1/72 in&72.27*65536/72&&&1bp&&\\
\omit\hfil\llap{3}bp\hfil&1/24 in&72.27*65536/24&&&3bp&&\\
\omit\hfil\llap{12}bp\hfil&1/6 in&72.27*65536/6&&&12bp&&\\
\omit\hfil\llap{72}bp\hfil&1 in&72.27*65536&&&72bp&&\\
dd&1238/1157 pt&1238/1157*65536&&&1dd&&\\
\omit\hfil\llap{11}dd\hfil&11*1238/1157 pt&11*1238/1157*65536&&&11dd&&\\
\omit\hfil\llap{12}dd\hfil&12*1238/1157 pt&12*1238/1157*65536&&&12dd&&\\
sp&1/65536 pt&1&&&1sp&&\\\hline
\multicolumn{8}{c}{\bfseries\large\TeX{} \strut dimensions}\\\hline
\end{tabular}}
\endgroup
\end{figure*}
There is something quite amusing with the Didot point. According to the \TeX
Book, $1157$\,|dd|=$1238$\,|pt|. The actual internal value of $1$\,|dd| in \TeX{} is $70124$\,|sp|. We can use \xintcfracname to display the list of
centered convergents of the fraction $70124/65536$:
%
\leftedline{|\xintListWithSep{, }{\xintFtoCCv{70124/65536}}|}
%
\xintFor* #1 in {\xintFtoCCv{70124/65536}}\do {$\printnumber{#1}$, }%
and we don't find
$1238/1157$ therein, but another approximant $1452/1357$!
And indeed multiplying $70124/65536$ by $1157$, and respectively $1357$, we find
the approximations (wait for more, later):
%
\leftedline{``$1157$\,|dd|''\dtt{=\xinttheexpr trunc(1157\dimexpr
1dd\relax/\dimexpr 1pt\relax,12)\relax}\dots|pt|}
%
\leftedline{``$1357$\,|dd|''\dtt{=\xinttheexpr trunc(1357\dimexpr
1dd\relax/\dimexpr 1pt\relax,12)\relax}\dots|pt|}
%
and we seemingly discover that $1357$\,|dd|=$1452$\,|pt| is \emph{far more
accurate} than
the \TeX Book formula $1157$\,|dd|=$1238$\,|pt|~!
The formula to compute $N$\,|dd| was
%
\leftedline{|\xinttheexpr trunc(N\dimexpr 1dd\relax/\dimexpr
1pt\relax,12)\relax}|}
%
What's the catch? The catch is that \TeX{} \emph{does not} compute $1157$\,|dd|
like we just did:%
%
\leftedline{$1157$\,|dd|=|\number\dimexpr 1157dd\relax/65536|%
\dtt{=\xintTrunc{12}{\number\dimexpr 1157dd\relax/65536}}\dots|pt|}
%
\leftedline{$1357$\,|dd|=|\number\dimexpr 1357dd\relax/65536|%
\dtt{=\xintTrunc{12}{\number\dimexpr 1357dd\relax/65536}}\dots|pt|}
%
We thus discover that \TeX{} (or rather here, e-\TeX{}, but one can check that
this works the same in \TeX82), uses indeed $1238/1157$ as a conversion
factor, and necessarily intermediate computations are done with more precision
than is possible with only integers less than $2^{31}$ (or $2^{30}$ for
dimensions). Hence the $1452/1357$ ratio is irrelevant, a misleading artefact
of the necessary rounding (or, as we see, truncating) for one |dd| as an
integral number of |sp|'s.
Let us now
use |\xintexpr| to compute the value of the Didot point in millimeters, if
the above rule is exactly verified:
%
\leftedline{|\xinttheexpr
trunc(1238/1157*25.4/72.27,12)\relax|%
\dtt{=\xinttheexpr trunc(1238/1157*25.4/72.27,12)\relax}|...mm|}
%
This fits very well with the possible values of the Didot point as listed in
the
\href{http://en.wikipedia.org/wiki/Point_%28typography%29#Didot}{Wikipedia Article}.
%
The value $0.376065$\,|mm| is said to be \emph{the traditional value in
European printers' offices}. So the $1157$\,|dd|=$1238$\,|pt| rule refers to
this Didot point, or more precisely to the \emph{conversion factor} to be used
between this Didot and \TeX{} points.
The actual value in millimeters of exactly one Didot point as implemented in
\TeX{} is
%
\leftedline {|\xinttheexpr trunc(\dimexpr
1dd\relax/65536/72.27*25.4,12)\relax|}
%
\leftedline{\dtt{=\xinttheexpr trunc(\dimexpr
1dd\relax/65536/72.27*25.4,12)\relax}|...mm|}
%
The difference of circa $5$\AA\ is arguably tiny!
% 543564351/508000000
By the way the \emph{European printers' offices \emph{(dixit Wikipedia)}
Didot} is thus exactly
%
\leftedline{|\xinttheexpr reduce(.376065/(25.4/72.27))\relax|%
\dtt{=\xinttheexpr reduce(.376065/(25.4/72.27))\relax}\,|pt|}
%
and the centered convergents of this fraction are \xintFor* #1 in
{\xintFtoCCv{543564351/508000000}}\do {\dtt{\printnumber{#1}}\xintifForLast{.}{, }} We do
recover the $1238/1157$ therein!
\subsection{\csh{ifcase}, \csh{ifnum}, ... constructs}\label{sec:ifcase}
When using things such as |\ifcase \xintSgn{\A}| one has to make sure to leave
a space after the closing brace for \TeX{} to
stop its scanning for a number: once \TeX{} has finished expanding
|\xintSgn{\A}| and has so far obtained either |1|, |0|, or |-1|, a
space (or something `unexpandable') must stop it looking for more
digits. Using |\ifcase\xintSgn\A| without the braces is very dangerous,
because the blanks (including the end of line) following |\A| will be
skipped and not serve to stop the number which |\ifcase| is looking for.
%
\begin{everbatim*}
\begin{enumerate}[nosep]\def\A{1}
\item \ifcase \xintSgn\A 0\or OK\else ERROR\fi
\item \ifcase \xintSgn\A\space 0\or OK\else ERROR\fi
\item \ifcase \xintSgn{\A} 0\or OK\else ERROR\fi
\end{enumerate}
\end{everbatim*}
In order to use successfully |\if...\fi| constructions either as arguments to
the \xintname bundle expandable macros, or when building up a completely
expandable macro of one's own, one needs some \TeX nical expertise (see also
\autoref{fn:expansions} on page~\pageref{fn:expansions}).
It is thus much to be recommended to opt rather for already existing expandable
branching macros, such as the ones which are provided by
\xintname/\xintfracname: among them
\csbxint{SgnFork}, \csbxint{ifSgn}, \csbxint{ifZero}, \csbxint{ifOne},
\csbxint{ifNotZero}, \csbxint{ifTrueAelseB}, \csbxint{ifCmp}, \csbxint{ifGt},
\csbxint{ifLt}, \csbxint{ifEq}, \csbxint{ifOdd}, and \csbxint{ifInt}. See their
respective documentations. All these conditionals always have either two or
three branches, and empty brace pairs |{}| for unused branches should not be
forgotten.
If these tests are to be applied to standard \TeX{} short integers, it is more
efficient to use (under \LaTeX{}) the equivalent conditional tests from the
\href{http://www.ctan.org/pkg/etoolbox}{etoolbox}%
%
\footnote{\url{http://www.ctan.org/pkg/etoolbox}}
package.
\subsection{Expandable implementations of mathematical algorithms}
It is possible to chain |\xintexpr|-essions with |\expandafter|'s, like experts
do with |\numexpr| to compute multiple things at once. See
\autoref{ssec:fibonacci} for an example devoted to Fibonacci numbers (this
section provides the code which was used on the title page for the
\dtt{$F(1250)$} evaluation.) Notice that the $47$th Fibonacci number is
\dtt{\Fibonacci {47}} thus already too big for \TeX{} and \eTeX{}.
The |\Fibonacci| macro found in \autoref{ssec:fibonacci} is completely
expandable, (it is even \fexpan dable in the sense previously explained) hence
can be used for example within |\message| to write to the log and terminal.
\begingroup
\def\A {1859}\def\B {1573}
\edef\C {\xintiiGCD\A\B}
\edef\X {\Fibonacci\A}
\edef\Y {\Fibonacci\B}
%
Also, one can thus use it as argument to the \xintname macros: for example if
we are interested in knowing how many digits $F(1250)$ has, it suffices to
issue |\xintLen {\Fibonacci {1250}}| (which expands to \dtt{\xintLen
{\Fibonacci {1250}}}). Or if we want to check the formula
$gcd(F(1859),F(1573))=F(gcd(1859,1573))=F(143)$, we only need%
%
\footnote{The
\csa{xintiiGCD} macro is provided by the \xintgcdname package.}
%
\leftedline{|$\xintiiGCD{\Fibonacci{1859}}{\Fibonacci{1573}}=\Fibonacci{\xintiiGCD{1859}{1573}}$|}
%
which outputs:
%
\leftedline{$\dtt{\xintiiGCD{\X}{\Y}}=\dtt{\Fibonacci{\C}}$}
The |\Fibonacci| macro expanded its |\xintiiGCD{1859}{1573}| argument via the
services of |\numexpr|: this step allows only things obeying the \TeX{} bound,
naturally! (but \dtt{F(\xintiiPow2{31}}) would be rather big anyhow...).
In practice, whenever one typesets things, one has left the expansion only
contexts; hence there is no objection to, on the contrary it is recommended,
assign the result of earlier computations to macros via an |\edef| (or an
|\fdef|, see \ref{fdef}), for later use. The above could thus be coded
\begin{everbatim}
\begingroup
\def\A {1859} \def\B {1573} \edef\C {\xintiiGCD\A\B}
\edef\X {\Fibonacci\A} \edef\Y {\Fibonacci\B}
The identity $\gcd(F(\A),F(\B))=F(\gcd(\A,\B))$ can be checked via evaluation
of both sides: $\gcd(F(\A),F(\B))=\gcd(\printnumber\X,\printnumber\Y)=
\printnumber{\xintiiGCD\X\Y} = F(\gcd(\A,\B))$.\par
% some further computations involving \A, \B, \C, \X, \Y
\endgroup % closing the group removes assignments to \A, \B, ...
% or choose longer names less susceptible to overwriting something. Note that there
% is no LaTeX \newecommand which would be to \edef like \newcommand is to \def
\end{everbatim}
The identity $\gcd(F(\A),F(\B))=F(\gcd(\A,\B))$ can be checked via evaluation
of both sides:
$\gcd(F(\A),F(\B))=\gcd(\dtt{\printnumber\X{\normalcolor,}\printnumber\Y})=
\dtt{\printnumber{\xintiiGCD\X\Y}} = F(\C) = F(\gcd(\A,\B))$.\par
\endgroup
One may thus legitimately ask the author: why expandability to such extremes,
for things such as big fractions or floating point numbers (even
continued fractions...) which anyhow can not be used directly
within \TeX's primitives such as |\ifnum|? the answer is that the author
chose, seemingly, at some point back in his past to waste from then on his time
on such useless things!
\subsection{Possible syntax errors to avoid}
\edef\x{\xintMul {3}{5}/\xintMul{7}{9}}
Here is a list of imaginable input errors. Some will cause compilation errors,
others are more annoying as they may pass through unsignaled.
\begin{itemize}
\item using |-| to prefix some macro: |-\xintiSqr{35}/271|.%
%
\footnote{to the
contrary, this \emph{is}
allowed inside an |\xintexpr|-ession.}
\item using one pair of braces too many |\xintIrr{{\xintiPow {3}{13}}/243}| (the
computation goes through with no error signaled, but the result is completely
wrong).
\item things like |\xintiiAdd { \x}{\y}| as the space will cause \csa{x} to be
expanded later, most probably within a |\numexpr| thus provoking possibly an
arithmetic overflow.
\item using |[]| and decimal points at the same time |1.5/3.5[2]|, or with a
sign in the denominator |3/-5[7]|. The scientific notation has no such
restriction, the two inputs |1.5/-3.5e-2| and |-1.5e2/3.5| are equivalent:
|\xintRaw{1.5/-3.5e-2}|\dtt{=\xintRaw{1.5/-3.5e-2}},
|\xintRaw{-1.5e2/3.5}|\dtt{=\xintRaw{-1.5e2/3.5}}.
\item generally speaking, using in a context expecting an integer (possibly
restricted to the \TeX{} bound) a macro or expression which returns a
fraction: |\xinttheexpr 4/2\relax| outputs \dtt{\xinttheexpr 4/2\relax},
not $2$. Use |\xintNum {\xinttheexpr 4/2\relax}| or |\xinttheiexpr 4/2\relax|
(which rounds the result to the nearest integer, here, the result is already
an integer) or |\xinttheiiexpr 4/2\relax|. Or, divide in your head |4| by
|2| and insert the result directly in the \TeX{} source.
\end{itemize}
\subsection{Error messages}
In situations such as division by zero, the package will insert in the
\TeX{} processing an undefined control sequence (we copy this method
from the |bigintcalc| package). This will trigger the writing to the log
of a message signaling an undefined control sequence. The name of the
control sequence is the message. The error is raised \emph{before} the
end of the expansion so as to not disturb further processing of the
token stream, after completion of the operation. Generally the problematic
operation will output a zero. Possible such error message control
sequences:
\begin{multicols}{2}\parskip0pt\relax
\begin{everbatim}
\xintError:ArrayIndexIsNegative
\xintError:ArrayIndexBeyondLimit
\xintError:FactorialOfNegative
\xintError:TooBigFactorial
\xintError:DivisionByZero
\xintError:NaN
\xintError:FractionRoundedToZero
\xintError:NotAnInteger
\xintError:ExponentTooBig
\xintError:RootOfNegative
\xintError:NoBezoutForZeros
\xintError:ignored
\xintError:removed
\xintError:inserted
\xintError:unknownfunction
\xintError:we_are_doomed
\xintError:missing_xintthe!
\end{everbatim}
\end{multicols}
There are now a few more if for example one attempts to use |\xintAdd| without
having loaded \xintfracname (with only \xintname loaded, only |\xintiAdd| and
|\xintiiAdd| are legal).\MyMarginNote{Changed!}
\begin{multicols}{2}\parskip0pt\relax
\begin{everbatim}
\Did_you_mean_iiAbs?or_load_xintfrac
\Did_you_mean_iiOpp?or_load_xintfrac
\Did_you_mean_iiAdd?or_load_xintfrac
\Did_you_mean_iiSub?or_load_xintfrac
\Did_you_mean_iiMul?or_load_xintfrac
\Did_you_mean_iiPow?or_load_xintfrac
\Did_you_mean_iiSqr?or_load_xintfrac
\Did_you_mean_iiMax?or_load_xintfrac
\Did_you_mean_iiMin?or_load_xintfrac
\Did_you_mean_iMaxof?or_load_xintfrac
\Did_you_mean_iMinof?or_load_xintfrac
\Did_you_mean_iiSum?or_load_xintfrac
\Did_you_mean_iiPrd?or_load_xintfrac
\Did_you_mean_iiPrdExpr?or_load_xintfrac
\Did_you_mean_iiSumExpr?or_load_xintfrac
\end{everbatim}
\end{multicols}
Don't forget to set |\errorcontextlines| to at least |2| to get from \LaTeX\
more meaningful error messages. Errors occuring during the parsing of
|\xintexpr-essions| try to provide helpful information about the offending
token.
Release |1.1| employs in some situations delimited macros and there is
the possibility in case of an ill-formed expression to end up beyond the
|\relax| end-marker. The errors inevitably arising could then lead to very
cryptic messages; but nothing unusual or especially traumatizing for the
daring experienced \TeX/\LaTeX\ user.
\subsection{Package namespace, catcodes}
The bundle packages needs that the \csa{space} and \csa{empty} control
sequences are pre-defined with the identical meanings as in Plain \TeX{} or
\LaTeX2e.
Private macros of \xintkernelname, \xintcorename, \xinttoolsname,
\xintname, \xintfracname, \xintexprname, \xintbinhexname, \xintgcdname,
\xintseriesname, and \xintcfracname{} use one or more underscores |_| as
private letter, to reduce the risk of getting overwritten. They almost
all begin either with |\XINT_| or with |\xint_|, a handful of these
private macros such as \csa{XINTsetupcatcodes}, \csa{XINTdigits} and
those with names such as |\XINTinFloat...| or |\XINTinfloat...| do not
have any underscore in their names (for obscure legacy reasons).
\xinttoolsname provides \hyperref[odef]{|\odef|}, \hyperref[oodef]{|\oodef|},
\hyperref[fdef]{|\fdef|} (if macros with these names already exist
\xinttoolsname will not overwrite them but provide |\xintodef| etc... ) but
all other public macros from the \xintname bundle packages start with |\xint|.
For the good functioning of the macros, standard catcodes are assumed for the
minus sign, the forward slash, the square brackets, the letter `e'. These
requirements are dropped inside an |\xintexpr|-ession: spaces are gobbled,
catcodes mostly do not matter, the |e| of scientific notation may be |E| (on
input) \dots{}
If a character used in the |\xintexpr| syntax is made active,
this will surely cause problems; prefixing it with |\string| is one option.
There is \csbxint{exprSafeCatcodes} and \csbxint{exprRestoreCatcodes} to
temporarily turn off potentially active characters (but setting catcodes is an
un-expandable action).
\begin{framed}
For advanced \TeX\ users. At loading time of the packages the
catcode configuration may be arbitrary as long as it satisfies the following
requirements: the percent is of category code comment character, the
backslash is of category code escape character, digits have category code
other and letters have category code letter. Nothing else is assumed.
\end{framed}
\subsection{Origins of the package}
|2013/03/28.| Package |bigintcalc| by \textsc{Heiko Oberdiek} already
provides expandable arithmetic operations on ``big integers'',
exceeding the \TeX{} limits (of $2^{31}-1$), so why another%
%
\footnote{this section was written before the \xintfracname package; the
author is not aware of another package allowing expandable
computations with arbitrarily big fractions.}
%
one?
I got started on this in early March 2013, via a thread on the
|c.t.tex| usenet group, where \textsc{Ulrich D\,i\,e\,z} used the
previously cited package together with a macro (|\ReverseOrder|)
which I had contributed to another thread.%
%
\footnote{the \csa{ReverseOrder} could be avoided in that circumstance,
but it does play a crucial r\^ole here.}
%
What I had learned in this
other thread thanks to interaction with \textsc{Ulrich D\,i\,e\,z} and
\textsc{GL} on expandable manipulations of tokens motivated me to
try my hands at addition and multiplication.
I wrote macros \csa{bigMul} and \csa{bigAdd} which I posted to the
newsgroup; they appeared to work comparatively fast. These first
versions did not use the \eTeX{} \csa{numexpr} primitive, they worked
one digit at a time, having previously stored carry-arithmetic in
1200 macros.
I noticed that the |bigintcalc| package used \csa{numexpr}
if available, but (as far as I could tell) not
to do computations many digits at a time. Using \csa{numexpr} for
one digit at a time for \csa{bigAdd} and \csa{bigMul} slowed them
a tiny bit but avoided cluttering \TeX{} memory with the 1200
macros storing pre-computed digit arithmetic. I wondered if some speed
could be gained by using \csa{numexpr} to do four digits at a time
for elementary multiplications (as the maximal admissible number
for \csa{numexpr} has ten digits).
|2013/04/14|. This initial \xintname was followed by \xintfracname which
handled exactly fractions and decimal numbers.
|2013/05/25|. Later came \xintexprname and at the same time \xintfracname got
extended to handle floating point numbers.
|2013/11/22|. Later, \xinttoolsname was detached.
|2014/10/28|. Release |1.1| significantly extended the \xintexprname parsers.
|2015/10/10|. Release |1.2| rewrote the core integer routines which had
remained essentially unmodified, apart from a slight improvement of division
early 2014.
This |1.2| release also got its impulse from a fast
``reversing'' macro, which I wrote after my interest got awakened again as a
result of correspondance with Bruno \textsc{Le Floch} during September 2015:
this new reverse uses a \TeX nique which \emph{requires} the tokens to be
digits. I wrote a routine which works (expandably) in quasi-linear time, but a
less fancy |O(N^2)| variant which I developed concurrently proved to be faster
all the way up to perhaps $7000$ digits, thus I dropped the quasi-linear one.
The less fancy variant has the advantage that \xintname can handle numbers
with more than $19900$ digits (but not much more than $19950$). This is with
the current common values of the input save stack and maximal expansion depth:
$5000$ and $10000$ respectively.
\section{Some utilities from the \xinttoolsname package}
This is a first overview. Many examples combining these utilities with the
arithmetic macros of \xintname are to be found in \autoref{sec:tools}.
\subsection{Assignments}\label{sec:assign}
\xintAssign \xintBezout{357}{323}\to\tmpA\tmpB\tmpU\tmpV\tmpD
It might not be necessary to maintain at all times complete expandability. A
devoted syntax is provided to make these things more efficient, for example when
using the \csbxint{iDivision} macro which computes both quotient and remainder
at
the same time:
%
\leftedline{\csbxint{Assign}
|\xintiiDivision{\xintiiPow {2}{1000}}{\xintiiFac{100}}|\csbnolk{to}|\A\B|}
%
give:
\xintAssign\xintiiDivision{\xintiPow {2}{1000}}{\xintiiFac{100}}\to\A\B
|\meaning\A|\dtt{: \printnumber{\meaning\A}\relax} and
|\meaning\B|\dtt{: \printnumber{\meaning\B}\relax}.
%
Another example (which uses \csbxint{Bezout} from the \xintgcdname package):
%
\leftedline{\csbxint{Assign}
%
|\xintBezout{357}{323}|\csbnolk{to}|\A\B\U\V\D|}
%
is equivalent to setting |\A| to \dtt{\tmpA}, |\B| to \dtt{\tmpB}, |\U| to
\dtt{\tmpU}, |\V| to \dtt{\tmpV}, and |\D| to \dtt{\tmpD}. And indeed
\dtt{(\tmpU)$\times$\tmpA-(\tmpV)$\times$\tmpB$=$%
\xintiSub{\xintiMul\tmpU\tmpA}{\xintiMul\tmpV\tmpB}} is a Bezout Identity.
Thus, what |\xintAssign| does is to first apply an
\hyperref[ssec:expansions]{\fexpan sion} to what comes next; it then defines one
after the other (using |\def|; an optional argument allows to modify the
expansion type, see \autoref{xintAssign} for details), the macros found after
|\to| to correspond to the successive braced contents (or single tokens) located
prior to |\to|. In case the first token (after the
optional parameter within brackets, \emph{cf.} the \csbxint{Assign} detailed
document) is not an opening brace |{|, |\xintAssign| consider that there is
only one macro to define, and that its replacement text should be all that
follows until the |\to|.
\xintAssign
\xintBezout{3570902836026}{200467139463}\to\tmpA\tmpB\tmpU\tmpV\tmpD
\leftedline
{\csbxint{Assign}|\xintBezout{3570902836026}{200467139463}|%
\csbnolk{to}|\A\B\U\V\D|}
\noindent
gives then |\U|\dtt{:
\printnumber\tmpU},
|\V|\dtt{:
\printnumber\tmpV} and |\D|\dtt{=\tmpD}.
%
In situations when one does not know in advance the number of items, one has
\csbxint{AssignArray} or its synonym \csbxint{DigitsOf}:
%
\leftedline{\csbxint{DigitsOf}|\xintiPow{2}{100}|\csbnolk{to}\csa{DIGITS}}
%
This defines \csa{DIGITS} to be macro with one parameter, \csa{DIGITS}|{0}|
gives the size |N| of the array and \csa{DIGITS}|{n}|, for |n| from |1| to |N|
then gives the |n|th element of the array, here the |n|th digit of $2^{100}$,
from the most significant to the least significant. As usual, the generated
macro \csa{DIGITS} is completely expandable (in two steps). As it wouldn't make
much sense to allow indices exceeding the \TeX{} bounds, the macros created by
\csbxint{AssignArray} put their argument inside a \csa{numexpr}, so it is
completely expanded and may be a count register, not necessarily prefixed by
|\the| or |\number|. Consider the following code snippet:
%
\begin{everbatim*}
% \newcount\cnta
% \newcount\cntb
\begingroup
\xintDigitsOf\xintiPow{2}{100}\to\DIGITS
\cnta = 1
\cntb = 0
\loop
\advance \cntb \xintiSqr{\DIGITS{\cnta}}
\ifnum \cnta < \DIGITS{0}
\advance\cnta 1
\repeat
|2^{100}| (=\xintiPow {2}{100}) has \DIGITS{0} digits and the sum of their squares is \the\cntb.
These digits are, from the least to the most significant: \cnta = \DIGITS{0} \loop
\DIGITS{\cnta}\ifnum \cnta > 1 \advance\cnta -1 , \repeat.\endgroup
\end{everbatim*}
Warning: \csbxint{Assign}, \csbxint{AssignArray} and \csbxint{DigitsOf}
\emph{do not do any check} on whether the macros they define are already
defined.
\subsection{Utilities for expandable manipulations}\label{sec:utils}
The package now has more utilities to deal expandably with `lists of things',
which were treated un-expandably in the previous section with \csa{xintAssign}
and \csa{xintAssignArray}: \csbxint{ReverseOrder} and \csbxint{Length} since the
first release, \csbxint{Apply} and \csbxint{ListWithSep} since |1.04|,
\csbxint{RevWithBraces}, \csbxint{CSVtoList}, \csbxint{NthElt} since |1.06|,
\csbxint{ApplyUnbraced}, since |1.06b|, \csbxint{loop} and \csbxint{iloop} since
|1.09g|.%
%
\footnote{All these utilities, as well as \csbxint{Assign},
\csbxint{AssignArray} and the \csbxint{For} loops are now available from the
\xinttoolsname package, independently of the big integers facilities of
\xintname.}
As an example the following code uses only expandable operations:
\begin{everbatim*}
$2^{100}$ (=\xintiPow {2}{100}) has \xintLen{\xintiPow {2}{100}} digits and the sum of their
squares is \xintiiSum{\xintApply {\xintiSqr}{\xintiPow {2}{100}}}. These digits are, from the
least to the most significant: \xintListWithSep {, }{\xintRev{\xintiPow {2}{100}}}. The thirteenth
most significant digit is \xintNthElt{13}{\xintiPow {2}{100}}. The seventh least significant one
is \xintNthElt{7}{\xintRev{\xintiPow {2}{100}}}.
\end{everbatim*}
It would be more efficient to do once and for all
|\edef\z{\xintiPow {2}{100}}|, and then use |\z| in place of
|\xintiPow {2}{100}| everywhere as this would spare the CPU some repetitions.
Expandably computing primes is done in \autoref{xintSeq}.
\subsection{A new kind of for loop}
As part of the \hyperref[sec:tools]{utilities} coming with the \xinttoolsname
package, there is a new kind of for loop, \csbxint{For}. Check it out
(\autoref{xintFor}).
\subsection{A new kind of expandable loop}
Also included in \xinttoolsname, \csbxint{iloop} is an expandable loop giving
access to an iteration index, without using count registers which would break
expandability. Check it out (\autoref{xintiloop}).
\etocdepthtag.toc {commands}
\addtocontents{toc}{\gdef\string\sectioncouleur{{joli}}}
\renewcommand{\etocaftertochook}{\addvspace{\bigskipamount}}
\clearpage
\section{Commands of the \xintkernelname package}
\label{sec:kernel}
\localtableofcontents
The \xintkernelname package contains mainly the common code base for handling
the load-order of the bundle packages, the management of catcodes at loading
time, definition of common constants and macro utilities which are used
throughout the code etc ... it is automatically loaded by all packages of the
bundle.
It provides a few macros possibly useful in other contexts.
\subsection{\csbh{odef}, \csbh{oodef}, \csbh{fdef}}
\label{odef}
\label{oodef}
\label{fdef}
\csa{oodef}|\controlsequence {<stuff>}| does
\everb|@
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\controlsequence
\expandafter\expandafter\expandafter{<stuff>}
|
This works only for a single
|\controlsequence|, with no parameter text, even without parameters. An
alternative would be:
\everb|@
\def\oodef #1#{\def\oodefparametertext{#1}%
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\oodefparametertext
\expandafter\expandafter\expandafter }
|
\noindent
but it does not allow |\global| as prefix, and, besides, would have anyhow its
use (almost) limited to parameter texts without macro parameter tokens
(except if the expanded thing does not see them, or is designed to deal with
them).
There is a similar macro |\odef| with only one expansion of the replacement text
|<stuff>|, and |\fdef| which expands fully |<stuff>| using |\romannumeral-`0|.
They can be prefixed with |\global|. It appears than |\fdef| is generally a bit
faster than |\edef| when expanding macros from the \xintname bundle, when the
result has a few dozens of digits. |\oodef| needs thousands of digits it seems
to become competitive.
\subsection{\csbh{xintReverseOrder}}\label{xintReverseOrder}
\csa{xintReverseOrder}\marg{list}\etype{n} does not do any expansion of its
argument and just reverses the order of the tokens in the \meta{list}. Braces
are removed once and the enclosed material, now unbraced, does not get
reversed. Unprotected spaces (of any character code) are gobbled.
%
\leftedline{|\xintReverseOrder{\xintDigitsOf\xintiPow {2}{100}\to\Stuff}|}
%
\leftedline{gives:
\ttfamily{\string\Stuff\string\to1002\string\xintiPow\string\xintDigitsOf}}
\subsection{\csbh{xintLength}}\label{xintLength}
\csa{xintLength}\marg{list}\etype{n} does not do \emph{any} expansion of its
argument and just counts how many tokens there are (possibly none). So to use
it to count things in the replacement text of a macro one should do
|\expandafter\xintLength\expandafter{\x}|. One may also use it inside macros
as |\xintLength{#1}|. Things enclosed in braces count as one. Blanks between
tokens are not counted. See \csbxint{NthElt}|{0}| (from \xinttoolsname) for a
variant which first \fexpan ds its argument.
%
\leftedline{|\xintLength {\xintiPow {2}{100}}|\dtt{=\xintLength
{\xintiPow{2}{100}}}}
%
\leftedline{${}\neq{}$|\xintLen {\xintiPow {2}{100}}|\dtt{=\xintLen
{\xintiPow{2}{100}}}}
\clearpage
\section{Commands of the \xinttoolsname package}
\label{sec:tools}
\localtableofcontents
\def\n{|{N}|}
\def\m{|{M}|}
\def\x{|{x}|}
These utilities used to be provided within the \xintname package; since |1.09g|
(|2013/11/22|) they have been moved to an independently usable package
\xinttoolsname, which has none of the \xintname facilities regarding big
numbers. Whenever relevant release |1.09h| has made the macros |\long| so they
accept |\par| tokens on input.
First the completely expandable utilities up to \csbxint{iloop}, then the non
expandable utilities.
This section contains various concrete examples and ends with a
\hyperref[ssec:quicksort]{completely expandable implementation of the Quick Sort
algorithm} together with a graphical illustration of its action.
See also \ref{xintReverseOrder} and \ref{xintLength} which come with package
\xintkernelname, automatically loaded by \xinttoolsname.
\subsection{\csbh{xintRevWithBraces}}\label{xintRevWithBraces}
%{\small New in release |1.06|.\par}
\edef\X{\xintRevWithBraces{12345}}
\edef\y{\xintRevWithBraces\X}
\expandafter\def\expandafter\w\expandafter
{\romannumeral0\xintrevwithbraces{{\A}{\B}{\C}{\D}{\E}}}
%
\csa{xintRevWithBraces}\marg{list}\etype{f} first does the \fexpan sion of its
argument then it reverses the order of the tokens, or braced material, it
encounters, maintaining existing braces and adding a brace pair around each
naked token encountered. Space tokens (in-between top level braces or naked
tokens) are gobbled. This macro is mainly thought out for use on a \meta{list}
of such braced material; with such a list as argument the \fexpan sion will only
hit against the first opening brace, hence do nothing, and the braced stuff may
thus be macros one does not want to expand.
%
\leftedline{|\edef\x{\xintRevWithBraces{12345}}|}
%
\leftedline{|\meaning\x:|\dtt{\meaning\X}}
%
\leftedline{|\edef\y{\xintRevWithBraces\x}|}
%
\leftedline{|\meaning\y:|\dtt{\meaning\y}}
%
The examples above could be defined with |\edef|'s because the braced material
did not contain macros. Alternatively:
%
\leftedline{|\expandafter\def\expandafter\w\expandafter|}
%
\leftedline{|{\romannumeral0\xintrevwithbraces{{\A}{\B}{\C}{\D}{\E}}}|}
%
\leftedline{|\meaning\w:|\dtt{\meaning\w}}
%
The macro \csa{xintReverseWithBracesNoExpand}\etype{n} does the same job
without the initial expansion of its argument.
\subsection{\csbh{xintZapFirstSpaces}, \csbh{xintZapLastSpaces}, \csbh{xintZapSpaces}, \csbh{xintZapSpacesB}}
\label{xintZapFirstSpaces}
\label{xintZapLastSpaces}
\label{xintZapSpaces}
\label{xintZapSpacesB}
%{\small New with release |1.09f|.\par}
\csa{xintZapFirstSpaces}\marg{stuff}\etype{n} does not do \emph{any} expansion
of its argument, nor brace removal of any sort, nor does it alter \meta{stuff}
in anyway apart from stripping away all \emph{leading} spaces.
This macro will be mostly of interest to programmers who will know what I will
now be talking about. \emph{The essential points, naturally, are the complete
expandability and the fact that no brace removal nor any other alteration is
done to the input.}
\TeX's input scanner already converts consecutive blanks into single space
tokens, but |\xintZapFirstSpaces| handles successfully also inputs with
consecutive multiple space tokens.
However, it is assumed that \meta{stuff} does not contain (except inside braced
sub-material) space tokens of character code distinct from $32$.
It expands in two steps, and if the goal is to apply it to the
expansion text of |\x| to define |\y|, then one should do:
|\expandafter\def\expandafter\y\expandafter
{\romannumeral0\expandafter\xintzapfirstspaces\expandafter{\x}}|.
Other use case: inside a macro as |\edef\x{\xintZapFirstSpaces {#1}}| assuming
naturally that |#1| is compatible with such an |\edef| once the leading spaces
have been stripped.
\begingroup
\def\x { \a { \X } { \b \Y } }
%
\leftedline{|\xintZapFirstSpaces { \a { \X } { \b \Y } }->|%
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter
{\romannumeral0\expandafter\xintzapfirstspaces\expandafter{\x}}}+++}
\endgroup
\medskip
\noindent\csbxint{ZapLastSpaces}\marg{stuff}\etype{n} does not do \emph{any} expansion of
its argument, nor brace removal of any sort, nor does it alter \meta{stuff} in
anyway apart from stripping away all \emph{ending} spaces. The same remarks as
for \csbxint{ZapFirstSpaces} apply.
% ATTENTION à l'\ignorespaces fait par \color!
\begingroup
\def\x { \a { \X } { \b \Y } }
%
\leftedline{|\xintZapLastSpaces { \a { \X } { \b \Y } }->|%
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter
{\romannumeral0\expandafter\xintzaplastspaces\expandafter{\x}}}+++}
\endgroup
\medskip
\noindent\csbxint{ZapSpaces}\marg{stuff}\etype{n} does not do \emph{any}
expansion of its
argument, nor brace removal of any sort, nor does it alter \meta{stuff} in
anyway apart from stripping away all \emph{leading} and all \emph{ending}
spaces. The same remarks as for \csbxint{ZapFirstSpaces} apply.
\begingroup
\def\x { \a { \X } { \b \Y } }
%
\leftedline{|\xintZapSpaces { \a { \X } { \b \Y } }->|%
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter
{\romannumeral0\expandafter\xintzapspaces\expandafter{\x}}}+++}
\endgroup
\medskip
\noindent\csbxint{ZapSpacesB}\marg{stuff}\etype{n} does not do \emph{any}
expansion of
its argument, nor does it alter \meta{stuff} in anyway apart from stripping away
all leading and all ending spaces and possibly removing one level of braces if
\meta{stuff} had the shape |<spaces>{braced}<spaces>|. The same remarks as for
\csbxint{ZapFirstSpaces} apply.
\begingroup
\def\x { \a { \X } { \b \Y } }
%
\leftedline{|\xintZapSpacesB { \a { \X } { \b \Y } }->|%
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter
{\romannumeral0\expandafter\xintzapspacesb\expandafter{\x}}}+++}
\def\x { { \a { \X } { \b \Y } } }
%
\leftedline{|\xintZapSpacesB { { \a { \X } { \b \Y } } }->|%
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter
{\romannumeral0\expandafter\xintzapspacesb\expandafter{\x}}}+++}
\endgroup
The spaces here at the start and end of the output come from the braced
material, and are not removed (one would need a second application for that;
recall though that the \xintname zapping macros do not expand their argument).
\subsection{\csbh{xintCSVtoList}}
\label{xintCSVtoList}
\label{xintCSVtoListNoExpand}
\csa{xintCSVtoList}|{a,b,c...,z}|\etype{f} returns |{a}{b}{c}...{z}|. A
\emph{list} is by
convention in this manual simply a succession of tokens, where each braced thing
will count as one item (``items'' are defined according to the rules of \TeX{}
for fetching undelimited parameters of a macro, which are exactly the same rules
as for \LaTeX{} and command arguments [they are the same things]). The word
`list' in `comma separated list of items' has its usual linguistic meaning,
and then an ``item'' is what is delimited by commas.
So \csa{xintCSVtoList} takes on input a `comma separated list of items' and
converts it into a `\TeX{} list of braced items'. The argument to
|\xintCSVtoList| may be a macro: it will first be
\hyperref[ssec:expansions]{\fexpan ded}. Hence the item before the first comma,
if it is itself a macro, will be expanded which may or may not be a good thing.
A space inserted at the start of the first item serves to stop that expansion
(and disappears). The macro \csbxint{CSVtoListNoExpand}\etype{n} does the same
job without
the initial expansion of the list argument.
Apart from that no expansion of the items is done and the list items may thus be
completely arbitrary (and even contain perilous stuff such as unmatched |\if|
and |\fi| tokens).
Contiguous spaces and tab characters, are collapsed by \TeX{}
into single spaces. All such spaces around commas%
%
\footnote{and multiple space tokens are not a problem; but those at the
top level (not hidden inside braces) \emph{must} be of character code
|32|.}
%
\fbox{are removed}, as well as
the spaces at the start and the spaces at the end of the list.%
%
\footnote{let us recall that this is all done completely expandably...
There is absolutely no alteration of any sort of the item apart from
the stripping of initial and final space tokens (of character code
|32|) and brace removal if and only if the item apart from intial and
final spaces (or more generally multiple |char 32| space tokens) is
braced.}
%
The items may contain explicit |\par|'s or
empty lines (converted by the \TeX{} input parsing into |\par| tokens).
\begingroup
\edef\X{\xintCSVtoList { 1 ,{ 2 , 3 , 4 , 5 }, a , {b,T} U , { c , d } , { {x ,
y} } }}
%
\leftedline{|\xintCSVtoList { 1 ,{ 2 , 3 , 4 , 5 }, a , {b,T} U , { c , d } ,
{ {x , y} } }|}
%
\leftedline{|->|%
{\makeatletter\dtt{\expandafter\strip@prefix\meaning\X}}}
One sees on this example how braces protect commas from
sub-lists to be perceived as delimiters of the top list. Braces around an entire
item are removed, even when surrounded by spaces before and/or after. Braces for
sub-parts of an item are not removed.
We observe also that there is a slight difference regarding the brace stripping
of an item: if the braces were not surrounded by spaces, also the initial and
final (but no other) spaces of the \emph{enclosed} material are removed. This is
the only situation where spaces protected by braces are nevertheless removed.
From the rules above: for an empty argument (only spaces, no braces, no comma)
the output is
\dtt{\expandafter\detokenize\expandafter{\romannumeral0\xintcsvtolist { }}}
(a list with one empty item),
for ``|<opt. spaces>{}<opt.
spaces>|'' the output is
\dtt{\expandafter\detokenize\expandafter
{\romannumeral0\xintcsvtolist { {} }}}
(again a list with one empty item, the braces were removed),
for ``|{ }|'' the output is
\dtt{\expandafter\detokenize\expandafter
{\romannumeral0\xintcsvtolist {{ }}}}
(again a list with one empty item, the braces were removed and then
the inner space was removed),
for ``| { }|'' the output is
\dtt{\expandafter\detokenize\expandafter
{\romannumeral0\xintcsvtolist { { }}}} (again a list with one empty item, the initial space served only to stop the expansion, so this was like ``|{ }|'' as input, the braces were removed and the inner space was stripped),
for ``\texttt{\ \{\ \ \}\ }'' the output is
\dtt{\expandafter\detokenize\expandafter
{\romannumeral0\xintcsvtolist { { } }}} (this time the ending space of the first
item meant that after brace removal the inner spaces were kept; recall though
that \TeX{} collapses on input consecutive blanks into one space token),
for ``|,|'' the output consists of two consecutive
empty items
\dtt{\expandafter\detokenize\expandafter{\romannumeral0\xintcsvtolist
{,}}}. Recall that on output everything is braced, a |{}| is an ``empty''
item.
%
Most of the above is mainly irrelevant for every day use, apart perhaps from the
fact to be noted that an empty input does not give an empty output but a
one-empty-item list (it is as if an ending comma was always added at the end of
the input).
\def\y { \a,\b,\c,\d,\e}
\expandafter\def\expandafter\Y\expandafter{\romannumeral0\xintcsvtolist{\y}}
\def\t {{\if},\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}
\expandafter\def\expandafter\T\expandafter{\romannumeral0\xintcsvtolist{\t}}
%
\leftedline{|\def\y{ \a,\b,\c,\d,\e} \xintCSVtoList\y->|%
{\makeatletter\dtt{\expandafter\strip@prefix\meaning\Y}}}
%
\leftedline{|\def\t {{\if},\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}|}
%
\leftedline
{|\xintCSVtoList\t->|\makeatletter\dtt{\expandafter\strip@prefix\meaning\T}}
%
The results above were automatically displayed using \TeX's primitive
\csa{meaning}, which adds a space after each control sequence name. These spaces
are not in the actual braced items of the produced lists. The first items |\a|
and |\if| were either preceded by a space or braced to prevent expansion. The
macro \csa{xintCSVtoListNoExpand} would have done the same job without the
initial expansion of the list argument, hence no need for such protection but if
|\y| is defined as |\def\y{\a,\b,\c,\d,\e}| we then must do:
%
\leftedline{|\expandafter\xintCSVtoListNoExpand\expandafter {\y}|} Else, we
may have direct use: %
%
\leftedline{|\xintCSVtoListNoExpand
{\if,\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}|}
%
\leftedline{|->|\dtt{\expandafter\detokenize\expandafter
{\romannumeral0\xintcsvtolistnoexpand
{\if,\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}}}}
%
Again these spaces are an artefact from the use in the source of the document of
\csa{meaning} (or rather here, \csa{detokenize}) to display the result of using
\csa{xintCSVtoListNoExpand} (which is done for real in this document
source).
For the similar conversion from comma separated list to braced items list, but
without removal of spaces around the commas, there is
\csa{xintCSVtoListNonStripped}\etype{f} and
\csa{xintCSVtoListNonStrippedNoExpand}\etype{n}.
\endgroup
\subsection{\csbh{xintNthElt}}\label{xintNthElt}
\def\macro #1{\the\numexpr 9-#1\relax}
\csa{xintNthElt\x}\marg{list}\etype{\numx f} gets (expandably) the |x|th braced
item of the \meta{list}. An unbraced item token will be returned as is. The list
itself may be a macro which is first \fexpan ded.
\leftedline{|\xintNthElt {3}{{agh}\u{zzz}\v{Z}}| is
\texttt{\xintNthElt {3}{{agh}\u{zzz}\v{Z}}}}
%
\leftedline{|\xintNthElt {3}{{agh}\u{{zzz}}\v{Z}}| is
\texttt{\expandafter\expandafter\expandafter
\detokenize\expandafter\expandafter\expandafter {\xintNthElt
{3}{{agh}\u{{zzz}}\v{Z}}}}}
%
\leftedline{|\xintNthElt {2}{{agh}\u{{zzz}}\v{Z}}| is
\texttt{\expandafter\expandafter\expandafter
\detokenize\expandafter\expandafter\expandafter {\xintNthElt
{2}{{agh}\u{{zzz}}\v{Z}}}}}
%
\leftedline{|\xintNthElt {37}{\xintiiFac {100}}|\dtt{=\xintNthElt
{37}{\xintiiFac {100}}} is the thirty-seventh digit of $100!$.}
%
\leftedline{|\xintNthElt {10}{\xintFtoCv
{566827/208524}}|\dtt{=\xintNthElt {10}{\xintFtoCv
{566827/208524}}}}
\leftedline{is the tenth convergent of $566827/208524$ (uses \xintcfracname
package).}
%
\leftedline{|\xintNthElt {7}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|%
\dtt{=\xintNthElt {7}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}}
%
\leftedline{|\xintNthElt {0}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|%
\dtt{=\xintNthElt {0}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}}
%
\leftedline{|\xintNthElt {-3}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|%
\dtt{=\xintNthElt {-3}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}}
If |x=0|,
the macro returns the \emph{length} of the expanded list: this is not equivalent
to \csbxint{Length} which does no pre-expansion. And it is different from
\csbxint{Len} which is to be used only on integers or fractions.
If |x<0|, the macro returns the \verb+|x|+th element from the end of the list.
%
\leftedline {|\xintNthElt {-5}{{{agh}}\u{zzz}\v{Z}}| is
\texttt{\expandafter\expandafter\expandafter \detokenize
\expandafter\expandafter\expandafter{\xintNthElt {-5}{{{agh}}\u{zzz}\v{Z}}}}}
The macro \csa{xintNthEltNoExpand}\etype{\numx n} does the same job but without
first expanding the list argument: |\xintNthEltNoExpand {-4}{\u\v\w T\x\y\z}| is
\xintNthEltNoExpand {-4}{\a\b\c\u\v\w T\x\y\z}.
In cases where |x| is larger (in absolute value) than the length of the list
then |\xintNthElt| returns nothing.
\subsection{\csbh{xintKeep}}\label{xintKeep}
\csa{xintKeep\x}\marg{list}\etype{\numx f} expands the token list argument and
returns a new list containing only the first |x| items. If |x<0| the macro
returns the last \verb+|x|+ elements (in the same order as in the initial
list). If \verb+|x|+ equals or exceeds the length of the list, the list (as
arising from expansion of the second argument) is returned. For |x=0| the
empty list is returned.
If |x>0| the (non space) items from the original end up braced in the
output: if one later wants to remove all brace pairs (either added to a naked
token, or initially present), one may use \csbxint {ListWithSep} with an empty
separator.
On the other hand, if |x<0| the macro acts by suppressing items from the head
of the list, and no brace pairs are added to the kept elements from the tail
(originally present ones are not removed).\MyMarginNote{\noindent Description
corrected in 1.2a doc}
\csa{xintKeepNoExpand} does the same without first \fexpan ding its list
argument.
%
\begin{everbatim*}
\fdef\test {\xintKeep {17}{\xintKeep {-69}{\xintSeq {1}{100}}}}\meaning\test\par
\noindent\fdef\test {\xintKeep {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintKeep {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintKeep {7}{123456789}}\meaning\test\par
\noindent\fdef\test {\xintKeep {-7}{123456789}}\meaning\test\par
\end{everbatim*}
%
\subsection{\csbh{xintKeepUnbraced}}\label{xintKeepUnbraced}
Sames as \csbxint{Keep} but no brace pairs are added around the kept items
from the head of the list. Each item will lose one level of brace pairs. For
|x<0| is not different from \csbxint{Keep}.\NewWith{1.2a}
\csa{xintKeepUnbracedNoExpand} does the same without first \fexpan ding its list
argument.
%
\begin{everbatim*}
\fdef\test {\xintKeepUnbraced {10}{\xintSeq {1}{100}}}\meaning\test\par
\noindent\fdef\test {\xintKeepUnbraced {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintKeepUnbraced {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintKeepUnbraced {7}{123456789}}\meaning\test\par
\noindent\fdef\test {\xintKeepUnbraced {-7}{123456789}}\meaning\test\par
\end{everbatim*}
\subsection{\csbh{xintTrim}}\label{xintTrim}
\csa{xintTrim\x}\marg{list}\etype{\numx f} expands the list argument and
gobbles its first |x| elements. The remaining ones are left as they are (no
brace pairs added). If |x<0| the macro gobbles the last \verb+|x|+
elements, and the kept elements from the head of the list end up braced in the
output. If \verb+|x|+ equals or exceeds the length
of the list, the empty list is returned. For |x=0| the full list is returned.
\csa{xintTrimNoExpand} does the same without first \fexpan ding its list
argument.
\begin{everbatim*}
\fdef\test {\xintTrim {17}{\xintTrim {-69}{\xintSeq {1}{100}}}}\meaning\test\par
\noindent\fdef\test {\xintTrim {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintTrim {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintTrim {7}{123456789}}\meaning\test\par
\noindent\fdef\test {\xintTrim {-7}{123456789}}\meaning\test\par
\end{everbatim*}
\subsection{\csbh{xintTrimUnbraced}}\label{xintTrimUnbraced}
Same as \csbxint{Trim} but in case of a negative |x| (cutting items from
the tail), the kept items from the head are not enclosed in brace pairs. They
will lose one level of braces.\NewWith{1.2a}
\csa{xintTrimUnbracedNoExpand} does the same without first \fexpan ding its list
argument.
\begin{everbatim*}
\fdef\test {\xintTrimUnbraced {-90}{\xintSeq {1}{100}}}\meaning\test\par
\noindent\fdef\test {\xintTrimUnbraced {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintTrimUnbraced {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par
\noindent\fdef\test {\xintTrimUnbraced {7}{123456789}}\meaning\test\par
\noindent\fdef\test {\xintTrimUnbraced {-7}{123456789}}\meaning\test\par
\end{everbatim*}
\subsection{\csbh{xintListWithSep}}\label{xintListWithSep}
\def\macro #1{\the\numexpr 9-#1\relax}
\csa{xintListWithSep}|{sep}|\marg{list}\etype{nf} inserts the given separator
|sep| in-between all items of the given list of braced items: this separator may
be a macro (or multiple tokens) but will not be expanded. The second argument
also may be itself a macro: it is \fexpan ded. Applying \csa{xintListWithSep}
removes the braces from the list items (for example |{1}{2}{3}| turns into
\dtt{\xintListWithSep,{123}} via |\xintListWithSep{,}{{1}{2}{3}}|). An
empty input gives an empty output, a singleton gives a singleton, the separator
is used starting with at least two elements. Using an empty separator has the
net effect of unbracing the braced items constituting the \meta{list} (in such
cases the new list may thus be longer than the original).
%
\leftedline{|\xintListWithSep{:}{\xintiiFac
{20}}|\dtt{=\xintListWithSep{:}{\xintiiFac {20}}}}
The macro \csa{xintListWithSepNoExpand}\etype{nn} does the same
job without the initial expansion.
\subsection{\csbh{xintApply}}\label{xintApply}
\def\macro #1{\the\numexpr 9-#1\relax}
\csa{xintApply}|{\macro}|\marg{list}\etype{ff} expandably applies the one
parameter command |\macro| to each item in the \meta{list} given as second
argument and returns a new list with these outputs: each item is given one after
the other as parameter to |\macro| which is expanded at that time (as usual,
\emph{i.e.} fully for what comes first), the results are braced and output
together as a succession of braced items (if |\macro| is defined to start with a
space, the space will be gobbled and the |\macro| will not be expanded; it is
allowed to have its own arguments, the list items serve as last arguments to
|\macro|). Hence |\xintApply{\macro}{{1}{2}{3}}| returns
|{\macro{1}}{\macro{2}}{\macro{3}}| where all instances of |\macro| have been
already \fexpan ded.
Being expandable, |\xintApply| is useful for example inside alignments where
implicit groups make standard loops constructs usually fail. In such situation
it is often not wished that the new list elements be braced, see
\csbxint{ApplyUnbraced}. The |\macro| does not have to be expandable:
|\xintApply| will try to expand it, the expansion may remain partial.
The \meta{list} may
itself be some macro expanding (in the previously described way) to the list of
tokens to which the command |\macro| will be applied. For example, if the
\meta{list} expands to some positive number, then each digit will be replaced by
the result of applying |\macro| on it. %
%
\leftedline{|\def\macro #1{\the\numexpr
9-#1\relax}|} %
%
\leftedline{|\xintApply\macro{\xintiiFac
{20}}|\dtt{=\xintApply\macro{\xintiiFac {20}}}}
The macro \csa{xintApplyNoExpand}\etype{fn} does the same job without the first
initial expansion which gave the \meta{list} of braced tokens to which |\macro|
is applied.
\subsection{\csbh{xintApplyUnbraced}}\label{xintApplyUnbraced}
\csa{xintApplyUnbraced}|{\macro}|\marg{list}\etype{ff} is like \csbxint{Apply}.
The difference is that after having expanded its list argument, and applied
|\macro| in turn to each item from the list, it reassembles the outputs without
enclosing them in braces. The net effect is the same as doing
%
\leftedline{|\xintListWithSep {}{\xintApply {\macro}|\marg{list}|}|} This is
useful for preparing a macro which will itself define some other macros or make
assignments, as the scope will not be limited by brace pairs.
%
\begin{everbatim*}
\def\macro #1{\expandafter\def\csname myself#1\endcsname {#1}}
\xintApplyUnbraced\macro{{elta}{eltb}{eltc}}
\begin{enumerate}[nosep,label=(\arabic{*})]
\item \meaning\myselfelta
\item \meaning\myselfeltb
\item \meaning\myselfeltc
\end{enumerate}
\end{everbatim*}
%
The macro \csa{xintApplyUnbracedNoExpand}\etype{fn} does the same job without
the first initial expansion which gave the \meta{list} of braced tokens to which
|\macro| is applied.
\subsection{\csbh{xintSeq}}\label{xintSeq}
\csa{xintSeq}|[d]{x}{y}|\etype{{{\upshape[\numx]}}\numx\numx} generates
expandably |{x}{x+d}...| up to and possibly including |{y}| if |d>0| or down
to and including |{y}| if |d<0|. Naturally |{y}| is omitted if |y-x| is not a
multiple of |d|. If |d=0| the macro returns |{x}|. If |y-x| and |d| have
opposite signs, the macro returns nothing. If the optional argument |d| is
omitted it is taken to be the sign of |y-x|. Hence |\xintSeq {1}{0}| is not
empty but |{1}{0}|. But |\xintSeq [1]{1}{0}| is empty.
The arguments |x| and |y| are expanded inside a |\numexpr| so they may be
count registers or a \LaTeX{} |\value{countername}|, or arithmetic with such
things.
%
\begin{everbatim*}
\xintListWithSep{,\hskip2pt plus 1pt minus 1pt }{\xintSeq {12}{-25}}
\end{everbatim*}
%
\begin{everbatim*}
\xintiiSum{\xintSeq [3]{1}{1000}}
\end{everbatim*}
When the macro is used without the optional argument |d|, it can only generate
up to about $5000$ numbers\IMPORTANT, the precise value depends upon some
\TeX{} memory parameter (input save stack).
With the optional argument |d| the macro proceeds differently (but less
efficiently) and does not stress the input save stack.
\subsection{Completely expandable prime test}\label{ssec:primesI}
Let us now construct a completely expandable macro which returns $1$ if its
given input is prime and $0$ if not:
\everb|@
\def\remainder #1#2{\the\numexpr #1-(#1/#2)*#2\relax }
\def\IsPrime #1%
{\xintANDof {\xintApply {\remainder {#1}}{\xintSeq {2}{\xintiSqrt{#1}}}}}
|
This uses \csbxint{iSqrt} and assumes its input is at least $5$. Rather than
\xintname's own \csbxint{iRem} we used a quicker |\numexpr| expression as we
are dealing with short integers. Also we used \csbxint{ANDof} which will
return $1$ only if all the items are non-zero. The macro is a bit
silly with an even input, ok, let's enhance it to detect an even input:
\everb|@
\def\IsPrime #1%
{\xintifOdd {#1}
{\xintANDof % odd case
{\xintApply {\remainder {#1}}
{\xintSeq [2]{3}{\xintiSqrt{#1}}}%
}%
}
{\xintifEq {#1}{2}{1}{0}}%
}
|
We used the \xintname provided expandable tests (on big integers or fractions)
in oder for |\IsPrime| to be \fexpan dable.
Our integers are short, but without |\expandafter|'s with
|\@firstoftwo|, % @ n'est plus actif dans le dtx 1.1 !
or some other related techniques,
direct use of |\ifnum..\fi| tests is dangerous. So to make the macro more
efficient we are going to use the expandable tests provided by the package
\href{http://ctan.org/pkg/etoolbox}{etoolbox}%
%
\footnote{\url{http://ctan.org/pkg/etoolbox}}.
%
The macro becomes:
%
\everb|@
\def\IsPrime #1%
{\ifnumodd {#1}
{\xintANDof % odd case
{\xintApply {\remainder {#1}}{\xintSeq [2]{3}{\xintiSqrt{#1}}}}}
{\ifnumequal {#1}{2}{1}{0}}}
|
In the odd case however we have to assume the integer is at least $7$, as
|\xintSeq| generates an empty list if |#1=3| or |5|, and |\xintANDof| returns
$1$ when supplied an empty list. Let us ease up a bit |\xintANDof|'s work by
letting it work on only $0$'s and $1$'s. We could use:
%
\everb|@
\def\IsNotDivisibleBy #1#2%
{\ifnum\numexpr #1-(#1/#2)*#2=0 \expandafter 0\else \expandafter1\fi}
|
\noindent
where the |\expandafter|'s are crucial for this macro to be \fexpan dable and
hence work within the applied \csbxint{ANDof}. Anyhow, now that we have loaded
\href{http://ctan.org/pkg/etoolbox}{etoolbox}, we might as well use:
%
\everb|@
\newcommand{\IsNotDivisibleBy}[2]{\ifnumequal{#1-(#1/#2)*#2}{0}{0}{1}}
|
\noindent
Let us enhance our prime macro to work also on the small primes:
\everb|@
\newcommand{\IsPrime}[1] % returns 1 if #1 is prime, and 0 if not
{\ifnumodd {#1}
{\ifnumless {#1}{8}
{\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes
{\xintANDof
{\xintApply
{ \IsNotDivisibleBy {#1}}{\xintSeq [2]{3}{\xintiSqrt{#1}}}}%
}}% END OF THE ODD BRANCH
{\ifnumequal {#1}{2}{1}{0}}% EVEN BRANCH
}
|
The input is still assumed positive. There is a deliberate blank before
\csa{IsNotDivisibleBy} to use this feature of \csbxint{Apply}: a space stops the
expansion of the applied macro (and disappears). This expansion will be done by
\csbxint{ANDof}, which has been designed to skip everything as soon as it finds
a false (i.e. zero) input. This way, the efficiency is considerably improved.
We did generate via the \csbxint{Seq} too many potential divisors though. Later
sections give two variants: one with \csbxint{iloop} (\autoref{ssec:primesII})
which is still expandable and another one (\autoref{ssec:primesIII}) which is a
close variant of the |\IsPrime| code above but with the \csbxint{For} loop, thus
breaking expandability. The \hyperref[ssec:primesII]{xintiloop variant} does not
first evaluate the integer square root, the \hyperref[ssec:primesIII]{xintFor
variant} still does. I did not compare their efficiencies.
Let us construct with this expandable primality test a table of the prime
numbers up to $1000$. We need to count how many we have in order to know how
many tab stops one shoud add in the last row.%
%
\footnote{although a tabular row may have less tabs than in the
preamble, there is a problem with the \char`\|\space\space vertical
rule, if one does that.}
%
There is some subtlety for this
last row. Turns out to be better to insert a |\\| only when we know for sure we
are starting a new row; this is how we have designed the |\OneCell| macro. And
for the last row, there are many ways, we use again |\xintApplyUnbraced| but
with a macro which gobbles its argument and replaces it with a tabulation
character. The \csbxint{For*} macro would be more elegant here.
%
\everb?@
\newcounter{primecount}
\newcounter{cellcount}
\newcommand{\NbOfColumns}{13}
\newcommand{\OneCell}[1]{%
\ifnumequal{\IsPrime{#1}}{1}
{\stepcounter{primecount}
\ifnumequal{\value{cellcount}}{\NbOfColumns}
{\\\setcounter{cellcount}{1}#1}
{&\stepcounter{cellcount}#1}%
} % was prime
{}% not a prime, nothing to do
}
\newcommand{\OneTab}[1]{&}
\begin{tabular}{|*{\NbOfColumns}{r}|}
\hline
2 \setcounter{cellcount}{1}\setcounter{primecount}{1}%
\xintApplyUnbraced \OneCell {\xintSeq [2]{3}{999}}%
\xintApplyUnbraced \OneTab
{\xintSeq [1]{1}{\the\numexpr\NbOfColumns-\value{cellcount}\relax}}%
\\
\hline
\end{tabular}
There are \arabic{primecount} prime numbers up to 1000.
?
The table has been put in \hyperref[primesupto1000]{float} which appears
\vpageref{primesupto1000}.
We had to be careful to use in the last row \csbxint{Seq} with its optional
argument |[1]| so as to not generate a decreasing sequence from |1| to |0|, but
really an empty sequence in case the row turns out to already have all its
cells (which doesn't happen here but would with a number of columns dividing
$168$).
%
\newcommand{\IsNotDivisibleBy}[2]{\ifnumequal{#1-(#1/#2)*#2}{0}{0}{1}}
\newcommand{\IsPrime}[1]
{\ifnumodd {#1}
{\ifnumless {#1}{8}
{\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes
{\xintANDof
{\xintApply
{ \IsNotDivisibleBy {#1}}{\xintSeq [2]{3}{\xintiSqrt{#1}}}}%
}}% END OF THE ODD BRANCH
{\ifnumequal {#1}{2}{1}{0}}% EVEN BRANCH
}
\newcounter{primecount}
\newcounter{cellcount}
\newcommand{\NbOfColumns}{13}
\newcommand{\OneCell}[1]
{\ifnumequal{\IsPrime{#1}}{1}
{\stepcounter{primecount}
\ifnumequal{\value{cellcount}}{\NbOfColumns}
{\\\setcounter{cellcount}{1}#1}
{&\stepcounter{cellcount}#1}%
} % was prime
{}% not a prime nothing to do
}
\newcommand{\OneTab}[1]{&}
\begin{figure*}[ht!]
\centering
\phantomsection\label{primesupto1000}
\begin{tabular}{|*{\NbOfColumns}{r}|}
\hline
2\setcounter{cellcount}{1}\setcounter{primecount}{1}%
\xintApplyUnbraced \OneCell {\xintSeq [2]{3}{999}}%
\xintApplyUnbraced \OneTab
{\xintSeq [1]{1}{\the\numexpr\NbOfColumns-\value{cellcount}\relax}}%
\\
\hline
\end{tabular}
\smallskip
\centeredline{There are \arabic{primecount} prime numbers up to 1000.}
\end{figure*}
\subsection{\csbh{xintloop}, \csbh{xintbreakloop}, \csbh{xintbreakloopanddo}, \csbh{xintloopskiptonext}}
\label{xintloop}
\label{xintbreakloop}
\label{xintbreakloopanddo}
\label{xintloopskiptonext}
|\xintloop|\meta{stuff}|\if<test>...\repeat|\retype{} is an expandable loop
compatible with nesting. However to break out of the loop one almost always need
some un-expandable step. The cousin \csbxint{iloop} is \csbxint{loop} with an
embedded expandable mechanism allowing to exit from the loop. The iterated
commands may contain |\par| tokens or empty lines.
If a sub-loop is to be used all the material from the start of the main loop and
up to the end of the entire subloop should be braced; these braces will be
removed and do not create a group. The simplest to allow the nesting of one or
more sub-loops is to brace everything between \csa{xintloop} and \csa{repeat},
being careful not to leave a space between the closing brace and |\repeat|.
As this loop and \csbxint{iloop} will primarily be of interest to experienced
\TeX{} macro programmers, my description will assume that the user is
knowledgeable enough. Some examples in this document will be perhaps more
illustrative than my attemps at explanation of use.
One can abort the loop with \csbxint{breakloop}; this should not be used inside
the final test, and one should expand the |\fi| from the corresponding test
before. One has also \csbxint{breakloopanddo} whose first argument will be
inserted in the token stream after the loop; one may need a macro such as
|\xint_afterfi| to move the whole thing after the |\fi|, as a simple
|\expandafter| will not be enough.
One will usually employ some count registers to manage the exit test from the
loop; this breaks expandability, see \csbxint{iloop} for an expandable integer
indexed loop. Use in alignments will be complicated by the fact that cells
create groups, and also from the fact that any encountered unexpandable material
will cause the \TeX{} input scanner to insert |\endtemplate| on each encountered
|&| or |\cr|; thus |\xintbreakloop| may not work as expected, but the situation
can be resolved via |\xint_firstofone{&}| or use of |\TAB| with |\def\TAB{&}|.
It is thus simpler for alignments to use rather than \csbxint{loop} either the
expandable \csbxint{ApplyUnbraced} or the non-expandable but alignment
compatible \csbxint{ApplyInline}, \csbxint{For} or \csbxint{For*}.
As an example, let us suppose we have two macros |\A|\marg{i}\marg{j} and
|\B|\marg{i}\marg{j} behaving like (small) integer valued matrix entries, and we
want to define a macro |\C|\marg{i}\marg{j} giving the matrix product (|i| and
|j| may be count registers). We will assume that |\A[I]| expands to the number
of rows, |\A[J]| to the number of columns and want the produced |\C| to act in
the same manner. The code is very dispendious in use of |\count| registers, not
optimized in any way, not made very robust (the defined macro can not have the
same name as the first two matrices for example), we just wanted to quickly
illustrate use of the nesting capabilities of |\xintloop|.%
%
\footnote{for a more sophisticated implementation of matrix
multiplication, inclusive of determinants, inverses, and display
utilities, with entries big integers or decimal numbers or even
fractions see \url{http://tex.stackexchange.com/a/143035/4686} from
November 11, 2013.}
%
\begin{everbatim*}
\newcount\rowmax \newcount\colmax \newcount\summax
\newcount\rowindex \newcount\colindex \newcount\sumindex
\newcount\tmpcount
\makeatletter
\def\MatrixMultiplication #1#2#3{%
\rowmax #1[I]\relax
\colmax #2[J]\relax
\summax #1[J]\relax
\rowindex 1
\xintloop % loop over row index i
{\colindex 1
\xintloop % loop over col index k
{\tmpcount 0
\sumindex 1
\xintloop % loop over intermediate index j
\advance\tmpcount \numexpr #1\rowindex\sumindex*#2\sumindex\colindex\relax
\ifnum\sumindex<\summax
\advance\sumindex 1
\repeat }%
\expandafter\edef\csname\string#3{\the\rowindex.\the\colindex}\endcsname
{\the\tmpcount}%
\ifnum\colindex<\colmax
\advance\colindex 1
\repeat }%
\ifnum\rowindex<\rowmax
\advance\rowindex 1
\repeat
\expandafter\edef\csname\string#3{I}\endcsname{\the\rowmax}%
\expandafter\edef\csname\string#3{J}\endcsname{\the\colmax}%
\def #3##1{\ifx[##1\expandafter\Matrix@helper@size
\else\expandafter\Matrix@helper@entry\fi #3{##1}}%
}%
\def\Matrix@helper@size #1#2#3]{\csname\string#1{#3}\endcsname }%
\def\Matrix@helper@entry #1#2#3%
{\csname\string#1{\the\numexpr#2.\the\numexpr#3}\endcsname }%
\def\A #1{\ifx[#1\expandafter\A@size
\else\expandafter\A@entry\fi {#1}}%
\def\A@size #1#2]{\ifx I#23\else4\fi}% 3rows, 4columns
\def\A@entry #1#2{\the\numexpr #1+#2-1\relax}% not pre-computed...
\def\B #1{\ifx[#1\expandafter\B@size
\else\expandafter\B@entry\fi {#1}}%
\def\B@size #1#2]{\ifx I#24\else3\fi}% 4rows, 3columns
\def\B@entry #1#2{\the\numexpr #1-#2\relax}% not pre-computed...
\makeatother
\MatrixMultiplication\A\B\C \MatrixMultiplication\C\C\D
\MatrixMultiplication\C\D\E \MatrixMultiplication\C\E\F
\begin{multicols}2
\[\begin{pmatrix}
\A11&\A12&\A13&\A14\\
\A21&\A22&\A23&\A24\\
\A31&\A32&\A33&\A34
\end{pmatrix}
\times
\begin{pmatrix}
\B11&\B12&\B13\\
\B21&\B22&\B23\\
\B31&\B32&\B33\\
\B41&\B42&\B43
\end{pmatrix}
=
\begin{pmatrix}
\C11&\C12&\C13\\
\C21&\C22&\C23\\
\C31&\C32&\C33
\end{pmatrix}\]
\[\begin{pmatrix}
\C11&\C12&\C13\\
\C21&\C22&\C23\\
\C31&\C32&\C33
\end{pmatrix}^2 = \begin{pmatrix}
\D11&\D12&\D13\\
\D21&\D22&\D23\\
\D31&\D32&\D33
\end{pmatrix}\]
\[\begin{pmatrix}
\C11&\C12&\C13\\
\C21&\C22&\C23\\
\C31&\C32&\C33
\end{pmatrix}^3 = \begin{pmatrix}
\E11&\E12&\E13\\
\E21&\E22&\E23\\
\E31&\E32&\E33
\end{pmatrix}\]
\[\begin{pmatrix}
\C11&\C12&\C13\\
\C21&\C22&\C23\\
\C31&\C32&\C33
\end{pmatrix}^4 = \begin{pmatrix}
\F11&\F12&\F13\\
\F21&\F22&\F23\\
\F31&\F32&\F33
\end{pmatrix}\]
\end{multicols}
\end{everbatim*}
\subsection{\csbh{xintiloop}, \csbh{xintiloopindex}, \csbh{xintouteriloopindex},
\csbh{xintbreakiloop}, \csbh{xintbreakiloopanddo}, \csbh{xintiloopskiptonext},
\csbh{xintiloopskipandredo}}
\label{xintiloop}
\label{xintbreakiloop}
\label{xintbreakiloopanddo}
\label{xintiloopskiptonext}
\label{xintiloopskipandredo}
\label{xintiloopindex}
\label{xintouteriloopindex}
\csa{xintiloop}|[start+delta]|\meta{stuff}|\if<test> ... \repeat|\retype{} is a
completely expandable nestable loop. complete expandability depends naturally on
the actual iterated contents, and complete expansion will not be achievable
under a sole \fexpan sion, as is indicated by the hollow star in the margin;
thus the loop can be used inside an |\edef| but not inside arguments to the
package macros. It can be used inside an |\xintexpr..\relax|. The
|[start+delta]| is mandatory, not optional.
This loop benefits via \csbxint{iloopindex} to (a limited access to) the integer
index of the iteration. The starting value |start| (which may be a |\count|) and
increment |delta| (\emph{id.}) are mandatory arguments. A space after the
closing square bracket is not significant, it will be ignored. Spaces inside the
square brackets will also be ignored as the two arguments are first given to a
|\numexpr...\relax|. Empty lines and explicit |\par| tokens are accepted.
As with \csbxint{loop}, this tool will mostly be of interest to advanced users.
For nesting, one puts inside braces all the
material from the start (immediately after |[start+delta]|) and up to and
inclusive of the inner loop, these braces will be removed and do not create a
loop. In case of nesting, \csbxint{outeriloopindex} gives access to the index of
the outer loop. If needed one could write on its model a macro giving access to
the index of the outer outer loop (or even to the |nth| outer loop).
The \csa{xintiloopindex} and \csa{xintouteriloopindex} can not be used inside
braces, and generally speaking this means they should be expanded first when
given as argument to a macro, and that this macro receives them as delimited
arguments, not braced ones. Or, but naturally this will break expandability, one
can assign the value of \csa{xintiloopindex} to some |\count|. Both
\csa{xintiloopindex} and \csa{xintouteriloopindex} extend to the litteral
representation of the index, thus in |\ifnum| tests, if it comes last one has to
correctly end the macro with a |\space|, or encapsulate it in a
|\numexpr..\relax|.
When the repeat-test of the loop is, for example, |\ifnum\xintiloopindex<10
\repeat|, this means that the last iteration will be with |\xintiloopindex=10|
(assuming |delta=1|). There is also |\ifnum\xintiloopindex=10 \else\repeat| to
get the last iteration to be the one with |\xintiloopindex=10|.
One has \csbxint{breakiloop} and \csbxint{breakiloopanddo} to abort the loop.
The syntax of |\xintbreakiloopanddo| is a bit surprising, the sequence of tokens
to be executed after breaking the loop is not within braces but is delimited by
a dot as in:
%
\leftedline{|\xintbreakiloopanddo <afterloop>.etc.. etc... \repeat|}
%
The reason is that one may wish to use the then current value of
|\xintiloopindex| in |<afterloop>| but it can't be within braces at the time it
is evaluated. However, it is not that easy as |\xintiloopindex| must be expanded
before, so one ends up with code like this:
%
\leftedline
{|\expandafter\xintbreakiloopanddo\expandafter\macro\xintiloopindex.%|}
%
\leftedline{|etc.. etc.. \repeat|}
%
As moreover the |\fi| from the test leading to the decision of breaking out of
the loop must be cleared out of the way, the above should be
a branch of an expandable conditional test, else one needs something such
as:
%
\leftedline
{|\xint_afterfi{\expandafter\xintbreakiloopanddo\expandafter\macro\xintiloopindex.}%|}
%
\leftedline{|\fi etc..etc.. \repeat|}
There is \csbxint{iloopskiptonext} to abort the current iteration and skip to
the next, \hyperref[xintiloopskipandredo]{\ttfamily\hyphenchar\font45 \char92
xintiloopskip\-and\-redo} to skip to the end of the current iteration and redo
it with the same value of the index (something else will have to change for this
not to become an eternal loop\dots ).
Inside alignments, if the looped-over text contains a |&| or a |\cr|, any
un-expandable material before a \csbxint{iloopindex} will make it fail because
of |\endtemplate|; in such cases one can always either replace |&| by a macro
expanding to it or replace it by a suitable |\firstofone{&}|, and similarly for
|\cr|.
\phantomsection\label{edefprimes}
As an example, let us construct an |\edef\z{...}| which will define |\z| to be a
list of prime numbers:
\begin{everbatim*}
\begingroup
\edef\z
{\xintiloop [10001+2]
{\xintiloop [3+2]
\ifnum\xintouteriloopindex<\numexpr\xintiloopindex*\xintiloopindex\relax
\xintouteriloopindex,
\expandafter\xintbreakiloop
\fi
\ifnum\xintouteriloopindex=\numexpr
(\xintouteriloopindex/\xintiloopindex)*\xintiloopindex\relax
\else
\repeat
}% no space here
\ifnum \xintiloopindex < 10999 \repeat }%
\meaning\z\endgroup
\end{everbatim*}and we should have taken
some steps to not have a trailing comma, but
the point was to show that one can do that in an |\edef|\,! See also
\autoref{ssec:primesII} which extracts from this code its way of testing
primality.
Let us create an alignment where each row will contain all divisors of its
first entry.
Here is the output, thus obtained without any count register:
\begin{everbatim*}
\begin{multicols}2
\tabskip1ex \normalcolor
\halign{&\hfil#\hfil\cr
\xintiloop [1+1]
{\expandafter\bfseries\xintiloopindex &
\xintiloop [1+1]
\ifnum\xintouteriloopindex=\numexpr
(\xintouteriloopindex/\xintiloopindex)*\xintiloopindex\relax
\xintiloopindex&\fi
\ifnum\xintiloopindex<\xintouteriloopindex\space % CRUCIAL \space HERE
\repeat \cr }%
\ifnum\xintiloopindex<30
\repeat
}
\end{multicols}
\end{everbatim*}
We wanted this first entry in bold face, but |\bfseries| leads to
unexpandable tokens, so the |\expandafter| was necessary for |\xintiloopindex|
and |\xintouteriloopindex| not to be confronted with a hard to digest
|\endtemplate|. An alternative way of coding:
%
\begin{everbatim}
\tabskip1ex
\def\firstofone #1{#1}%
\halign{&\hfil#\hfil\cr
\xintiloop [1+1]
{\bfseries\xintiloopindex\firstofone{&}%
\xintiloop [1+1] \ifnum\xintouteriloopindex=\numexpr
(\xintouteriloopindex/\xintiloopindex)*\xintiloopindex\relax
\xintiloopindex\firstofone{&}\fi
\ifnum\xintiloopindex<\xintouteriloopindex\space % \space is CRUCIAL
\repeat \firstofone{\cr}}%
\ifnum\xintiloopindex<30 \repeat }
\end{everbatim}
\subsection{Another completely expandable prime test}\label{ssec:primesII}
The |\IsPrime| macro from \autoref{ssec:primesI} checked expandably if a (short)
integer was prime, here is a partial rewrite using \csbxint{iloop}. We use the
|etoolbox| expandable conditionals for convenience, but not everywhere as
|\xintiloopindex| can not be evaluated while being braced. This is also the
reason why |\xintbreakiloopanddo| is delimited, and the next macro
|\SmallestFactor| which returns the smallest prime factor examplifies that. One
could write more efficient completely expandable routines, the aim here was only
to illustrate use of the general purpose \csbxint{iloop}. A little table giving
the first values of |\SmallestFactor| follows, its coding uses \csbxint{For},
which is described later; none of this uses count registers.
%
\begin{everbatim*}
\let\IsPrime\undefined \let\SmallestFactor\undefined % clean up possible previous mess
\newcommand{\IsPrime}[1] % returns 1 if #1 is prime, and 0 if not
{\ifnumodd {#1}
{\ifnumless {#1}{8}
{\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes
{\if
\xintiloop [3+2]
\ifnum#1<\numexpr\xintiloopindex*\xintiloopindex\relax
\expandafter\xintbreakiloopanddo\expandafter1\expandafter.%
\fi
\ifnum#1=\numexpr (#1/\xintiloopindex)*\xintiloopindex\relax
\else
\repeat 00\expandafter0\else\expandafter1\fi
}%
}% END OF THE ODD BRANCH
{\ifnumequal {#1}{2}{1}{0}}% EVEN BRANCH
}%
\catcode`_ 11
\newcommand{\SmallestFactor}[1] % returns the smallest prime factor of #1>1
{\ifnumodd {#1}
{\ifnumless {#1}{8}
{#1}% 3,5,7 are primes
{\xintiloop [3+2]
\ifnum#1<\numexpr\xintiloopindex*\xintiloopindex\relax
\xint_afterfi{\xintbreakiloopanddo#1.}%
\fi
\ifnum#1=\numexpr (#1/\xintiloopindex)*\xintiloopindex\relax
\xint_afterfi{\expandafter\xintbreakiloopanddo\xintiloopindex.}%
\fi
\iftrue\repeat
}%
}% END OF THE ODD BRANCH
{2}% EVEN BRANCH
}%
\catcode`_ 8
{\centering
\begin{tabular}{|c|*{10}c|}
\hline
\xintFor #1 in {0,1,2,3,4,5,6,7,8,9}\do {&\bfseries #1}\\
\hline
\bfseries 0&--&--&2&3&2&5&2&7&2&3\\
\xintFor #1 in {1,2,3,4,5,6,7,8,9}\do
{\bfseries #1%
\xintFor #2 in {0,1,2,3,4,5,6,7,8,9}\do
{&\SmallestFactor{#1#2}}\\}%
\hline
\end{tabular}\par
}
\end{everbatim*}
\subsection{A table of factorizations}
\label{ssec:factorizationtable}
As one more example with \csbxint{iloop} let us use an alignment to display the
factorization of some numbers. The loop will actually only play a minor r\^ole
here, just handling the row index, the row contents being almost entirely
produced via a macro |\factorize|. The factorizing macro does not use
|\xintiloop| as it didn't appear to be the convenient tool. As |\factorize| will
have to be used on |\xintiloopindex|, it has been defined as a delimited macro.
To spare some fractions of a second in the compilation time of this document
(which has many many other things to do), \number"7FFFFFED{} and
\number"7FFFFFFF, which turn out to be prime numbers, are not given to
|factorize| but just typeset directly; this illustrates use of
\csbxint{iloopskiptonext}.
The code next generates a \hyperref[floatfactorize]{table} which has
been made into a float appearing \vpageref{floatfactorize}. Here is now
the code for factorization; the conditionals use the package provided
|\xint_firstoftwo| and |\xint_secondoftwo|, one could have employed
rather \LaTeX{}'s own |\@firstoftwo| and |\@secondoftwo|, or, simpler
still in \LaTeX{} context, the |\ifnumequal|, |\ifnumless| \dots,
utilities from the package |etoolbox| which do exactly that under the
hood. Only \TeX{} acceptable numbers are treated here, but it would be
easy to make a translation and use the \xintname macros, thus extending
the scope to big numbers; naturally up to a cost in speed.
The reason for some strange looking expressions is to avoid arithmetic overflow.
\begin{everbatim*}
\catcode`_ 11
\def\abortfactorize #1\xint_secondoftwo\fi #2#3{\fi}
\def\factorize #1.{\ifnum#1=1 \abortfactorize\fi
\ifnum\numexpr #1-2=\numexpr ((#1/2)-1)*2\relax
\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi
{2&\expandafter\factorize\the\numexpr#1/2.}%
{\factorize_b #1.3.}}%
\def\factorize_b #1.#2.{\ifnum#1=1 \abortfactorize\fi
\ifnum\numexpr #1-(#2-1)*#2<#2
#1\abortfactorize
\fi
\ifnum \numexpr #1-#2=\numexpr ((#1/#2)-1)*#2\relax
\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi
{#2&\expandafter\factorize_b\the\numexpr#1/#2.#2.}%
{\expandafter\factorize_b\the\numexpr #1\expandafter.%
\the\numexpr #2+2.}}%
\catcode`_ 8
\begin{figure*}[ht!]
\centering\phantomsection\label{floatfactorize}\normalcolor
\tabskip1ex
\centeredline{\vbox{\halign {\hfil\strut#\hfil&&\hfil#\hfil\cr\noalign{\hrule}
\xintiloop ["7FFFFFE0+1]
\expandafter\bfseries\xintiloopindex &
\ifnum\xintiloopindex="7FFFFFED
\number"7FFFFFED\cr\noalign{\hrule}
\expandafter\xintiloopskiptonext
\fi
\expandafter\factorize\xintiloopindex.\cr\noalign{\hrule}
\ifnum\xintiloopindex<"7FFFFFFE
\repeat
\bfseries \number"7FFFFFFF&\number "7FFFFFFF\cr\noalign{\hrule}
}}}
\centeredline{A table of factorizations}
\end{figure*}
\end{everbatim*}
\begin{framed}
The next utilities are not compatible with expansion-only context.
\end{framed}
\subsection{\csbh{xintApplyInline}}\label{xintApplyInline}
\csa{xintApplyInline}|{\macro}|\marg{list}\ntype{o{\lowast f}} works non
expandably. It applies the one-parameter |\macro| to the first element of the
expanded list (|\macro| may have itself some arguments, the list item will be
appended as last argument), and is then re-inserted in the input stream after
the tokens resulting from this first expansion of |\macro|. The next item is
then handled.
This is to be used in situations where one needs to do some repetitive
things. It is not expandable and can not be completely expanded inside a
macro definition, to prepare material for later execution, contrarily to what
\csbxint{Apply} or \csbxint{ApplyUnbraced} achieve.
\begin{everbatim*}
\def\Macro #1{\advance\cnta #1 , \the\cnta}
\cnta 0
0\xintApplyInline\Macro {3141592653}.
\end{everbatim*}
The first argument |\macro| does not have to be an expandable macro.
\csa{xintApplyInline} submits its second, token list parameter to an
\hyperref[ssec:expansions]{\fexpan
sion}. Then, each \emph{unbraced} item will also be \fexpan ded. This provides
an easy way to insert one list inside another. \emph{Braced} items are not
expanded. Spaces in-between items are gobbled (as well as those at the start
or the end of the list), but not the spaces \emph{inside} the braced items.
\csa{xintApplyInline}, despite being non-expandable, does survive to
contexts where the executed |\macro| closes groups, as happens inside
alignments with the tabulation character |&|.
This tabular provides an example:\par
\begin{everbatim*}
\centerline{\normalcolor\begin{tabular}{ccc}
$N$ & $N^2$ & $N^3$ \\ \hline
\def\Row #1{ #1 & \xintiiSqr {#1} & \xintiiPow {#1}{3} \\ \hline }%
\xintApplyInline \Row {\xintCSVtoList{17,28,39,50,61}}
\end{tabular}}\medskip
\end{everbatim*}
We see that despite the fact that the first encountered tabulation character in
the first row close a group and thus erases |\Row| from \TeX's memory,
|\xintApplyInline| knows how to deal with this.
Using \csbxint{ApplyUnbraced} is an alternative: the difference is that
this would have prepared all rows first and only put them back into the
token stream once they are all assembled, whereas with |\xintApplyInline|
each row is constructed and immediately fed back into the token stream: when
one does things with numbers having hundreds of digits, one learns that
keeping on hold and shuffling around hundreds of tokens has an impact on
\TeX{}'s speed (make this ``thousands of tokens'' for the impact to be
noticeable).
One may nest various |\xintApplyInline|'s. For example (see the
\hyperref[float]{table} \vpageref{float}):\par
\begin{everbatim*}
\begin{figure*}[ht!]
\centering\phantomsection\label{float}
\def\Row #1{#1:\xintApplyInline {\Item {#1}}{0123456789}\\ }%
\def\Item #1#2{&\xintiPow {#1}{#2}}%
\centeredline {\begin{tabular}{ccccccccccc} &0&1&2&3&4&5&6&7&8&9\\ \hline
\xintApplyInline \Row {0123456789}
\end{tabular}}
\end{figure*}
\end{everbatim*}
One could not move the definition of |\Item| inside the tabular,
as it would get lost after the first |&|. But this
works:
\everb|@
\begin{tabular}{ccccccccccc}
&0&1&2&3&4&5&6&7&8&9\\ \hline
\def\Row #1{#1:\xintApplyInline {&\xintiPow {#1}}{0123456789}\\ }%
\xintApplyInline \Row {0123456789}
\end{tabular}
|
A limitation is that, contrarily to what one may have expected, the
|\macro| for an |\xintApplyInline| can not be used to define
the |\macro| for a nested sub-|\xintApplyInline|. For example,
this does not work:\par
\everb|@
\def\Row #1{#1:\def\Item ##1{&\xintiPow {#1}{##1}}%
\xintApplyInline \Item {0123456789}\\ }%
\xintApplyInline \Row {0123456789} % does not work
|
\noindent But see \csbxint{For}.
\subsection{\csbh{xintFor}, \csbh{xintFor*}}\label{xintFor}\label{xintFor*}
\csbxint{For}\ntype{on} is a new kind of for loop. Rather than using macros
for encapsulating list items, its behavior is more like a macro with parameters:
|#1|, |#2|, \dots, |#9| are used to represent the items for up to nine levels of
nested loops. Here is an example:
%
\everb|@
\xintFor #9 in {1,2,3} \do {%
\xintFor #1 in {4,5,6} \do {%
\xintFor #3 in {7,8,9} \do {%
\xintFor #2 in {10,11,12} \do {%
$$#9\times#1\times#3\times#2=\xintiiPrd{{#1}{#2}{#3}{#9}}$$}}}}
|
\noindent This example illustrates that one does not have to use |#1| as the
first one:
the order is arbitrary. But each level of nesting should have its specific macro
parameter. Nine levels of nesting is presumably overkill, but I did not know
where it was reasonable to stop. |\par| tokens are accepted in both the comma
separated list and the replacement text.
\begin{framed}
A macro |\macro| whose definition uses internally an \csbxint{For} loop may be
used inside another \csbxint{For} loop even if the two loops both use the same
macro parameter. Note: the loop definition inside |\macro| must double
the character |#| as is the general rule in \TeX{} with definitions done
inside macros.
The macros \csa{xintFor} and \csa{xintFor*} are not expandable, one can not
use them inside an |\edef|. But they may be used inside alignments (such as a
\LaTeX{} |tabular|), as will be shown in examples.
\end{framed}
The spaces between the various declarative elements are all optional;
furthermore spaces around the commas or at the start and end of the list
argument are allowed, they will be removed. If an item must contain itself
commas, it should be braced to prevent these commas from being misinterpreted as
list separator. These braces will be removed during processing. The list
argument may be a macro |\MyList| expanding in one step to the comma separated
list (if it has no arguments, it does not have to be braced). It
will be expanded (only once) to reveal its comma separated items for processing,
comma separated items will not be expanded before being fed into the replacement
text as |#1|, or |#2|, etc\dots, only leading and trailing spaces are removed.
A starred variant \csbxint{For*}\ntype{{\lowast f}n} deals with lists of braced
items, rather than comma separated items. It has also a distinct expansion
policy, which is detailed below.
Contrarily to what happens in loops where the item is represented by a macro,
here it is truly exactly as when defining (in \LaTeX{}) a ``command'' with
parameters |#1|, etc... This may avoid the user quite a few troubles with
|\expandafter|s or other |\edef/\noexpand|s which one encounters at times when
trying to do things with \LaTeX's {\makeatother|\@for|} or other loops
which encapsulate the item in a macro expanding to that item.
\begin{framed}
The non-starred variant \csbxint{For} deals with comma separated values
(\emph{spaces before and after the commas are removed}) and the comma
separated list may be a macro which is only expanded once (to prevent
expansion of the first item |\x| in a list directly input as |\x,\y,...| it
should be input as |{\x},\y,..| or |<space>\x,\y,..|, naturally all of that
within the mandatory braces of the \csa{xintFor \#n in \{list\}} syntax). The
items are not expanded, if the input is |<stuff>,\x,<stuff>| then |#1| will be
at some point |\x| not its expansion (and not either a macro with |\x| as
replacement text, just the token |\x|). Input such as |<stuff>,,<stuff>|
creates an empty |#1|, the iteration is not skipped. An empty list does lead
to the use of the replacement text, once, with an empty |#1| (or |#n|). Except
if the entire list is represented as a single macro with no parameters,
\fbox{it must be braced.}
\end{framed}
\begin{framed}
The starred variant \csbxint{For*} deals with token lists (\emph{spaces
between braced items or single tokens are not significant}) and
\hyperref[ssec:expansions]{\fexpan ds} each \emph{unbraced} list item. This
makes it easy to simulate concatenation of various list macros |\x|, |\y|, ...
If |\x| expands to |{1}{2}{3}| and |\y| expands to |{4}{5}{6}| then |{\x\y}|
as argument to |\xintFor*| has the same effect as |{{1}{2}{3}{4}{5}{6}}|%
\stepcounter{footnote}%
\makeatletter\hbox {\@textsuperscript {\normalfont \thefootnote
}}\makeatother. Spaces at the start, end, or in-between items are gobbled
(but naturally not the spaces which may be inside \emph{braced} items). Except
if the list argument is a single macro with no parameters, \fbox{it must be
braced.} Each item which is not braced will be fully expanded (as the |\x|
and |\y| in the example above). An empty list leads to an empty result.
\end{framed}
\begingroup\makeatletter
\def\@footnotetext #1{\insert\footins {\reset@font \footnotesize \interlinepenalty \interfootnotelinepenalty \splittopskip \footnotesep \splitmaxdepth \dp \strutbox \floatingpenalty \@MM \hsize \columnwidth \@parboxrestore \color@begingroup \@makefntext {\rule \z@ \footnotesep \ignorespaces #1\@finalstrut \strutbox }\color@endgroup }}
\addtocounter{footnote}{-1}
\edef\@thefnmark {\thefootnote}
\@footnotetext{braces around single token items
are optional so this is the same as \texttt{\{123456\}}.}
\endgroup
\addtocounter{Hfootnote}{1}
The macro \csbxint{Seq} which generates arithmetic sequences may only be used
with \csbxint{For*} (numbers from output of |\xintSeq| are braced, not separated
by commas). %
%
\leftedline{|\xintFor* #1 in {\xintSeq [+2]{-7}{+2}}\do {stuff
with #1}|} will have |#1=-7,-5,-3,-1, and 1|. The |#1| as issued from the
list produced by \csbxint{Seq} is the litteral representation as would be
produced by |\arabic| on a \LaTeX{} counter, it is not a count register. When
used in |\ifnum| tests or other contexts where \TeX{} looks for a number it
should thus be postfixed with |\relax| or |\space|.
When nesting \csa{xintFor*} loops, using \csa{xintSeq} in the inner loops is
inefficient, as the arithmetic sequence will be re-created each time. A more
efficient style is:
%
\begin{everbatim}
\edef\innersequence {\xintSeq[+2]{-50}{50}}%
\xintFor* #1 in {\xintSeq {13}{27}} \do
{\xintFor* #2 in \innersequence \do {stuff with #1 and #2}%
.. some other macros .. }
\end{everbatim}
This is a general remark applying for any nesting of loops, one should avoid
recreating the inner lists of arguments at each iteration of the outer loop.
However, in the example above, if the |.. some other macros ..| part
closes a group which was opened before the |\edef\innersequence|, then
this definition will be lost. An alternative to |\edef|, also efficient,
exists when dealing with arithmetic sequences: it is to use the
\csbxint{integers} keyword (described later) which simulates infinite
arithmetic sequences; the loops will then be terminated via a test |#1|
(or |#2| etc\dots) and subsequent use of \csbxint{BreakFor}.
The \csbxint{For} loops are not completely expandable; but they may be nested
and used inside alignments or other contexts where the replacement text closes
groups. Here is an example (still using \LaTeX's tabular):
\begin{everbatim*}
\begin{tabular}{rccccc}
\xintFor #7 in {A,B,C} \do {%
#7:\xintFor* #3 in {abcde} \do {&($ #3 \to #7 $)}\\ }%
\end{tabular}
\end{everbatim*}
When
inserted inside a macro for later execution the |#| characters must be
doubled.%
%
\footnote{sometimes what seems to be a macro argument isn't really; in
\csa{raisebox\{1cm\}\{}\csa{xintFor \#1 in \{a,b,c\} }\csa{do
\{\#1\}\}} no doubling should be done.}
%
For example:
%
\begin{everbatim*}
\def\T{\def\z {}%
\xintFor* ##1 in {{u}{v}{w}} \do {%
\xintFor ##2 in {x,y,z} \do {%
\expandafter\def\expandafter\z\expandafter {\z\sep (##1,##2)} }%
}%
}%
\T\def\sep {\def\sep{, }}\z
\end{everbatim*}
Similarly when the replacement text
of |\xintFor| defines a macro with parameters, the macro character |#| must be
doubled.
It is licit to use inside an \csbxint{For} a |\macro| which itself has
been defined to use internally some other \csbxint{For}. The same macro
parameter |#1| can be used with no conflict (as mentioned above, in the
definition of |\macro| the |#| used in the \csbxint{For} declaration must be
doubled, as is the general rule in \TeX{} with things defined inside other
things).
The iterated commands as well as the list items are allowed to contain explicit
|\par| tokens. Neither \csbxint{For} nor \csbxint{For*} create groups. The
effect is like piling up the iterated commands with each time |#1| (or |#2| ...)
replaced by an item of the list. However, contrarily to the completely
expandable \csbxint{ApplyUnbraced}, but similarly to the non completely
expandable \csbxint{ApplyInline} each iteration is executed first before looking
at the next |#1|%
%
\footnote{to be completely honest, both \csbxint{For} and
\csbxint{For*} initially scoop up both the list and the iterated
commands; \csbxint{For} scoops up a second time the entire comma
separated list in order to feed it to \csbxint{CSVtoList}. The starred
variant \csbxint{For*} which does not need this step will thus be a
bit faster on equivalent inputs.}
%
(and
the starred variant \csbxint{For*} keeps on expanding each unbraced item it
finds, gobbling spaces).
\subsection{\csbh{xintifForFirst}, \csbh{xintifForLast}}
\label{xintifForFirst}\label{xintifForLast}
\csbxint{ifForFirst}\,\texttt{\{YES branch\}\{NO branch\}}\etype{nn}
and \csbxint{ifForLast}\,\texttt{\{YES
branch\}\hskip 0pt plus 0.2em \{NO branch\}}\etype{nn} execute the |YES| or
|NO| branch
if the
\csbxint{For}
or \csbxint{For*} loop is currently in its first, respectively last, iteration.
Designed to work as expected under nesting. Don't forget an empty brace pair
|{}| if a branch is to do nothing. May be used multiple times in the replacement
text of the loop.
There is no such thing as an iteration counter provided by the \csa{xintFor}
loops; the user is invited to define if needed his own count register or
\LaTeX{} counter, for example with a suitable |\stepcounter| inside the
replacement text of the loop to update it.
\begin{framed}
It is a known feature of these conditionals that they cease to function if
put at a location of the |\xintFor| replacement text which has closed a
group, for example in the last cell of an alignment created by the loop,
assuming the replacement text of the |\xintFor| loop creates a row. The
conditional must be used before the first cell is closed. This is not likely
to change in future versions. It is not an intrinsic limitation as the
branches of the conditional can be the complete rows, inclusive of all |&|'s
and the tabular newline |\\|.
\end{framed}
\subsection{ \csbh{xintBreakFor}, \csbh{xintBreakForAndDo}}
\label{xintBreakFor}\label{xintBreakForAndDo}
One may immediately terminate an \csbxint{For} or \csbxint{For*} loop with
\csbxint{BreakFor}. As the criterion for breaking will be decided on a
basis of some test, it is recommended to use for this test the syntax of
\href{http://ctan.org/pkg/ifthen}{ifthen}%
%
\footnote{\url{http://ctan.org/pkg/ifthen}}
%
or
\href{http://ctan.org/pkg/etoolbox}{etoolbox}%
%
\footnote{\url{http://ctan.org/pkg/etoolbox}}
%
or the \xintname own conditionals, rather than one of the various
|\if...\fi| of \TeX{}. Else (and this is without even mentioning all the various
pecularities of the
|\if...\fi| constructs), one has to carefully move the break after the closing
of
the conditional, typically with |\expandafter\xintBreakFor\fi|.%
%
\footnote{the difficulties here are similar to those mentioned in
\autoref{sec:ifcase}, although less severe, as complete expandability
is not to be maintained; hence the allowed use of
\href{http://ctan.org/pkg/ifthen}{ifthen}.}
There is also \csbxint{BreakForAndDo}. Both are illustrated by various examples
in the next section which is devoted to ``forever'' loops.
\subsection{\csbh{xintintegers}, \csbh{xintdimensions}, \csbh{xintrationals}}
\label{xintegers}\label{xintintegers}
\label{xintdimensions}\label{xintrationals}
If the list argument to \csbxint{For} (or \csbxint{For*}, both are equivalent in
this context) is \csbxint{integers} (equivalently \csbxint{egers}) or more
generally \csbxint{integers}|[||start|\allowbreak|+|\allowbreak|delta||]|
(\emph{the whole within braces}!)%
%
\footnote{the |start+delta| optional specification may have extra spaces
around the plus sign of near the square brackets, such spaces are
removed. The same applies with \csa{xintdimensions} and
\csa{xintrationals}.},
%
then \csbxint{For} does an infinite iteration where
|#1| (or |#2|, \dots, |#9|) will run through the arithmetic sequence of (short)
integers with initial value |start| and increment |delta| (default values:
|start=1|, |delta=1|; if the optional argument is present it must contains both
of them, and they may be explicit integers, or macros or count registers). The
|#1| (or |#2|, \dots, |#9|) will stand for |\numexpr <opt sign><digits>\relax|,
and the litteral representation as a string of digits can thus be obtained as
\fbox{\csa{the\#1}} or |\number#1|. Such a |#1| can be used in an |\ifnum| test
with no need to be postfixed with a space or a |\relax| and one should
\emph{not} add them.
If the list argument is \csbxint{dimensions} or more generally
\csbxint{dimensions}|[||start|\allowbreak|+|\allowbreak|delta||]| (\emph{within
braces}!), then
\csbxint{For} does an infinite iteration where |#1| (or |#2|, \dots, |#9|) will
run through the arithmetic sequence of dimensions with initial value
|start| and increment |delta|. Default values: |start=0pt|, |delta=1pt|; if
the optional argument is present it must contain both of them, and they may
be explicit specifications, or macros, or dimen registers, or length commands
in \LaTeX{} (the stretch and shrink components will be discarded). The |#1|
will be |\dimexpr <opt sign><digits>sp\relax|, from which one can get the
litteral (approximate) representation in points via |\the#1|. So |#1| can be
used anywhere \TeX{} expects a dimension (and there is no need in conditionals
to insert a |\relax|, and one should \emph{not} do it), and to print its value
one uses \fbox{\csa{the\#1}}. The chosen representation guarantees exact
incrementation with no rounding errors accumulating from converting into
points at each step.
If the list argument to \csbxint{For} (or \csbxint{For*}) is \csbxint{rationals}
or more generally
\csbxint{rationals}|[||start|\allowbreak|+|\allowbreak|delta||]| (\emph{within
braces}!), then \csbxint{For} does an infinite iteration where |#1| (or |#2|,
\dots, |#9|) will run through the arithmetic sequence of \xintfracname fractions
with initial value |start| and increment |delta| (default values: |start=1/1|,
|delta=1/1|). This loop works \emph{only with \xintfracname loaded}. if the
optional argument is present it must contain both of them, and they may be given
in any of the formats recognized by \xintfracname (fractions, decimal
numbers, numbers in scientific notations, numerators and denominators in
scientific notation, etc...) , or as macros or count registers (if they are
short integers). The |#1| (or |#2|, \dots, |#9|) will be an |a/b| fraction
(without a |[n]| part), where
the denominator |b| is the product of the denominators of
|start| and |delta| (for reasons of speed |#1| is not reduced to irreducible
form, and for another reason explained later |start| and |delta| are not put
either into irreducible form; the input may use explicitely \csa{xintIrr} to
achieve that).
\begin{everbatim*}
\begingroup\small
\noindent\parbox{\dimexpr\linewidth-3em}{\color[named]{OrangeRed}%
\xintFor #1 in {\xintrationals [10/21+1/21]} \do
{#1=\xintifInt {#1}
{\textcolor{blue}{\xintTrunc{10}{#1}}}
{\xintTrunc{10}{#1}}% display in blue if an integer
\xintifGt {#1}{1.123}{\xintBreakFor}{, }%
}}
\endgroup\smallskip
\end{everbatim*}
\smallskip The example above confirms that computations are done exactly, and
illustrates that the two initial (reduced) denominators are not multiplied when
they are found to be equal. It is thus recommended to input |start| and |delta|
with a common smallest possible denominator, or as fixed point numbers with the
same numbers of digits after the decimal mark; and this is also the reason why
|start| and |delta| are not by default made irreducible. As internally the
computations are done with numerators and denominators completely expanded, one
should be careful not to input numbers in scientific notation with exponents in
the hundreds, as they will get converted into as many zeroes.
\begin{everbatim*}
\noindent\parbox{\dimexpr.7\linewidth}{\raggedright
\xintFor #1 in {\xintrationals [0.000+0.125]} \do
{\edef\tmp{\xintTrunc{3}{#1}}%
\xintifInt {#1}
{\textcolor{blue}{\tmp}}
{\tmp}%
\xintifGt {#1}{2}{\xintBreakFor}{, }%
}}\smallskip
\end{everbatim*}
We see here that \csbxint{Trunc} outputs (deliberately) zero as $0$, not (here)
$0.000$, the idea being not to lose the information that the truncated thing was
truly zero. Perhaps this behavior should be changed? or made optional? Anyhow
printing of fixed points numbers should be dealt with via dedicated packages
such as |numprint| or |siunitx|.\par
\subsection{Another table of primes}\label{ssec:primesIII}
As a further example, let us dynamically generate a tabular with the first $50$
prime numbers after $12345$. First we need a macro to test if a (short) number
is prime. Such a completely expandable macro was given in \autoref{xintSeq},
here we consider a variant which will be slightly more efficient. This new
|\IsPrime| has two parameters. The first one is a macro which it redefines to
expand to the result of the primality test applied to the second argument. For
convenience we use the \href{http://ctan.org/pkg/etoolbox}{etoolbox} wrappers to
various |\ifnum| tests, although here there isn't anymore the constraint of
complete expandability (but using explicit |\if..\fi| in tabulars has its
quirks); equivalent tests are provided by \xintname, but they have some overhead
as they are able to deal with arbitrarily big integers.
\def\IsPrime #1#2%
{\edef\TheNumber {\the\numexpr #2}% positive integer
\ifnumodd {\TheNumber}
{\ifnumgreater {\TheNumber}{1}
{\edef\ItsSquareRoot{\xintiSqrt \TheNumber}%
\xintFor ##1 in {\xintintegers [3+2]}\do
{\ifnumgreater {##1}{\ItsSquareRoot}
{\def#1{1}\xintBreakFor}
{}%
\ifnumequal {\TheNumber}{(\TheNumber/##1)*##1}
{\def#1{0}\xintBreakFor }
{}%
}}
{\def#1{0}}}% 1 is not prime
{\ifnumequal {\TheNumber}{2}{\def#1{1}}{\def#1{0}}}%
}%
\everb|@
\def\IsPrime #1#2% """color[named]{PineGreen}#1=\Result, #2=tested number (assumed >0).;!
{\edef\TheNumber {\the\numexpr #2}%"""color[named]{PineGreen} hence #2 may be a count or \numexpr.;!
\ifnumodd {\TheNumber}
{\ifnumgreater {\TheNumber}{1}
{\edef\ItsSquareRoot{\xintiSqrt \TheNumber}%
\xintFor """color{red}##1;! in {"""color{red}\xintintegers;! [3+2]}\do
{\ifnumgreater {"""color{red}##1;!}{\ItsSquareRoot} """color[named]{PineGreen}% "textcolor{red}{##1} is a \numexpr.;!
{\def#1{1}\xintBreakFor}
{}%
\ifnumequal {\TheNumber}{(\TheNumber/##1)*##1}
{\def#1{0}\xintBreakFor }
{}%
}}
{\def#1{0}}}% 1 is not prime
{\ifnumequal {\TheNumber}{2}{\def#1{1}}{\def#1{0}}}%
}
|
As we used \csbxint{For} inside a macro we had to double the |#| in its |#1|
parameter. Here is now the code which creates the prime table (the table has
been put in a \hyperref[primes]{float}, which should be found on page
\pageref{primes}):
\everb?@
\newcounter{primecount}
\newcounter{cellcount}
\begin{figure*}[ht!]
\centering
\begin{tabular}{|*{7}c|}
\hline
\setcounter{primecount}{0}\setcounter{cellcount}{0}%
\xintFor """color{red}#1;! in {"""color{red}\xintintegers;! [12345+2]} \do
"""color[named]{PineGreen}% "textcolor{red}{#1} is a \numexpr.;!
{\IsPrime\Result{#1}%
\ifnumgreater{\Result}{0}
{\stepcounter{primecount}%
\stepcounter{cellcount}%
\ifnumequal {\value{cellcount}}{7}
{"""color{red}\the#1;! \\\setcounter{cellcount}{0}}
{"""color{red}\the#1;! &}}
{}%
\ifnumequal {\value{primecount}}{50}
{\xintBreakForAndDo
{\multicolumn {6}{l|}{These are the first 50 primes after 12345.}\\}}
{}%
}\hline
\end{tabular}
\end{figure*}
?
\begin{figure*}[ht!]
\centering\phantomsection\label{primes}
\begin{tabular}{|*{7}c|}
\hline
\setcounter{primecount}{0}\setcounter{cellcount}{0}%
\xintFor #1 in {\xintintegers [12345+2]} \do
{\IsPrime\Result{#1}%
\ifnumgreater{\Result}{0}
{\stepcounter{primecount}%
\stepcounter{cellcount}%
\ifnumequal {\value{cellcount}}{7}
{\the#1 \\\setcounter{cellcount}{0}}
{\the#1 &}}
{}%
\ifnumequal {\value{primecount}}{50}
{\xintBreakForAndDo
{\multicolumn {6}{l|}{These are the first 50 primes after 12345.}\\}}
{}%
}\hline
\end{tabular}
\end{figure*}
\subsection{Some arithmetic with Fibonacci numbers}
\label{ssec:fibonacci}
Here is the code employed on the title page to compute (expandably, of
course!) the 1250th Fibonacci number:
\begin{everbatim*}
\catcode`_ 11
\def\Fibonacci #1{% \Fibonacci{N} computes F(N) with F(0)=0, F(1)=1.
\expandafter\Fibonacci_a\expandafter
{\the\numexpr #1\expandafter}\expandafter
{\romannumeral0\xintiieval 1\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval 1\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval 1\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval 0\relax}}
%
\def\Fibonacci_a #1{%
\ifcase #1
\expandafter\Fibonacci_end_i
\or
\expandafter\Fibonacci_end_ii
\else
\ifodd #1
\expandafter\expandafter\expandafter\Fibonacci_b_ii
\else
\expandafter\expandafter\expandafter\Fibonacci_b_i
\fi
\fi {#1}%
}% * signs are omitted from the next macros, tacit multiplications
\def\Fibonacci_b_i #1#2#3{\expandafter\Fibonacci_a\expandafter
{\the\numexpr #1/2\expandafter}\expandafter
{\romannumeral0\xintiieval sqr(#2)+sqr(#3)\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval (2#2-#3)#3\relax}%
}% end of Fibonacci_b_i
\def\Fibonacci_b_ii #1#2#3#4#5{\expandafter\Fibonacci_a\expandafter
{\the\numexpr (#1-1)/2\expandafter}\expandafter
{\romannumeral0\xintiieval sqr(#2)+sqr(#3)\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval (2#2-#3)#3\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval #2#4+#3#5\expandafter\relax\expandafter}\expandafter
{\romannumeral0\xintiieval #2#5+#3(#4-#5)\relax}%
}% end of Fibonacci_b_ii
% code as used on title page:
%\def\Fibonacci_end_i #1#2#3#4#5{\xintthe#5}
%\def\Fibonacci_end_ii #1#2#3#4#5{\xinttheiiexpr #2#5+#3(#4-#5)\relax}
% new definitions:
\def\Fibonacci_end_i #1#2#3#4#5{{#4}{#5}}% {F(N+1)}{F(N)} in \xintexpr format
\def\Fibonacci_end_ii #1#2#3#4#5%
{\expandafter
{\romannumeral0\xintiieval #2#4+#3#5\expandafter\relax
\expandafter}\expandafter
{\romannumeral0\xintiieval #2#5+#3(#4-#5)\relax}}% idem.
% \FibonacciN returns F(N) (in encapsulated format: needs \xintthe for printing)
\def\FibonacciN {\expandafter\xint_secondoftwo\romannumeral-`0\Fibonacci }%
\catcode`_ 8
\end{everbatim*}
I have modified the ending: we want not only one specific value |F(N)| but
a pair of successive values which can serve as starting point of another routine
devoted to compute a whole sequence |F(N), F(N+1), F(N+2),....|. This pair is,
for efficiency, kept in the encapsulated internal \xintexprname format.
|\FibonacciN| outputs the single |F(N)|, also as an |\xintexpr|-ession, and
printing it will thus need the |\xintthe| prefix.
\begingroup\footnotesize\sffamily\baselineskip 10pt
Here a code snippet which
checks the routine via a \string\message\ of the first $51$ Fibonacci
numbers (this is not an efficient way to generate a sequence of such
numbers, it is only for validating \csa{FibonacciN}).
%
\begin{everbatim}
\def\Fibo #1.{\xintthe\FibonacciN {#1}}%
\message{\xintiloop [0+1] \expandafter\Fibo\xintiloopindex.,
\ifnum\xintiloopindex<49 \repeat \xintthe\FibonacciN{50}.}
\end{everbatim}
\endgroup
The various |\romannumeral0\xintiieval| could very well all have been
|\xintiiexpr|'s but then we would have needed more |\expandafter|'s.
Indeed the order of expansion must be controlled for the whole thing to work,
and |\romannumeral0\xintiieval| is the first expanded form of |\xintiiexpr|.
The way we use |\expandafter|'s to chain successive |\xintexpr| evaluations is
exactly analogous to well-known expandable techniques made possible by
|\numexpr|.
\begin{framed}
There is a difference though: |\numexpr| is \emph{NOT} expandable, and to
force its expansion we must prefix it with |\the| or |\number|. On the other
hand |\xintexpr|, |\xintiexpr|, ..., (or |\xinteval|, |\xintieval|, ...)
expand fully when prefixed by |\romannumeral-`0|: the computation is fully
executed and its result encapsulated in a private format.
Using |\xintthe| as prefix is necessary to print the result (this is like
|\the| for |\numexpr|), but it is not necessary to get the computation done
(contrarily to the situation with |\numexpr|).
And, starting with release |1.09j|, it is also allowed to expand a non
|\xintthe| prefixed |\xintexpr|-ession inside an |\edef|: the private format
is now protected, hence the error message complaining about a missing
|\xintthe| will not be executed, and the integrity of the format will be
preserved.
This new possibility brings some efficiency gain, when one writes
non-expandable algorithms using \xintexprname. If |\xintthe| is
employed inside |\edef| the number or fraction will be un-locked into
its possibly hundreds of digits and all these tokens will possibly
weigh on the upcoming shuffling of (braced) tokens. The private
encapsulated format has only a few tokens, hence expansion will
proceed a bit faster.
\indent see footnote\footnotemark
\end{framed}
\footnotetext{To be completely honest the examination by \TeX{} of all
successive digits was not avoided, as it occurs already in the
locking-up of the result, what is avoided is to spend time un-locking,
and then have the macros shuffle around possibly hundreds of digit
tokens rather than a few control words.}
Our |\Fibonacci| expands completely under \fexpan sion,
so we can use \hyperref[fdef]{\ttfamily\char92fdef} rather than |\edef| in a
situation such as %
\leftedline {|\fdef \X {\FibonacciN {100}}|} but for the
reasons explained above, it is as efficient to employ |\edef|. And if we want
%
\leftedline{|\edef \Y {(\FibonacciN{100},\FibonacciN{200})}|,} then |\edef| is
necessary.
Allright, so let's now give the code to generate a sequence of braced Fibonacci
numbers |{F(N)}{F(N+1)}{F(N+2)}...|, using |\Fibonacci| for the first
two and then using the standard recursion |F(N+2)=F(N+1)+F(N)|:
\catcode`_ 11
\def\FibonacciSeq #1#2{%#1=starting index, #2>#1=ending index
\expandafter\Fibonacci_Seq\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2-1}%
}%
\def\Fibonacci_Seq #1#2{%
\expandafter\Fibonacci_Seq_loop\expandafter
{\the\numexpr #1\expandafter}\romannumeral0\Fibonacci {#1}{#2}%
}%
\def\Fibonacci_Seq_loop #1#2#3#4{% standard Fibonacci recursion
{#3}\unless\ifnum #1<#4 \Fibonacci_Seq_end\fi
\expandafter\Fibonacci_Seq_loop\expandafter
{\the\numexpr #1+1\expandafter}\expandafter
{\romannumeral0\xintiieval #2+#3\relax}{#2}{#4}%
}%
\def\Fibonacci_Seq_end\fi\expandafter\Fibonacci_Seq_loop\expandafter
#1\expandafter #2#3#4{\fi {#3}}%
\catcode`_ 8
\begingroup\footnotesize\baselineskip10pt
\everb|@
\catcode`_ 11
\def\FibonacciSeq #1#2{%#1=starting index, #2>#1=ending index
\expandafter\Fibonacci_Seq\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2-1}%
}%
\def\Fibonacci_Seq #1#2{%
\expandafter\Fibonacci_Seq_loop\expandafter
{\the\numexpr #1\expandafter}\romannumeral0\Fibonacci {#1}{#2}%
}%
\def\Fibonacci_Seq_loop #1#2#3#4{% standard Fibonacci recursion
{#3}\unless\ifnum #1<#4 \Fibonacci_Seq_end\fi
\expandafter\Fibonacci_Seq_loop\expandafter
{\the\numexpr #1+1\expandafter}\expandafter
{\romannumeral0\xintiieval #2+#3\relax}{#2}{#4}%
}%
\def\Fibonacci_Seq_end\fi\expandafter\Fibonacci_Seq_loop\expandafter
#1\expandafter #2#3#4{\fi {#3}}%
\catcode`_ 8
|
\endgroup
Deliberately and for optimization, this |\FibonacciSeq| macro is
completely expandable but not \fexpan dable. It would be easy to modify
it to be so. But I wanted to check that the \csbxint{For*} does apply
full expansion to what comes next each time it fetches an item from its
list argument. Thus, there is no need to generate lists of braced
Fibonacci numbers beforehand, as \csbxint{For*}, without using any
|\edef|, still manages to generate the list via iterated full expansion.
I initially used only one |\halign| in a three-column |multicols|
environment, but |multicols| only knows to divide the page horizontally
evenly, thus I employed in the end one |\halign| for each column (I
could have then used a |tabular| as no column break was then needed).
\begin{figure*}[ht!]
\phantomsection\label{fibonacci}
\newcounter{index}
\fdef\Fibxxx{\FibonacciN {30}}%
\setcounter{index}{30}%
\centeredline{\tabskip 1ex
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr
\xintFor* #1 in {\FibonacciSeq {30}{59}}\do
{\theindex &\xintthe#1 &
\xintiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{index}\cr }}%
}\vrule
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr
\xintFor* #1 in {\FibonacciSeq {60}{89}}\do
{\theindex &\xintthe#1 &
\xintiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{index}\cr }}%
}\vrule
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr
\xintFor* #1 in {\FibonacciSeq {90}{119}}\do
{\theindex &\xintthe#1 &
\xintiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{index}\cr }}%
}}%
%
\centeredline{Some Fibonacci numbers together with their residues modulo
|F(30)|\dtt{=\xintthe\Fibxxx}}
\end{figure*}
\begingroup\footnotesize\baselineskip10pt
\everb|@
\newcounter{index}
\tabskip 1ex
\fdef\Fibxxx{\FibonacciN {30}}%
\setcounter{index}{30}%
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr
\xintFor* #1 in {\FibonacciSeq {30}{59}}\do
{\theindex &\xintthe#1 &
\xintiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{index}\cr }}%
}\vrule
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr
\xintFor* #1 in {\FibonacciSeq {60}{89}}\do
{\theindex &\xintthe#1 &
\xintiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{index}\cr }}%
}\vrule
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr
\xintFor* #1 in {\FibonacciSeq {90}{119}}\do
{\theindex &\xintthe#1 &
\xintiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{index}\cr }}%
}%
|
\endgroup
This produces the Fibonacci numbers from |F(30)| to |F(119)|, and
computes also all the
congruence classes modulo |F(30)|. The output has
been put in a \hyperref[fibonacci]{float}, which appears
\vpageref[above]{fibonacci}. I leave to the mathematically inclined
readers the task to explain the visible patterns\dots |;-)|.
\subsection{\csbh{xintForpair}, \csbh{xintForthree}, \csbh{xintForfour}}\label{xintForpair}\label{xintForthree}\label{xintForfour}
The syntax\ntype{on} is illustrated in this
example. The notation is the usual one for |n|-uples, with parentheses and
commas. Spaces around commas and parentheses are ignored.
%
\begin{everbatim*}
{\centering\begin{tabular}{cccc}
\xintForpair #1#2 in { ( A , a ) , ( B , b ) , ( C , c ) } \do {%
\xintForpair #3#4 in { ( X , x ) , ( Y , y ) , ( Z , z ) } \do {%
$\Biggl($\begin{tabular}{cc}
-#1- & -#3-\\
-#4- & -#2-\\
\end{tabular}$\Biggr)$&}\\\noalign{\vskip1\jot}}%
\end{tabular}\\}
\end{everbatim*}
Only |#1#2|, |#2#3|, |#3#4|, \dots, |#8#9| are valid (no error check
is done on the input syntax, |#1#3| or similar all end up in errors).
One can nest with \csbxint{For}, for disjoint sets of macro parameters. There is
also \csa{xintForthree} (from |#1#2#3| to |#7#8#9|) and \csa{xintForfour} (from
|#1#2#3#4| to |#6#7#8#9|). |\par| tokens are accepted in both the comma
separated list and the replacement text.
\subsection{\csbh{xintAssign}}\label{xintAssign}
\csa{xintAssign}\meta{braced things}\csa{to}%
\meta{as many cs as they are things} %\ntype{{(f$\to$\lowast [x)}{\lowast N}}
%
defines (without checking if something gets overwritten) the control sequences
on the right of \csa{to} to expand to the successive tokens or braced items
found one after the other on the left of \csa{to}. It is not expandable.
A `full' expansion is first applied to the material in front of
\csa{xintAssign}, which may thus be a macro expanding to a list of braced items.
\xintAssign \xintiiPow {7}{13}\to\SevenToThePowerThirteen
\xintAssign \xintiiDivision{1000000000000}{133333333}\to\Q\R
Special case: if after this initial expansion no brace is found immediately
after \csa{xintAssign}, it is assumed that there is only one control sequence
following |\to|, and this control sequence is then defined via
|\def| to expand to the material between
\csa{xintAssign} and \csa{to}. Other types of expansions are specified through
an optional parameter to \csa{xintAssign}, see \emph{infra}.
%
\leftedline{|\xintAssign \xintiiDivision{1000000000000}{133333333}\to\Q\R|}
%
\leftedline{|\meaning\Q: |\dtt{\meaning\Q}, |\meaning\R:|
\dtt{\meaning\R}} %
%
\leftedline{|\xintAssign \xintiiPow
{7}{13}\to\SevenToThePowerThirteen|}
%
\leftedline{|\SevenToThePowerThirteen|\dtt{=\SevenToThePowerThirteen}}
%
\leftedline{(same as |\edef\SevenToThePowerThirteen{\xintiPow {7}{13}}|)}
\noindent\csa{xintAssign} admits since |1.09i| an
optional parameter, for example |\xintAssign [e]...| or |\xintAssign [oo]
...|. With |[f]| for example the definitions of the macros initially on the
right of |\to| will be made with \hyperref[fdef]{\ttfamily\char92fdef} which
\fexpan ds the replacement text. The default is simply to make the
definitions with |\def|, corresponding to an empty optional paramter |[]|.
Possibilities: |[], [g], [e], [x], [o], [go], [oo], [goo], [f], [gf]|.
In all cases, recall that |\xintAssign| starts with an \fexpan sion of what
comes next; this produces some list of tokens or braced items, and the
optional parameter only intervenes to decide the expansion type to be applied
then to each one of these items.
\emph{Note:} prior to release |1.09j|, |\xintAssign| did an |\edef| by
default, but it now does |\def|. Use the optional parameter |[e]| to force use
of |\edef|.
{\small \emph{Remark:} since |xinttools 1.1c|, \csa{xintAssign} is less picky
and a stray space right before the |\to| causes no surprises, and the
successive braced items may be separated by spaces, which will get
discarded. In case the contents up to |\to| did not start with a brace a
single macro is defined and it will contain the spaces. Contrarily to the
earlier version, there is no problem if such contents do contain braces
after the first non-brace token.
\par
}
\subsection{\csbh{xintAssignArray}}\label{xintAssignArray}
\xintAssignArray \xintBezout {1000}{113}\to\Bez
\csa{xintAssignArray}\meta{braced
things}\csa{to}\csa{myArray} %\ntype{{(f$\to$\lowast x)}N}
%
first expands fully what comes immediately after |\xintAssignArray| and
expects to find a list of braced things |{A}{B}...| (or tokens). It then
defines \csa{myArray} as a macro with one parameter, such that \csa{myArray\x}
expands to give the |x|th braced thing of this original
list (the argument \texttt{\x} itself is fed to a |\numexpr| by |\myArray|,
and |\myArray| expands in two steps to its output). With |0| as parameter,
\csa{myArray}|{0}| returns the number |M| of elements of the array so that the
successive elements are \csa{myArray}|{1}|, \dots, \csa{myArray}|{M}|.
%
\leftedline{|\xintAssignArray \xintBezout {1000}{113}\to\Bez|} will set
|\Bez{0}| to \dtt{\Bez0}, |\Bez{1}| to \dtt{\Bez1}, |\Bez{2}| to
\dtt{\Bez2}, |\Bez{3}| to \dtt{\Bez3}, |\Bez{4}| to
\dtt{\Bez4}, and |\Bez{5}| to \dtt{\Bez5}:
\dtt{(\Bez3)${}\times{}$\Bez1${}-{}$(\Bez4)${}\times{}$\Bez2${}={}$\Bez5.}
This macro is incompatible with expansion-only contexts.
\csa{xintAssignArray} admits now an optional
parameter, for example |\xintAssignArray [e]...|. This means that the
definitions of the macros will be made with |\edef|. The default is
|[]|, which makes the definitions with |\def|. Other possibilities: |[],
[o], [oo], [f]|. Contrarily to \csbxint{Assign} one can not use the |g|
here to make the definitions global. For this, one should rather do
|\xintAssignArray| within a group starting with |\globaldefs 1|.
Note that prior to release |1.09j| each item (token or braced material) was
submitted to an |\edef|, but the default is now to use |\def|.
\subsection{\csbh{xintDigitsOf}}\label{xintDigitsOf}
This is a synonym for \csbxint{AssignArray},\ntype{fN} to be used to define
an array giving all the digits of a given (positive, else the minus sign will
be treated as first item) number.
\begingroup\xintDigitsOf\xintiPow {7}{500}\to\digits
%
\leftedline{|\xintDigitsOf\xintiPow {7}{500}\to\digits|}
\noindent $7^{500}$ has |\digits{0}=|\digits{0} digits, and the 123rd among them
(starting from the most significant) is
|\digits{123}=|\digits{123}.
\endgroup
\subsection{\csbh{xintRelaxArray}}\label{xintRelaxArray}
\csa{xintRelaxArray}\csa{myArray} %\ntype{N}
%
(globally) sets to \csa{relax} all macros which were defined by the previous
\csa{xintAssignArray} with \csa{myArray} as array macro.
\subsection{The Quick Sort algorithm illustrated}\label{ssec:quicksort}
First a completely expandable macro which sorts a comma separated list of
numbers.%
%
\footnote{The code in earlier versions of this manual handled inputs composed
of braced items. I have switched to comma separated inputs on the occasion
of \url{http://tex.stackexchange.com/a/273084}. The version here is like
|code 3| on \url{http://tex.stackexchange.com} (which is about |3x| faster
than the earlier code it replaced in this manual) with a modification to
make it more efficient if the data has many repeated values.
A faster routine (for sorting hundreds of values) is provided as |code 6| at
the link mentioned in the footnote, it is based on Merge Sort, but limited
to inputs which one can handle as \TeX{} dimensions.%
This |code 6| could be extended to handle more general numbers, as
acceptable by \xintfracname. I have also written a non expandable version,
which is even faster, but this matters really only when handling hundreds or
rather thousands of values.}
%
The |\QSx| macro expands its list argument, which may thus be a macro; its
comma separated items must expand to integers or decimal numbers or fractions
or scientific notation as acceptable to \xintfracname, but if an item is
itself some (expandable) macro, this macro will be expanded each time the item
is considered in a comparison test! This is actually good if the macro expands
in one step to the digits, and there are many many digits, but bad if the macro
needs to do many computations. Thus |\QSx| should be used with either explicit
numbers or with items being macros expanding in one step to the numbers
(particularly if these numbers are very big).
If the interest is only in \TeX{} integers, then one should replace the
|\xintifCmp| macro with a suitable conditional, possibly helped by tools such as
|\ifnumgreater|, |\ifnumequal| and |\ifnumless| from
\href{http://ctan.org/pkg/etoolbox}{etoolbox} (\LaTeX{} only; I didn't see a
direct equivalent to |\xintifCmp|.) Or, if we are dealing with decimal numbers
with at most four+four digits, then one should use suitable |\ifdim| tests.
Naturally this will boost consequently the speed, from having skipped all the
overhead in parsing fractions and scientific numbers as are acceptable by
\xintfracname macros, and subsequent treatment.
\begin{everbatim*}
% THE QUICK SORT ALGORITHM EXPANDABLY
% \usepackage{xintfrac} in the preamble (latex)
\makeatletter
% use extra safe delimiters
\catcode`! 3 \catcode`? 3
\def\QSx {\romannumeral0\qsx }%
% first we check if empty list (else \qsx@finish will not find a comma)
\def\qsx #1{\expandafter\qsx@a\romannumeral-`0#1,!,?}%
\def\qsx@a #1{\ifx,#1\expandafter\qsx@abort\else
\expandafter\qsx@start\fi #1}%
\def\qsx@abort #1?{ }%
\def\qsx@start {\expandafter\qsx@finish\romannumeral0\qsx@b,}%
\def\qsx@finish ,#1{ #1}%
%
% we check if empty of single and if not pick up the first as Pivot:
\def\qsx@b ,#1#2,#3{\ifx?#3\xintdothis\qsx@empty\fi
\ifx!#3\xintdothis\qsx@single\fi
\xintorthat\qsx@separate {#1#2}{}{}{#1#2}#3}%
\def\qsx@empty #1#2#3#4#5{ }%
\def\qsx@single #1#2#3#4#5?{, #4}%
\def\qsx@separate #1#2#3#4#5#6,%
{%
\ifx!#5\expandafter\qsx@separate@done\fi
\xintifCmp {#5#6}{#4}%
\qsx@separate@appendtosmaller
\qsx@separate@appendtoequal
\qsx@separate@appendtogreater {#5#6}{#1}{#2}{#3}{#4}%
}%
%
\def\qsx@separate@appendtoequal #1#2{\qsx@separate {#2,#1}}%
\def\qsx@separate@appendtogreater #1#2#3{\qsx@separate {#2}{#3,#1}}%
\def\qsx@separate@appendtosmaller #1#2#3#4{\qsx@separate {#2}{#3}{#4,#1}}%
%
\def\qsx@separate@done\xintifCmp #1%
\qsx@separate@appendtosmaller
\qsx@separate@appendtoequal
\qsx@separate@appendtogreater #2#3#4#5#6#7?%
{%
\expandafter\qsx@f\expandafter {\romannumeral0\qsx@b #4,!,?}{\qsx@b #5,!,?}{#3}%
}%
%
\def\qsx@f #1#2#3{#2, #3#1}%
%
\catcode`! 12 \catcode`? 12
\makeatother
% EXAMPLE
\begingroup
\edef\z {\QSx {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4,
1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9}}
\meaning\z
\def\a {3.123456789123456789}\def\b {3.123456789123456788}
\def\c {3.123456789123456790}\def\d {3.123456789123456787}
\oodef\z {\QSx { \a, \b, \c, \d}}%
% The space before \a to let it not be expanded during the conversion from CSV
% values to List. The \oodef expands exactly twice (via a bunch of \expandafter's)
\meaning\z
\endgroup
\end{everbatim*} (the spaces after \string\d, etc... come from the use of the
|\meaning| primitive.)
The choice of pivot as first element is bad if the list is already almost
sorted. Let's add a variant which will pick up the pivot index randomly. The
previous routine worked also internally with comma separated lists, but for a
change this one will use internally lists of braced items (the initial
conversion via \csbxint{CSVtoList} handles all potential spurious space
problems).
\unless\ifxetex % pour tester compilation de xint.dtx avec xetex qui n'a pas
% \pdfuniformedeviate
\begin{everbatim*}
% QuickSort expandably on comma separated values with random choice of pivots
% ====> Requires availability of \pdfuniformdeviate <====
% \usepackage{xintfrac, xinttools} in preamble
\makeatletter
\def\QSx {\romannumeral0\qsx }% This is a f-expandable macro.
% This converts from comma separated values on input and back on output.
% **** NOTE: these steps (and the other ones too, actually) are costly if input
% has thousands of items.
\def\qsx #1{\xintlistwithsep{, }%
{\expandafter\qsx@sort@a\expandafter{\romannumeral0\xintcsvtolist{#1}}}}%
%
% we check if empty or single or double and if not pick up the first as Pivot:
\def\qsx@sort@a #1%
{\expandafter\qsx@sort@b\expandafter{\romannumeral0\xintlength{#1}}{#1}}%
\def\qsx@sort@b #1{\ifcase #1
\expandafter\qsx@sort@empty
\or\expandafter\qsx@sort@single
\or\expandafter\qsx@sort@double
\else\expandafter\qsx@sort@c\fi {#1}}%
\def\qsx@sort@empty #1#2{ }%
\def\qsx@sort@single #1#2{#2}%
\catcode`_ 11
\def\qsx@sort@double #1#2{\xintifGt #2{\xint_exchangetwo_keepbraces}{}#2}%
\catcode`_ 8
\def\qsx@sort@c #1#2{%
\expandafter\qsx@sort@sep@a\expandafter
{\romannumeral0\xintnthelt{\pdfuniformdeviate #1+\@ne}{#2}}#2?}%
\def\qsx@sort@sep@a #1{\qsx@sort@sep@loop {}{}{}{#1}}%
\def\qsx@sort@sep@loop #1#2#3#4#5%
{%
\ifx?#5\expandafter\qsx@sort@sep@done\fi
\xintifCmp {#5}{#4}%
\qsx@sort@sep@appendtosmaller
\qsx@sort@sep@appendtoequal
\qsx@sort@sep@appendtogreater {#5}{#1}{#2}{#3}{#4}%
}%
%
\def\qsx@sort@sep@appendtoequal #1#2{\qsx@sort@sep@loop {#2{#1}}}%
\def\qsx@sort@sep@appendtogreater #1#2#3{\qsx@sort@sep@loop {#2}{#3{#1}}}%
\def\qsx@sort@sep@appendtosmaller #1#2#3#4{\qsx@sort@sep@loop {#2}{#3}{#4{#1}}}%
%
\def\qsx@sort@sep@done\xintifCmp #1%
\qsx@sort@sep@appendtosmaller
\qsx@sort@sep@appendtoequal
\qsx@sort@sep@appendtogreater #2#3#4#5#6%
{%
\expandafter\qsx@sort@recurse\expandafter
{\romannumeral0\qsx@sort@a {#4}}{\qsx@sort@a {#5}}{#3}%
}%
%
\def\qsx@sort@recurse #1#2#3{#2#3#1}%
%
\makeatother
% EXAMPLES
\begingroup
\edef\z {\QSx {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4,
1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9}}
\meaning\z
\def\a {3.123456789123456789}\def\b {3.123456789123456788}
\def\c {3.123456789123456790}\def\d {3.123456789123456787}
\oodef\z {\QSx { \a, \b, \c, \d}}%
% The space before \a to let it not be expanded during the conversion from CSV
% values to List. The \oodef expands exactly twice (via a bunch of \expandafter's)
\meaning\z
\def\somenumbers{%
3997.6421, 8809.9358, 1805.4976, 5673.6478, 3179.1328, 1425.4503, 4417.7691,
2166.9040, 9279.7159, 3797.6992, 8057.1926, 2971.9166, 9372.2699, 9128.4052,
1228.0931, 3859.5459, 8561.7670, 2949.6929, 3512.1873, 1698.3952, 5282.9359,
1055.2154, 8760.8428, 7543.6015, 4934.4302, 7526.2729, 6246.0052, 9512.4667,
7423.1124, 5601.8436, 4433.5361, 9970.4849, 1519.3302, 7944.4953, 4910.7662,
3679.1515, 8167.6824, 2644.4325, 8239.4799, 4595.1908, 1560.2458, 6098.9677,
3116.3850, 9130.5298, 3236.2895, 3177.6830, 5373.1193, 5118.4922, 2743.8513,
8008.5975, 4189.2614, 1883.2764, 9090.9641, 2625.5400, 2899.3257, 9157.1094,
8048.4216, 3875.6233, 5684.3375, 8399.4277, 4528.5308, 6926.7729, 6941.6278,
9745.4137, 1875.1205, 2755.0443, 9161.1524, 9491.1593, 8857.3519, 4290.0451,
2382.4218, 3678.2963, 5647.0379, 1528.7301, 2627.8957, 9007.9860, 1988.5417,
2405.1911, 5065.8063, 5856.2141, 8989.8105, 9349.7840, 9970.3013, 8105.4062,
3041.7779, 5058.0480, 8165.0721, 9637.7196, 1795.0894, 7275.3838, 5997.0429,
7562.6481, 8084.0163, 3481.6319, 8078.8512, 2983.7624, 3925.4026, 4931.5812,
1323.1517, 6253.0945}%
\oodef\z {\QSx \somenumbers}%
\hsize 87\fontcharwd\font`0 \setbox0\hbox{\kern\fontcharwd\font`0}%
\lccode`~=32 \lowercase{\def~}{\discretionary{}{}{\copy0}}\catcode32 13
\noindent\ \ \ \scantokens\expandafter{\meaning\z}\par
\endgroup
\end{everbatim*}
\fi % fin de si pas xetex
All these examples were with numbers which may have been handled via |\ifdim|
tests rather than \csbxint{ifCmp} from \xintfracname ; naturally that would
have been faster. For a yet faster routine (based however on the Merge Sort
and using the |\pdfescapestring| PDF\TeX{} primitive) see |code 6| at
\url{http://tex.stackexchange.com/a/273084}.
We then turn to a graphical illustration of the algorithm.%
%
\footnote{I have rewritten the routine to do only once (and not thrice) the
needed calls to \csa{xintifCmp}, up to the price of one additional |\edef|,
although due to the context execution time on our side is not an issue and
moreover is anyhow overwhelmed by the TikZ's activities. Simultaneously I
have updated the code \url{http://tex.stackexchange.com/a/142634/4686}. The
variant with the choice of pivot on the right has more overhead: the reason
is simply that we do not convert the data into an array, but maintain a list
of tokens with self-reorganizing delimiters.}
%
For simplicity the pivot is always chosen as the first list item. Then we also
give a variant which picks up the last item as pivot.
\begin{everbatim*}
% in LaTeX preamble:
% \usepackage{xintfrac, xinttools}
% \usepackage{color}
% or, when using Plain TeX:
% \input xintfrac.sty \input xinttools.sty
% \input color.tex
%
% Color definitions
\definecolor{LEFT}{RGB}{216,195,88}
\definecolor{RIGHT}{RGB}{208,231,153}
\definecolor{INERT}{RGB}{199,200,194}
\definecolor{INERTpiv}{RGB}{237,237,237}
\definecolor{PIVOT}{RGB}{109,8,57}
% Start of macro defintions
\makeatletter
% \catcode`? 3 % a bit too paranoid. Normal ? will do.
%
% argument will never be empty
\def\QS@cmp@a #1{\QS@cmp@b #1??}%
\def\QS@cmp@b #1{\noexpand\QS@sep@A\@ne{#1}\QS@cmp@d {#1}}%
\def\QS@cmp@d #1#2{\ifx ?#2\expandafter\QS@cmp@done\fi
\xintifCmp {#1}{#2}\tw@\@ne\z@{#2}\QS@cmp@d {#1}}%
\def\QS@cmp@done #1?{?}%
%
\def\QS@sep@A #1?{\QSLr\QS@sep@L #1\thr@@?#1\thr@@?#1\thr@@?}%
\def\QS@sep@L #1#2{\ifcase #1{#2}\or\or\else\expandafter\QS@sep@I@start\fi \QS@sep@L}%
\def\QS@sep@I@start\QS@sep@L {\noexpand\empty?\QSIr\QS@sep@I}%
\def\QS@sep@I #1#2{\ifcase#1\or{#2}\or\else\expandafter\QS@sep@R@start\fi\QS@sep@I}%
\def\QS@sep@R@start\QS@sep@I {\noexpand\empty?\QSRr\QS@sep@R}%
\def\QS@sep@R #1#2{\ifcase#1\or\or{#2}\else\expandafter\QS@sep@done\fi\QS@sep@R}%
\def\QS@sep@done\QS@sep@R {\noexpand\empty?}%
%
\def\QS@loop {%
\xintloop
% pivot phase
\def\QS@pivotcount{0}%
\let\QSLr\DecoLEFTwithPivot \let\QSIr \DecoINERT
\let\QSRr\DecoRIGHTwithPivot \let\QSIrr\DecoINERT
\centerline{\QS@list}%
% sorting phase
\ifnum\QS@pivotcount>\z@
\def\QSLr {\QS@cmp@a}\def\QSRr {\QS@cmp@a}%
\def\QSIr {\QSIrr}\let\QSIrr\relax
\edef\QS@list{\QS@list}% compare
\let\QSLr\relax\let\QSRr\relax\let\QSIr\relax
\edef\QS@list{\QS@list}% separate
\def\QSLr ##1##2?{\ifx\empty##1\else\noexpand \QSLr {{##1}##2}\fi}%
\def\QSIr ##1##2?{\ifx\empty##1\else\noexpand \QSIr {{##1}##2}\fi}%
\def\QSRr ##1##2?{\ifx\empty##1\else\noexpand \QSRr {{##1}##2}\fi}%
\edef\QS@list{\QS@list}% gather
\let\QSLr\DecoLEFT \let\QSRr\DecoRIGHT
\let\QSIr\DecoINERTwithPivot \let\QSIrr\DecoINERT
\centerline{\QS@list}%
\repeat }%
%
% \xintFor* loops handle gracefully empty lists.
\def\DecoLEFT #1{\xintFor* ##1 in {#1} \do {\colorbox{LEFT}{##1}}}%
\def\DecoINERT #1{\xintFor* ##1 in {#1} \do {\colorbox{INERT}{##1}}}%
\def\DecoRIGHT #1{\xintFor* ##1 in {#1} \do {\colorbox{RIGHT}{##1}}}%
\def\DecoPivot #1{\begingroup\color{PIVOT}\advance\fboxsep-\fboxrule\fbox{#1}\endgroup}%
%
\def\DecoLEFTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}%
\xintFor* ##1 in {#1} \do
{\xintifForFirst {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}}%
\def\DecoINERTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}%
\xintFor* ##1 in {#1} \do
{\xintifForFirst {\colorbox{INERTpiv}{##1}}{\colorbox{INERT}{##1}}}}%
\def\DecoRIGHTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}%
\xintFor* ##1 in {#1} \do
{\xintifForFirst {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}}%
%
\def\QuickSort #1{% warning: not compatible with empty #1.
% initialize, doing conversion from comma separated values to a list of braced items
\edef\QS@list{\noexpand\QSRr{\xintCSVtoList{#1}}}% many \edef's are to follow anyhow
% earlier I did a first drawing of the list, here with the color of RIGHT elements,
% but the color should have been for example white, anyway I drop this first line
%\let\QSRr\DecoRIGHT
%\par\centerline{\QS@list}%
%
% loop as many times as needed
\QS@loop }%
%
% \catcode`? 12 % in case we had used a funny ? as delimiter.
\makeatother
%% End of macro definitions.
%% Start of Example
\begingroup\offinterlineskip
\small
% \QuickSort {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4,
% 1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9}
% \medskip
% with repeated values
\QuickSort {1.0, 0.5, 0.3, 0.8, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4,
1.3, 1.1, 0.7, 0.3, 1.6, 0.6, 0.3, 0.8, 0.2, 0.8, 0.7, 1.2}
\endgroup
\end{everbatim*}
Here is the variant which always picks the pivot as the rightmost element.
\begin{everbatim*}
\makeatletter
%
\def\QS@cmp@a #1{\noexpand\QS@sep@A\expandafter\QS@cmp@d\expandafter
{\romannumeral0\xintnthelt{-1}{#1}}#1??}%
%
\def\DecoLEFTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}%
\xintFor* ##1 in {#1} \do
{\xintifForLast {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}}
\def\DecoINERTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}%
\xintFor* ##1 in {#1} \do
{\xintifForLast {\colorbox{INERTpiv}{##1}}{\colorbox{INERT}{##1}}}}
\def\DecoRIGHTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}%
\xintFor* ##1 in {#1} \do
{\xintifForLast {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}}
\def\QuickSort #1{%
% initialize, doing conversion from comma separated values to a list of braced items
\edef\QS@list{\noexpand\QSLr {\xintCSVtoList{#1}}}% many \edef's are to follow anyhow
%
% loop as many times as needed
\QS@loop }%
\makeatother
\begingroup\offinterlineskip
\small
% \QuickSort {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4,
% 1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9}
% \medskip
% with repeated values
\QuickSort {1.0, 0.5, 0.3, 0.8, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4,
1.3, 1.1, 0.7, 0.3, 1.6, 0.6, 0.3, 0.8, 0.2, 0.8, 0.7, 1.2}
\endgroup
\end{everbatim*}
The choice of the first or last item as pivot is not a good one as nearly
ordered lists will take quadratic time. But for explaining the algorithm via a
graphical interpretation, it is not that bad. If one wanted to pick up the
pivot randomly, the routine would have to be substantially rewritten: in
particular the |\Deco..withPivot| macros need to know where the pivot is, and
currently this is implemented by using either |\xintifForFirst| or
|\xintifForLast|.
\clearpage
\section{Commands of the \xintcorename package}
\label{sec:core}
\localtableofcontents
Prior to release |1.1| the macros which are now included in the separate
package \xintcorename were part of \xintname. Package \xintcorename is
automatically loaded by \xintname.\IMPORTANT\
\xintcorename provides the five basic arithmetic operations on big integers:
addition, subtraction, multiplication, division and powers. Division may be
either rounded (\csbxint{iiDivRound}) (the rounding of |0.5| is |1| and the
one of |-0.5| is |-1|) or Euclidean (\csbxint{iiQuo}) (which for positive
operands is the same as truncated division), or truncated (\csbxint{iiDivTrunc}).
In the description of the macros the \texttt{\n} and \texttt{\m} symbols stand
for explicit (big) integers within braces or more generally any control
sequence (possibly within braces) \hyperref[ssec:expansions]{\fexpan ding} to
such a big integer.
The macros with a single |i| in their names parse their arguments
automatically through \hyperref[xintiNum]{\string\xintNum}. This type of
expansion applied to an argument is signaled by a
\textcolor[named]{PineGreen}{\Numf} in the margin. The accepted input format
is then a sequence of plus and minus signs, followed by some string of zeroes,
followed by digits.
If \xintfracname additionally to \xintcorename is loaded, \csbxint{Num}
becomes a synonym to \csbxint{TTrunc}; this means that
arbitrary fractions will be accepted as arguments of the
macros with a single |i| in their names, but get truncated to integers before
further processing. The format of the output will be as with only \xintname
loaded. The only extension is in allowing a wider variety of inputs.
The macros with |ii| in their names have arguments which will only be \fexpan
ded, but will not be parsed via \hyperref[xintiNum]{\string\xintNum}.
Arguments of this type are signaled by the margin annotation
\textcolor[named]{PineGreen}{\emph{f}}. For such big integers only one minus
sign and no plus sign, nor leading zeros, are accepted. |-0| is not valid in
this strict input format. Loading \xintfracname does not bring any
modification to these macros whether for input or output.
The letter \texttt{x} (with margin annotation
\textcolor[named]{PineGreen}{\numx}) stands for something which will be
inserted in-between a |\numexpr| and a |\relax|. It will thus be completely
expanded and must give an integer obeying the \TeX{} bounds. Thus, it may be
for example a count register, or itself a \csa{numexpr} expression, or just a
number written explicitely with digits or something like |4*\count 255 + 17|,
etc...
For the rules regarding direct use of count registers or \csa{numexpr}
expression, in the arguments to the package macros, see the
\hyperref[sec:useofcount]{Use of count} section.
\begin{framed}
Earlier releases of \xintcorename also provided macros |\xintAdd|,
|\xintMul|,\dots as synonyms to |\xintiAdd|, |\xintiMul|,\dots, destined to
be re-defined by \xintfracname.\IMPORTANT{} It was announced some time ago
that their usage was deprecated, because the output formats depended on
whether \xintfracname was loaded or not. They now have been \fbox{removed.}
\MyMarginNote[\kern\dimexpr\FrameSep+\FrameRule\relax]{Changed}
The macros \csbxint{iAdd}, \csbxint{iMul}, \dots, or \csbxint{iiAdd},
\csbxint{iiMul}, \dots which come with \xintcorename are guaranteed to
always output an integer without a trailing |/B[n]|. The latter have the
lesser overhead, and the former do not complain, if \xintfracname is loaded,
even if used with true fractions, as they will then truncate their arguments
to integers. But their output format remains unmodified: integers with no
fraction slash nor |[N]| thingy.
\end{framed}
The {\color[named]{PineGreen}$\star$}'s in the margin are there to remind of
the complete expandability, even \fexpan dability of the macros, as discussed
in \autoref{ssec:expansions}.
\subsection{\csbh{xintNum}, \csbh{xintiNum}}\label{xintiNum}
|\xintNum|\n\etype{f} removes chains of plus or minus signs, followed by
zeroes. %
%
\leftedline{|\xintNum{+---++----+--000000000367941789479}|\dtt
{=\xintNum{+---++----+--000000000367941789479}}}
All \xintname macros with a single |i| in their names, such as \csbxint{iAdd},
\csbxint{iMul} apply \csbxint{Num} to their arguments.
When \xintfracname is loaded, \csbxint{Num} becomes a synonym to
\csbxint{TTrunc}. And \csbxint{iNum} preserved the original integer only
meaning.
\subsection{\csbh{xintSgn}, \csbh{xintiiSgn}}\label{xintiiSgn}
|\xintiiSgn|\n\etype{f} returns 1 if the number is positive, 0 if it is zero
and -1 if it is negative. It skips the \csbxint{Num} overhead.
\csbxint{Sgn}\etype{\Numf} is the variant using \csbxint{Num} and getting
extended by \xintfracname to fractions.
\subsection{\csbh{xintiOpp}, \csbh{xintiiOpp}}\label{xintiOpp}\label{xintiiOpp}
|\xintiOpp|\n\etype{\Numf} return the opposite |-N| of the number |N|.
\csa{xintiiOpp} is the strict integer-only variant which skips
the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintiAbs}, \csbh{xintiiAbs}}\label{xintiAbs}\label{xintiiAbs}
|\xintiAbs|\n\etype{\Numf} returns the absolute value of the number.
\csa{xintiiAbs}
skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintiiFDg}}\label{xintFDg}\label{xintiiFDg}
|\xintiiFDg|\n\etype{f} returns the first digit (most significant) of the
decimal expansion. It skips the overhead of parsing via \csbxint{Num}. The
variant \csa{xintFDg}\etype{\Numf} uses |\xintNum| and gets extended by
\xintfracname.
\subsection{\csbh{xintiiLDg}}\label{xintLDg}\label{xintiiLDg}
|\xintiiLDg|\n\etype{f} returns the least significant digit. When the number
is positive, this is the same as the remainder in the euclidean division by
ten. It skips the overhead of parsing via \csbxint{Num}. The variant
\csa{xintLDg}\etype{\Numf} uses |\xintNum| and gets extended by \xintfracname.
\subsection{\csbh{xintDouble}, \csbh{xintHalf}}
\label{xintDouble}
\label{xintHalf}
|\xintDouble|\n\etype{f} returns |2N| and |\xintHalf|\n is |N/2| rounded
towards zero. These macros remain integer-only, even with \xintfracname loaded.
\subsection{\csbh{xintInc}, \csbh{xintDec}}
\label{xintInc}
\label{xintDec}
|\xintInc|\n\etype{f} is |N+1| and |\xintDec|\n{} is |N-1|. These macros
remain integer-only, even with \xintfracname loaded. They skip the overhead
of parsing via \csbxint{Num}.
\subsection{\csbh{xintiAdd}, \csbh{xintiiAdd}}\label{xintiAdd}\label{xintiiAdd}
|\xintiAdd|\n\m\etype{\Numf\Numf} returns the sum of the two numbers.
\csa{xintiiAdd} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintiSub}, \csbh{xintiiSub}}\label{xintiSub}\label{xintiiSub}
|\xintiSub|\n\m\etype{\Numf\Numf} returns the difference |N-M|.
\csa{xintiiSub} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintiMul}, \csbh{xintiiMul}}\label{xintiMul}\label{xintiiMul}
|\xintiMul|\n\m\etype{\Numf\Numf} returns the product of the two numbers.
\csa{xintiiMul} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintiSqr}, \csbh{xintiiSqr}}\label{xintiSqr}\label{xintiiSqr}
|\xintiSqr|\n\etype{\Numf} returns the square. \csa{xintiiSqr} skips the
\csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintiPow}, \csbh{xintiiPow}}\label{xintiPow}\label{xintiiPow}
|\xintiPow|\n\x\etype{\Numf\numx} returns |N^x|. When |x| is zero, this is 1.
If |N=0| and |x<0|, if \verb+|N|>1+ and |x<0|, an error is raised. There will
also be an error naturally if |x| exceeds the maximal \eTeX{} number
\dtt{\number"7FFFFFFF}, but the real limit for huge exponents comes from
either the computation time or the settings of some tex memory parameters.
\begin{framed}
Indeed, the maximal power of $2$ which \xintname is able to compute
explicitely is |2^(2^17)=2^131072| which has \dtt{39457} digits. This
exceeds the maximal size on input for the \xintcorename multiplication, hence
any |2^N| with a higher |N| will fail. On the other hand |2^(2^16)| has
\dtt{19729} digits, thus it can be squared once to obtain |2^(2^17)| or
multiplied by anything smaller, thus all exponents up to and including |2^17|
are allowed (because the power operation works by squaring things and making
products).
\end{framed}
Side remark: after all it does pay to think! I almost melted my CPU trying by
dichotomy to pin-point the exact maximal allowable |N| for |\xintiiPow 2{N}|
before finally making the reasoning above. Indeed, each such computation with
|N>130000| activates the fan of my laptop and results in so warm a keyboard
that I can hardly go on working on it! And it takes about 12 minutes for each
|\xintiiPow2{N}| with such |N|'s of the order of $130000$ (a.t.t.o.w.).
When \xintfracname is loaded the type of the second argument to \csa{xintiPow}
becomes \Numf: fractional input is accepted but will be truncated to an
integer; it still must be non-negative else the macro would produce fractions.
For the version accepting negative (but still integer) exponents see
\csbxint{Pow}.
\csa{xintiiPow} is the variant which skips the \csbxint{Num}
overhead\etype{f\numx} for the first argument.
\subsection{\csbh{xintiFac}, \csbh{xintiiFac}}
\label{xintiiFac}
|\xintiiFac|\x\etype{\numx} computes the factorial.
\begin{framed}
The (theoretically) allowable range is $0\leqslant x\leqslant10000$.
However the maximal possible computation depends on the values of some memory
parameters of the |tex| executable: with the current default settings of
TeXLive 2015, the maximal computable factorial (a.t.t.o.w. 2015/10/06) turns
out to be $5971!$ which has $19956$ digits.%\footnotemark
\end{framed}
|\xintiFac| is originally a synonym. With \xintfracname loaded it applies
|\xintNum| to its argument and thus accepts a fractional input but truncates
it to an integer.
The |factorial| function, or equivalently |!| as post-fix operator is
available in \csbxint{iiexpr}, \csbxint{expr}:
\begin{everbatim*}
\printnumber{\xinttheiiexpr 200!\relax}\par
\end{everbatim*}
See also \csbxint{FloatFac} from package \xintfracname for the float variant,
used in \csbxint{floatexpr}.
\subsection{\csbh{xintiDivision},
\csbh{xintiiDivision}}\label{xintiDivision}\label{xintiiDivision}
|\xintiiDivision|\n\m\etype{ff} returns |{quotient Q}{remainder R}|. This is
euclidean division: |N = QM + R|, |0|${}\leq{}$\verb+R < |M|+. So the
remainder is always non-negative and the formula |N = QM + R| always holds
independently of the signs of |N| or |M|. Division by zero is an error (even
if |N| vanishes) and returns |{0}{0}|. It skips the overhead of parsing via
\csbxint{Num}.
|\xintiDivision|\etype{\Numf\Numf} submits its arguments to \csbxint{Num} and
is extended by \xintfracname to accept fractions on input, which it truncates
first, and is not to be confused with the \xintfracname macro \csbxint{Div}
which divides one fraction by another.
\subsection{\csbh{xintiQuo}, \csbh{xintiiQuo}}\label{xintiQuo}\label{xintiiQuo}
|\xintiiQuo|\n\m\etype{ff} returns the quotient from the euclidean division.
It skips the overhead of parsing via \csbxint{Num}.
|\xintiQuo|\etype{\Numf\Numf} submits its arguments to \csbxint{Num} and
is extended by \xintfracname to accept fractions on input, which it truncates
first.
Note: |\xintQuo| is the former name of |\xintiQuo|. Its use is deprecated.
\subsection{\csbh{xintiRem}, \csbh{xintiiRem}}\label{xintiRem}\label{xintiiRem}
|\xintiiRem|\n\m\etype{ff} returns the remainder from the euclidean
division. It skips the overhead of parsing via \csbxint{Num}.
|\xintiRem|\etype{\Numf\Numf} submits its arguments to \csbxint{Num} and
is extended by \xintfracname to accept fractions on input, which it truncates
first.
Note: |\xintRem| is the former name of |\xintiRem|. Its use is deprecated.
\subsection{\csbh{xintiDivRound}, \csbh{xintiiDivRound}}
\label{xintiDivRound}\label{xintiiDivRound}
|\xintiiDivRound|\n\m\etype{ff} returns the rounded value of the algebraic
quotient $N/M$ of two big integers. The rounding of half integers is towards
the nearest integer of bigger absolute value. The macro skips the overhead of
parsing via \csbxint{Num}. The rounding is away from zero.
\begin{everbatim*}
\xintiiDivRound {100}{3}, \xintiiDivRound {101}{3}
\end{everbatim*}
|\xintiDivRound|\etype{\Numf\Numf} submits its arguments to \csbxint{Num}. It
is extended by \xintfracname to accept fractions on input, which it truncates
first before computing the rounded quotient.
\subsection{\csbh{xintiDivTrunc}, \csbh{xintiiDivTrunc}}
\label{xintiDivTrunc}\label{xintiiDivTrunc}
|\xintiiDivTrunc|\n\m\etype{ff} computes the truncation towards zero of the
algebraic quotient $N/M$. It skips the overhead of parsing the operands with
\csbxint{Num}. For $M>0$ it is the same as \csbxint{iiQuo}.
\begin{everbatim*}
$\xintiiQuo {1000}{-57}, \xintiiDivRound {1000}{-57}, \xintiiDivTrunc {1000}{-57}$
\end{everbatim*}
|\xintiDivTrunc|\etype{\Numf\Numf} submits first its arguments to \csbxint{Num}.
\subsection{\csbh{xintiMod}, \csbh{xintiiMod}}
\label{xintiMod}\label{xintiiMod}
|\xintiiMod|\n\m\etype{ff} computes $N - M*t(N/M)$, where $t(N/M)$ is the
algebraic quotient truncated towards zero . The macro skips the overhead of parsing
the operands with \csbxint{Num}. For $M>0$ it is the same as \csbxint{iiRem}.
\begin{everbatim*}
$\xintiiRem {1000}{-57}, \xintiiMod {1000}{-57},
\xintiiRem {-1000}{57}, \xintiiMod {-1000}{57}$
\end{everbatim*}
|\xintiMod|\etype{\Numf\Numf} submits first its arguments to \csbxint{Num}.
\clearpage
\section{Commands of the \xintname package}
\label{sec:xint}
\begin{framed}
This package loads automatically \xintcorename (and \xintkernelname) hence
all macros described in \autoref{sec:core} are still available. Notice
though that it does \emph{not} load package \xinttoolsname.
\end{framed}
\localtableofcontents
Version |1.0| was released |2013/03/28|. This is \texttt{\xintbndlversion} of
\texttt{\xintbndldate}. The core arithmetic macros have been
moved to separate package \xintcorename, which is
automatically loaded by \xintname.
See the documentation of \xintcorename or \autoref{ssec:expansions} for the
significance of the \textcolor[named]{PineGreen}{\Numf},
\textcolor[named]{PineGreen}{\emph{f}}, \textcolor[named]{PineGreen}{\numx}
and \textcolor[named]{PineGreen}{$\star$} margin annotations and some
important background information.
\subsection{\csbh{xintReverseDigits}} \label{xintReverseDigits}
|\xintReverseDigits|\n\etype{f} will reverse the order of the digits of the
number, preserving an optional upfront minus sign. \csa{xintRev} is the former
denomination and is kept as an alias to it. Leading zeroes resulting from the
operation are not removed. Contrarily to \csbxint{ReverseOrder} this macro can
only be used with digits and it first expands its argument (but beware that
|-\x| will give an unexpected result as the minus sign immediately stops this
expansion; one can use |\xintiiOpp{\x}| as argument.)
This command has been rewritten for |1.2| and is faster for very long inputs.
It is (almost) not used internally by the \xintcorename code, but the use
of related routines explains to some extent the higher speed of release |1.2|.
\begingroup
\begin{everbatim*}
\fdef\x{\xintReverseDigits
{-98765432109876543210987654321098765432109876543210}}\meaning\x\par
\noindent\fdef\x{\xintReverseDigits {\xintReverseDigits
{-98765432109876543210987654321098765432109876543210}}}\meaning\x\par
\end{everbatim*}
\endgroup
Notice that the output in this case with its leading zero is not in the strict
integer format expected by the `|ii|' arithmetic macros.
\subsection{\csbh{xintLen}}\label{xintiLen}
|\xintLen|\n\etype{\Numf} returns the length of the number, not counting the
sign. %
%
\leftedline{|\xintLen{-12345678901234567890123456789}|\dtt
{=\xintLen{-12345678901234567890123456789}}} Extended by \xintfracname to
fractions: the length of |A/B[n]| is the length of |A| plus the
length of |B| plus the absolute value of |n| and minus one (an integer input as
|N| is internally represented in a form equivalent to |N/1[0]| so the minus one
means that the extended \csa{xintLen} behaves the same as the original for
integers). %
%
\leftedline{|\xintLen{-1e3/5.425}|\dtt
{=\xintLen{-1e3/5.425}}} The length is computed on the |A/B[n]| which would
have been returned by \csbxint{Raw}: |\xintRaw {-1e3/5.425}|\dtt{=\xintRaw
{-1e3/5.425}}.
Let's point out that the whole thing should sum up to
less than circa $2^{31}$, but this is a bit theoretical.
|\xintLen| is only for numbers or fractions. See also \csbxint{NthElt} from
\xinttoolsname. See also \csbxint{Length} from \xintkernelname for counting
tokens (or rather braced groups), more generally.
\subsection{\csbh{xintCmp}, \csbh{xintiiCmp}}
|\xintCmp|\n\m\etype{\Numf\Numf} returns \dtt{1} if |N>M|, \dtt{0} if |N=M|,
and \dtt{-1} if |N<M|. Extended by \xintfracname to fractions (its output
naturally still being either |1|, |0|, or |-1|).
\csa{xintiiCmp} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintEq}, \csbh{xintiiEq}}\label{xintEq}
|\xintEq|\n\m\etype{\Numf\Numf} returns 1 if |N=M|, 0 otherwise. Extended
by \xintfracname to fractions.
\csa{xintiiEq} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintNeq}, \csbh{xintiiNeq}}
|\xintNeq|\n\m\etype{\Numf\Numf} returns 0 if |N=M|, 1 otherwise. Extended
by \xintfracname to fractions.
\csa{xintiiNeq} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintGt}, \csbh{xintiiGt}}\label{xintGt}
|\xintGt|\n\m\etype{\Numf\Numf} returns 1 if |N|$>$|M|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiGt} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintLt}, \csbh{xintiiLt}}\label{xintLt}
|\xintLt|\n\m\etype{\Numf\Numf} returns 1 if |N|$<$|M|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiLt} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintLtorEq}, \csbh{xintiiLtorEq}}
|\xintLtorEq|\n\m\etype{\Numf\Numf} returns 1 if |N|$\leqslant$|M|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiLtorEq} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintGtorEq}, \csbh{xintiiGtorEq}}
|\xintGtorEq|\n\m\etype{\Numf\Numf} returns 1 if |N|$\geqslant$|M|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiGtorEq} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintIsZero}, \csbh{xintiiIsZero}}\label{xintIsZero}
|\xintIsZero|\n\etype{\Numf} returns 1 if |N=0|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiIsZero} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintNot}}\label{xintNot}
\csa{xintNot}\etype{\Numf} is a synonym for \csa{xintIsZero}.
\subsection{\csbh{xintIsNotZero}, \csbh{xintiiIsNotZero}}\label{xintIsNotZero}
|\xintIsNotZero|\n\etype{\Numf} returns 1 if |N<>0|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiIsNotZero} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintIsOne},
\csbh{xintiiIsOne}}\label{xintIsOne}\label{xintiiIsOne}
|\xintIsOne|\n\etype{\Numf} returns 1 if |N=1|, 0 otherwise.
Extended by \xintfracname to fractions.
\csa{xintiiIsOne} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintAND}}\label{xintAND}
|\xintAND|\n\m\etype{\Numf\Numf} returns 1 if |N<>0| and |M<>0| and zero
otherwise. Extended by \xintfracname to fractions.
\subsection{\csbh{xintOR}}\label{xintOR}
|\xintOR|\n\m\etype{\Numf\Numf} returns 1 if |N<>0| or |M<>0| and zero
otherwise. Extended by \xintfracname to fractions.
\subsection{\csbh{xintXOR}}\label{xintXOR}
|\xintXOR|\n\m\etype{\Numf\Numf} returns 1 if exactly one of |N| or |M|
is true (i.e. non-zero). Extended by \xintfracname to fractions.
\subsection{\csbh{xintANDof}}\label{xintANDof}
\csa{xintANDof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast\Numf} returns 1 if all
are true (i.e. non zero) and zero otherwise. The list argument may be a macro,
it (or rather its first token) is \fexpan ded first (each item also is \fexpan
ded). Extended by \xintfracname to fractions.
\subsection{\csbh{xintORof}}\label{xintORof}
\csa{xintORof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast\Numf} returns 1 if at
least one is true (i.e. does not vanish). The list argument may be a macro, it
is \fexpan ded first. Extended by \xintfracname to fractions.
\subsection{\csbh{xintXORof}}\label{xintXORof}
\csa{xintXORof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast\Numf} returns 1 if an odd
number of them are true (i.e. does not vanish). The list argument may be a
macro, it is \fexpan ded first. Extended by \xintfracname to fractions.
\subsection{\csbh{xintGeq}}\label{xintiGeq}
|\xintGeq|\n\m\etype{\Numf\Numf} returns 1 if the \emph{absolute value}
of the first number is at least equal to the absolute value of the second
number. If \verb+|N|<|M|+ it returns 0. Extended by \xintfracname to fractions.
%(starting with release |1.07|)
Important: the macro compares \emph{absolute values}.
\subsection{\csbh{xintiMax}, \csbh{xintiiMax}}\label{xintiMax}\label{xintiiMax}
|\xintiMax|\n\m\etype{\Numf\Numf} returns the largest of the two in the sense
of the order structure on the relative integers (\emph{i.e.} the right-most
number if they are put on a line with positive numbers on the right):
|\xintiMax {-5}{-6}|\dtt{=\xintiMax{-5}{-6}}.
The |\xintiiMax| macro skips the overhead of parsing the operands with
\csbxint{Num}.\etype{ff}
\subsection{\csbh{xintiMin}, \csbh{xintiiMin}}\label{xintiMin}\label{xintiiMin}
|\xintiMin|\n\m\etype{\Numf\Numf} returns the smallest of the two in the
sense of the order structure on the relative integers (\emph{i.e.} the left-most
number if they are put on a line with positive numbers on the right): |\xintiMin
{-5}{-6}|\dtt{=\xintiMin{-5}{-6}}.
The |\xintiiMin| macro skips the overhead of parsing the operands with
\csbxint{Num}.\etype{ff}
\subsection{\csbh{xintiMaxof}, \csbh{xintiiMaxof}}\label{xintiMaxof}\label{xintiiMaxof}
\csa{xintiMaxof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast\Numf} returns the
maximum. The list argument may be a macro, it is \fexpan ded first. Each item
is submitted to |\xintNum| normalization.
\csa{xintiiMaxof} does the same, skips |\xintNum| normalization of
items.\NewWith {1.2a}
\subsection{\csbh{xintiMinof}, \csbh{xintiiMinof}}\label{xintiMinof}\label{xintiiMinof}
\csa{xintiMinof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast\Numf} returns the
minimum. The list argument may be a macro, it is \fexpan ded first. Each item
is submitted to |\xintNum| normalization.
\csa{xintiiMinof} does the same, skips |\xintNum| normalization of
items.\NewWith {1.2a}
\subsection{\csbh{xintiiSum}}\label{xintiiSum}
\csa{xintiiSum}\marg{braced things}\etype{{\lowast f}} after expanding its
argument expects to find a sequence of tokens (or braced material). Each is
\fexpan ded, and the sum of all these numbers is returned.
Note: the summands are \emph{not} parsed by \csbxint{Num}.
%
\leftedline{%
\csa{xintiiSum}|{{123}{-98763450}{\xintiiFac{7}}{\xintiMul{3347}{591}}}|%
\dtt{=\xintiiSum{{123}{-98763450}{\xintiiFac{7}}{\xintiMul{3347}{591}}}}}
%
\leftedline{\csa{xintiiSum}|{1234567890}|\dtt{=\xintiiSum{1234567890}}}
An empty sum is no error and returns zero: |\xintiiSum
{}|\dtt{=\xintiiSum {}}. A sum with only one term returns that
number: |\xintiiSum {{-1234}}|\dtt{=\xintiiSum {{-1234}}}.
Attention that |\xintiiSum {-1234}| is not legal input and will make the
\TeX{} run fail. On the other hand |\xintiiSum
{1234}|\dtt{=\xintiiSum{1234}}.
\subsection{\csbh{xintiiPrd}}\label{xintiiPrd}
\csa{xintiiPrd}\marg{braced things}\etype{{\lowast f}} after expanding its
argument expects to find a sequence of (of braced items or unbraced
single tokens). Each is
expanded (with the usual meaning), and the product of all these numbers is
returned. Note: the operands are \emph{not} parsed by \csbxint{Num}.
%
\leftedline{\csa{xintiiPrd}|{{-9876}{\xintiiFac{7}}{\xintiMul{3347}{591}}}|%
\dtt{=%
\xintiiPrd{{-9876}{\xintiiFac{7}}{\xintiMul{3347}{591}}}}}
%
\leftedline{\csa{xintiiPrd}|{123456789123456789}|\dtt{=%
\xintiiPrd{123456789123456789}}} An empty product is no error and returns 1:
|\xintiiPrd {}|\dtt{=\xintiiPrd {}}. A product reduced to a single term
returns this number: |\xintiiPrd {{-1234}}=|\dtt{\xintiiPrd {{-1234}}}.
Attention that |\xintiiPrd {-1234}| is not legal input and will make the \TeX{}
compilation fail. On the other hand |\xintiiPrd {1234}|\dtt{=\xintiiPrd
{1234}}. %
%
\begin{everbatim*}
$2^{200}3^{100}7^{100}=\printnumber
{\xintiiPrd {{\xintiPow {2}{200}}{\xintiPow {3}{100}}{\xintiPow {7}{100}}}}$
\end{everbatim*}
With \xintexprname, this would be easier:
%
\leftedline {|\xinttheiiexpr 2^200*3^100*7^100\relax |}
\subsection{\csbh{xintSgnFork}}\label{xintSgnFork}
\csa{xintSgnFork}\verb+{-1|0|1}+\marg{A}\marg{B}\marg{C}\etype{xnnn}
expandably chooses to execute either the \meta{A}, \meta{B} or \meta{C} code,
depending on its first argument. This first argument should be anything
expanding to either |-1|, |0| or |1| in a non self-delimiting way (i.e. a
count register must be prefixed by |\the| and a |\numexpr...\relax| also must
be prefixed by |\the|). This utility is provided to help construct expandable
macros choosing depending on a condition which one of the package macros to
use, or which values to confer to their arguments.
\subsection{\csbh{xintifSgn}, \csbh{xintiiifSgn}}\label{xintifSgn}
Similar to \csa{xintSgnFork}\etype{\Numf nnn} except that the first argument may
expand to a (big) integer (or a fraction if \xintfracname is loaded), and it is
its sign which decides which of the three branches is taken. Furthermore this
first argument may be a count register, with no |\the| or |\number| prefix.
\csa{xintiiifSgn} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintifZero}, \csbh{xintiiifZero}}\label{xintifZero}
\csa{xintifZero}\marg{N}\marg{IsZero}\marg{IsNotZero}\etype{\Numf nn} expandably
checks if the first mandatory argument |N| (a number, possibly a fraction if
\xintfracname is loaded, or a macro expanding to one such) is zero or not. It
then either executes the first or the second branch. Beware that both branches
must be present.
\csa{xintiiifZero} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintifNotZero}, \csbh{xintiiifNotZero}}\label{xintifNotZero}
\csa{xintifNotZero}\marg{N}\marg{IsNotZero}\marg{IsZero}\etype{\Numf nn}
expandably checks if the first mandatory argument |N| (a number, possibly a
fraction if \xintfracname is loaded, or a macro expanding to one such) is not
zero or is zero. It then either executes the first or the second branch. Beware
that both branches must be present.
\csa{xintiiifNotZero} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintifOne}, \csbh{xintiiifOne}}\label{xintifOne}
\csa{xintifOne}\marg{N}\marg{IsOne}\marg{IsNotOne}\etype{\Numf nn} expandably
checks if the first mandatory argument |N| (a number, possibly a fraction if
\xintfracname is loaded, or a macro expanding to one such) is one or not. It
then either executes the first or the second branch. Beware that both branches
must be present.
\csa{xintiiifOne} skips the \csbxint{Num} overhead.\etype{f}
\subsection{\csbh{xintifTrueAelseB}, \csbh{xintifFalseAelseB}}
\label{xintifTrueAelseB}
\label{xintifFalseAelseB}
\csa{xintifTrueAelseB}\marg{N}\marg{true branch}\marg{false branch}\etype{\Numf
nn} is a synonym for \csbxint{ifNotZero}.
{\small
\noindent 1. with |1.09i|, the synonyms |\xintifTrueFalse| and |\xintifTrue| are
deprecated
and will be removed in next release.\par
\noindent 2. These macros have no lowercase versions, use |\xintifzero|,
|\xintifnotzero|.\par }
\csa{xintifFalseAelseB}\marg{N}\marg{false branch}\marg{true branch}\etype{\Numf
nn} is a synonym for \csbxint{ifZero}.
\subsection{\csbh{xintifCmp}, \csbh{xintiiifCmp}}\label{xintifCmp}
\csa{xintifCmp}\marg{A}\marg{B}\marg{if A<B}\marg{if A=B}\marg{if
A>B}\etype{\Numf\Numf nnn} compares
its arguments and chooses accordingly the correct branch.
\csa{xintiiifCmp} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintifEq}, \csbh{xintiiifEq}}\label{xintifEq}
\csa{xintifEq}\marg{A}\marg{B}\marg{YES}\marg{NO}\etype{\Numf\Numf nn}
checks equality of its two first arguments (numbers, or fractions if
\xintfracname is loaded) and does the |YES| or the |NO| branch.
\csa{xintiiifEq} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintifGt}, \csbh{xintiiifGt}}\label{xintifGt}
\csa{xintifGt}\marg{A}\marg{B}\marg{YES}\marg{NO}\etype{\Numf\Numf nn} checks if
$A>B$ and in that case executes the |YES| branch. Extended to fractions (in
particular decimal numbers) by \xintfracname.
\csa{xintiiifGt} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintifLt}, \csbh{xintiiifLt}}\label{xintifLt}
\csa{xintifLt}\marg{A}\marg{B}\marg{YES}\marg{NO}\etype{\Numf\Numf nn}
checks if $A<B$ and in that case executes the |YES| branch. Extended to
fractions (in particular decimal numbers) by \xintfracname.
\csa{xintiiifLt} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintifOdd}, \csbh{xintiiifOdd}}\label{xintifOdd}
\csa{xintifOdd}\marg{A}\marg{YES}\marg{NO}\etype{\Numf nn} checks if $A$ is and
odd integer and in that case executes the |YES| branch.
\csa{xintiiifOdd} skips the \csbxint{Num} overhead.\etype{f}
\begin{framed}
The macros described next are all integer-only on input. Those with |ii| in
their names skip the \csbxint{Num} parsing. The others, with \xintfracname
loaded, can have fractions as arguments, which will get truncated to
integers via \csbxint{TTrunc}. On output, the macros here always produce
integers (with no |/B[N]|).
\end{framed}
\subsection{\csbh{xintiiMON}, \csbh{xintiiMMON}}
\label{xintMON}\label{xintMMON}\label{xintiiMON}\label{xintiiMMON}
|\xintiiMON|\n\etype{f} returns |(-1)^N| and |\xintiiMMON|\n{} returns
|(-1)^{N-1}|. They skip the overhead of parsing via \csbxint{Num}.
%
\leftedline{|\xintiiMON {-280914019374101929}|\dtt{=\xintiiMON
{280914019374101929}}, |\xintiiMMON
{-280914019374101929}|\dtt{=\xintiiMMON {280914019374101929}}}
The variants
\csa{xintMON}\etype{\Numf} and \csa{xintMMON} use |\xintNum| and get extended
to fractions by \xintfracname.
\subsection{\csbh{xintiiOdd}}\label{xintOdd}\label{xintiiOdd}
|\xintiiOdd|\n\etype{f} is 1 if the number is odd and 0 otherwise. It skips
the overhead of parsing via \csbxint{Num}. \csa{xintOdd}\etype{\Numf} is the
variant using |\xintNum| and extended to fractions by \xintfracname.
\subsection{\csbh{xintiiEven}}\label{xintEven}\label{xintiiEven}
|\xintiiEven|\n\etype{f} is 1 if the number is even and 0 otherwise. It skips
the overhead of parsing via \csbxint{Num}. \csa{xintEven}\etype{\Numf} is the
variant using |\xintNum| and extended to fractions by \xintfracname.
\subsection{\csbh{xintiSqrt}, \csbh{xintiiSqrt}, \csbh{xintiiSqrtR}, \csbh{xintiSquareRoot},
\csbh{xintiiSquareRoot}}\label{xintiSqrt}\label{xintiiSqrt}\label{xintiiSqrtR}
\label{xintiSquareRoot}\label{xintiiSquareRoot}
\noindent|\xintiSqrt|\n\etype{\Numf} returns the largest integer whose square
is at most equal to |N|. |\xintiiSqrt| is the variant skipping the |\xintNum|
overhead.\etype{f} |\xintiiSqrtR| also skips the |\xintNum| overhead and it
returns the rounded, not truncated, square root.\etype{f}
\begin{everbatim*}
\begin{itemize}[nosep]
\item \xintiiSqrt {3000000000000000000000000000000000000}
\item \xintiiSqrtR {3000000000000000000000000000000000000}
\item \xintiiSqrt {\xintiiE {3}{100}}
\end{itemize}
\end{everbatim*}
|\xintiSquareRoot|\n\etype{\Numf} returns |{M}{d}| with |d>0|, |M^2-d=N| and
|M| smallest (hence |=1+\xintiSqrt{N}|).
|\xintiiSquareRoot|\etype{f} is the variant skipping the |\xintNum| overhead.
\begin{everbatim*}
\xintAssign\xintiiSquareRoot {17000000000000000000000000}\to\A\B
\xintiiSub{\xintiiSqr\A}\B=\A\string^2-\B
\end{everbatim*}
A rational approximation to $\sqrt{|N|}$ is $|M|-\frac{|d|}{|2M|}$ (this is a
majorant and the error is at most |1/2M|; if |N| is a perfect square |k^2|
then |M=k+1| and this gives |k+1/(2k+2)|, not |k|).
Package \xintfracname has \csbxint{FloatSqrt} for square
roots of floating point numbers.
\subsection{\csbh{xintiFac}, \csbh{xintiiFac}}
Defined in \xintcorename, see \autoref{xintiiFac} for more info.
\subsection{\csbh{xintiBinomial}, \csbh{xintiiBinomial}}
\label{xintiiBinomial}
|\xintiiBinomial{x}{y}|\etype{\numx\numx} computes binomial coefficients.
|\xintiBinomial| is originally a synonym.\NewWith{1.2f}
With \xintfracname loaded it applies
|\xintNum| to its arguments and thus accepts fractional inputs but truncates
them to an integer.
When |x<0| an out-of-range error is raised. Else, if |y<0| or if |x<y| the macro
evaluates to \dtt{\xintiiBinomial{1}{-1}}.\CHANGED{1.2h}
\begin{framed}
The (theoretically) allowable range is $0\leqslant y \leqslant x\leqslant99999999$.
\end{framed}
% Thus the maximal computable value is ${9999 \choose 5000}$ which turns out
% to have \dtt{3008} digits.
This theoretical range includes binomial coefficients with more than the
roughly 19950 digits that the arithmetics of \xintname can handle. In such
cases, the computation will end up in a low-level \TeX{} error after a
long time.
%
It turns out that ${65000 \choose 32500}$ has \dtt{19565} digits and
${64000 \choose 32000}$ has \dtt{19264} digits. The latter can be evaluated
(this takes a long long time) but presumably not the former (I didn't try).
Reasonable feasible evaluations are with binomial coefficients not exceeding
about one thousand digits.
%
The |binomial| function is available in the \xintexprname parsers.
\begin{everbatim*}
\xinttheiiexpr seq(binomial(100,i), i=47..53)\relax
\end{everbatim*}
See \csbxint{FloatBinomial} from package \xintfracname for the float variant,
used in \csbxint{floatexpr}.
In order to
evaluate binomial coefficients ${x \choose y}$ with $x>99999999$, or even
$x\geqslant 2^{31}$, but $y$ is not too large, one may use an ad hoc function
definition such as:
\begin{everbatim*}
\xintdeffunc mybigbinomial(x,y):=`*`(x-y+1..[1]..x)//y!;%
% without [1], x would have been limited to < 2^31
\printnumber{\xinttheexpr mybigbinomial(98765432109876543210,10)\relax}
\end{everbatim*}
To get this functionality in macro form, one can do:
\begin{everbatim*}
\xintNewIIExpr\MyBigBinomial [2]{`*`(#1-#2+1..[1]..#1)//#2!}
\printnumber{\MyBigBinomial {98765432109876543210}{10}}
\end{everbatim*}
As we used \csa{xintNewIIExpr}, this macro will only accept strict integers.
Had we used \csa{xintNewExpr} the |\MyBigBinomial| would have accepted general
fractions or decimal numbers, and computed the product at the numerator
without truncating them to integers; but the factorial at the denominator
would truncate its argument.
\subsection{\csbh{xintiPFactorial}, \csbh{xintiiPFactorial}}
\label{xintiiPFactorial}
|\xintiiPFactorial{a}{b}|\etype{\numx\numx} computes the partial factorial
|(a+1)(a+2)...b|.
|\xintiPFactorial| is originally a synonym.\NewWith{1.2f}
With \xintfracname loaded it applies
|\xintNum| to its arguments and thus accepts fractional inputs but truncates
them to an integer.
\begin{framed}
The (theoretically) allowable range is $0\leqslant a \leqslant
b\leqslant99999999$. If |a=b| the value is |1|.
\begin{everbatim*}
\xintiiPFactorial {100}{130}
\end{everbatim*}
\end{framed}
It was a bit unfortunate with
|1.2f| that the code deliberately raised an error if the condition
|0<=a<=b<10^8| was violated. The rule now\CHANGED{1.2h} with |1.2h|is to
interpret it as the product of the |j| for |a<j<=b|, hence if |a>=b|, it
returns |1| because of an empty product. But only for the range |0<= a <= b <
10^8| is it to be considered that the behaviour is fixed and will not change
in the future.
This theoretical range includes values with more than the
roughly 19950 digits that the arithmetics of \xintname can handle. In such
cases, the computation will end up in a low-level \TeX{} error after a
long time.
%
The |pfactorial| function is available in the \xintexprname parsers.
\begin{everbatim*}
\xinttheiiexpr pfactorial(100,130)\relax
\end{everbatim*}
See \csbxint{FloatPFactorial} from package \xintfracname for the float
variant, used in \csbxint{floatexpr}.
In case values are needed with $b>99999999$, or even $b\geqslant 2^{31}$, but
$b-a$ is not too large, one may use an ad hoc function definition such as:
\begin{everbatim*}
\xintdeffunc mybigpfac(a,b):=`*`(a+1..[1]..b);%
% without [1], b would have been limited to < 2^31
\printnumber{\xinttheexpr mybigpfac(98765432100,98765432120)\relax}
\end{everbatim*}
\begin{framed}
The macros described next are strictly for integer-only arguments. These
arguments are \emph{not} filtered via \csbxint{Num}. The macros are not
usable with fractions, even with \xintfracname loaded.
\end{framed}
\subsection{\csbh{xintDSL}}\label{xintDSL}
|\xintDSL|\n\etype{f} is decimal shift left, \emph{i.e.} multiplication by
ten.
\subsection{\csbh{xintDSR}}\label{xintDSR}
|\xintDSR|\n\etype{f} is decimal shift right, \emph{i.e.} it removes the last
digit (keeping the sign), equivalently it is the closest integer to |N/10| when
starting at zero.
\subsection{\csbh{xintDSH}}\label{xintDSH}
|\xintDSH|\x\n\etype{\numx f} is parametrized decimal shift. When |x| is
negative, it is like iterating \csa{xintDSL} \verb+|x|+ times (\emph{i.e.}
multiplication by $10^{-x}$). When |x| positive, it is like iterating
\csa{DSR} |x| times (and is more efficient), and for a non-negative |N| this is
thus the same as the quotient from the euclidean division by |10^x|.
\subsection{\csbh{xintDSHr}, \csbh{xintDSx}}\label{xintDSHr}\label{xintDSx}
|\xintDSHr|\x\n\etype{\numx f} expects |x| to be zero or positive and it
returns then a value |R| which is correlated to the value |Q| returned by
|\xintDSH|\x\n{} in the following manner:
\begin{itemize}
\item if |N| is
positive or zero, |Q| and |R| are the quotient and remainder in
the euclidean division by |10^x| (obtained in a more efficient
manner than using \csa{xintiDivision}),
\item if |N| is negative let
|Q1| and |R1| be the quotient and remainder in the euclidean
division by |10^x| of the absolute value of |N|. If |Q1|
does not vanish, then |Q=-Q1| and |R=R1|. If |Q1| vanishes, then
|Q=0| and |R=-R1|.
\item for |x=0|, |Q=N| and |R=0|.
\end{itemize}
So one has |N = 10^x Q + R| if |Q| turns out to be zero or
positive, and |N = 10^x Q - R| if |Q| turns out to be negative,
which is exactly the case when |N| is at most |-10^x|.
|\xintDSx|\x\n\etype{\numx f} for |x| negative is exactly as
|\xintDSH|\x\n, \emph{i.e.} multiplication by $10^{-|x|}$. For |x| zero or
positive it returns the two numbers |{Q}{R}| described above, each one within
braces. So |Q| is |\xintDSH|\x\n, and |R| is |\xintDSHr|\x\n, but computed
simultaneously.
\xintAssign\xintDSx {-1}{-123456789}\to\M
\leftedline{|\xintAssign\xintDSx {-1}{-123456789}\to\M|}
\leftedline{|\meaning\M: |\dtt{\meaning\M}.}
\xintAssign\xintDSx {-20}{1234567689}\to\M
\leftedline{|\xintAssign\xintDSx {-20}{123456789}\to\M|}
\leftedline{|\meaning\M: |\dtt{\meaning\M}.}
\xintAssign\xintDSx{0}{-123004321}\to\Q\R
\leftedline{|\xintAssign\xintDSx {0}{-123004321}\to\Q\R|}
\leftedline{|\meaning\Q: |\dtt{\meaning\Q}, |\meaning\R:|\dtt{\meaning\R.}}
\leftedline{|\xintDSH {0}{-123004321}|\dtt{=\xintDSH {0}{-123004321}},
|\xintDSHr {0}{-123004321}|\dtt{=\xintDSHr {0}{-123004321}}}
\xintAssign\xintDSx {6}{-123004321}\to\Q\R
\leftedline{|\xintAssign\xintDSx {6}{-123004321}\to\Q\R|}
\leftedline{|\meaning\Q: |\dtt{\meaning\Q},|\meaning\R: |\dtt{\meaning\R.}}
\leftedline{|\xintDSH {6}{-123004321}|\dtt{=\xintDSH {6}{-123004321}},
|\xintDSHr {6}{-123004321}|\dtt{=\xintDSHr {6}{-123004321}}}
\xintAssign\xintDSx {8}{-123004321}\to\Q\R
\leftedline{|\xintAssign\xintDSx {8}{-123004321}\to\Q\R|}
\leftedline{|\meaning\Q: |\dtt{\meaning\Q},|\meaning\R: |\dtt{\meaning\R.}}
\leftedline{|\xintDSH {8}{-123004321}|\dtt{=\xintDSH {8}{-123004321}},
|\xintDSHr {8}{-123004321}|\dtt{=\xintDSHr {8}{-123004321}}}
\xintAssign\xintDSx {9}{-123004321}\to\Q\R
\leftedline{|\xintAssign\xintDSx {9}{-123004321}\to\Q\R|}
\leftedline{|\meaning\Q: |\dtt{\meaning\Q},|\meaning\R: |\dtt{\meaning\R.}}
\leftedline{|\xintDSH {9}{-123004321}|\dtt{=\xintDSH {9}{-123004321}},
|\xintDSHr {9}{-123004321}|\dtt{=\xintDSHr {9}{-123004321}}}
\subsection{\csbh{xintDecSplit}}\label{xintDecSplit}
|\xintDecSplit|\x\n\etype{\numx f} cuts the number into two pieces (each one
within a pair of enclosing braces). First the sign if present is \emph{removed}.
Then, for |x| positive or null, the second piece contains the |x| least
significant digits (\emph{empty} if |x=0|) and the first piece the remaining
digits (\emph{empty} when |x| equals or exceeds the length of |N|). Leading
zeroes in the second piece are not removed. When |x| is negative the first piece
contains the \verb+|x|+ most significant digits and the second piece the
remaining digits (\emph{empty} if $|x|$ equals or exceeds the length of |N|).
Leading zeroes in this second piece are not removed. So the absolute value of the
original number is always the concatenation of the first and second piece.
{\footnotesize This macro's behavior for |N| non-negative is final and will not
change. I am still hesitant about what to do with the sign of a
negative |N|.\par}
\xintAssign\xintDecSplit {0}{-123004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {0}{-123004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\xintAssign\xintDecSplit {5}{-123004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {5}{-123004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\xintAssign\xintDecSplit {9}{-123004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {9}{-123004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\xintAssign\xintDecSplit {10}{-123004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {10}{-123004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\xintAssign\xintDecSplit {-5}{-12300004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {-5}{-12300004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\xintAssign\xintDecSplit {-11}{-12300004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {-11}{-12300004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\xintAssign\xintDecSplit {-15}{-12300004321}\to\L\R
\leftedline{|\xintAssign\xintDecSplit {-15}{-12300004321}\to\L\R|}
\leftedline{|\meaning\L: |\dtt{\meaning\L}, |\meaning\R: |\dtt{\meaning\R.}}
\subsection{\csbh{xintDecSplitL}}\label{xintDecSplitL}
|\xintDecSplitL|\x\n\etype{\numx f} returns the first piece after the action
of \csa{xintDecSplit}.
\subsection{\csbh{xintDecSplitR}}\label{xintDecSplitR}
|\xintDecSplitR|\x\n\etype{\numx f} returns the second piece after the action
of \csa{xintDecSplit}.
\subsection{\csbh{xintiiE}}\label{xintiiE}
|\xintiiE|\n\x\etype{f\numx } serves to add zeros to the right of |N|.
\begin{everbatim*}
\xintiiE {123}{89}
\end{everbatim*}
%\pagebreak
\clearpage
\section{Commands of the \xintfracname package}
\label{sec:frac}
\begin{framed}
This package loads automatically \xintname and \xintcorename, hence all
macros described in \autoref{sec:xint} and \autoref{sec:core} are
available; but some among them will only accept integers on input, not
fractions or numbers in scientific notation. This is the case
particularly for all those having |ii| in their names.
\end{framed}
\localtableofcontents
\def\x{|{x}|}
This package was first included in release |1.03| (|2013/04/14|) of the
\xintname bundle. The general rule of the bundle that each macro first expands
(what comes first, fully) each one of its arguments applies.
|f|\ntype{\Ff} stands for an integer or a fraction (see \autoref{sec:inputs}
for the accepted input formats) or something which expands to an integer or
fraction. It is possible to use in the numerator or the denominator of |f| count
registers and even expressions with infix arithmetic operators, under some rules
which are explained in the previous \hyperref[sec:useofcount]{Use of count
registers} section.
As in the \hyperref[sec:xint]{xint.sty} documentation, |x|\ntype{\numx}
stands for something which will internally be embedded in a \csa{numexpr}.
It
may thus be a count register or something like |4*\count 255 + 17|, etc..., but
must expand to an integer obeying the \TeX{} bound.
The fraction format on output is the scientific notation for the `float' macros,
and the |A/B[n]| format for all other fraction macros, with the exception of
\csbxint{Trunc}, {\color{blue}\string\xint\-Round} (which produce decimal
numbers) and \csbxint{Irr}, \csbxint{Jrr}, \csbxint{RawWithZeros} (which returns
an |A/B| with no trailing |[n]|, and prints the |B| even if it is |1|), and
\csbxint{PRaw} which does not print the |[n]| if |n=0| or the |B| if |B=1|.
To be certain to print an integer output without trailing |[n]| nor fraction
slash, one should use either |\xintPRaw {\xintIrr {f}}| or |\xintNum {f}| when
it is already known that |f| evaluates to a (big) integer. For example
|\xintPRaw {\xintAdd {2/5}{3/5}}| gives a perhaps disappointing
\dtt{\xintPRaw {\xintAdd {2/5}{3/5}}}
%
%
%
whereas |\xintPRaw {\xintIrr {\xintAdd
{2/5}{3/5}}}| returns \dtt{\xintPRaw {\xintIrr {\xintAdd
{2/5}{3/5}}}}. As we knew the result was an integer we could have used
|\xintNum {\xintAdd {2/5}{3/5}}=|\xintNum {\xintAdd {2/5}{3/5}}.
Some macros (such as \csbxint{iTrunc}, \csbxint{iRound}, and \csbxint{iFac})
always produce integers on output.
The macro \csbxint{XTrunc} uses \csbxint{iloop} from package \xinttoolsname,
hence there is a partial dependency of \xintfracname on
\xinttoolsname,\IMPORTANT{} and the latter must be required explicitely by the
user intending to use \csbxint{XTrunc}.
Refer to \autoref{ssec:floatingpoint} for general background information on
how floating point numbers and evaluations are implemented.
\subsection{\csbh{xintNum}}\label{xintNum}
The macro\etype{f} from \xintname is made a synonym to \csbxint{TTrunc}.%
%(\textcolor[named]{PineGreen}{Changed!})
\footnote{In earlier releases than
|1.1|, \csbxint{Num} did \csbxint{Irr} and then complained if the
denominator was not |1|, else, it silently removed the denominator.}
The original (which
normalizes big integers to strict format) is still available as
\csbxint{iNum}.
It is imprudent to apply \csa{xintNum} to numbers with a large
power of ten given either in scientific notation or with the |[n]| notation,
as the macro will according to its definition add all the needed zeroes to
produce an explicit integer in strict format.
\subsection{\csbh{xintifInt}}\label{xintifInt}
\csa{xintifInt}|{f}{YES branch}{NO branch}|\etype{\Ff nn} expandably chooses
the |YES| branch if |f| reveals itself after expansion and simplification to
be an integer. As with the other \xintname conditionals, both branches must be
present although one of the two (or both, but why then?) may well be an empty
brace pair |{}|. Spaces in-between the braced things do not matter, but a
space after the closing brace of the |NO| branch is significant.
\subsection{\csbh{xintLen}}\label{xintLen}
The original macro\etype{\Ff} is extended to accept a fraction on input.
%
\leftedline {|\xintLen {201710/298219}|\dtt{=\xintLen {201710/298219}},
|\xintLen {1234/1}|\dtt{=\xintLen {1234/1}}, |\xintLen {1234}|%
\dtt{=\xintLen {1234}}}
\subsection{\csbh{xintRaw}}\label{xintRaw}
This macro `prints' the\etype{\Ff}
fraction |f| as it is received by the package after its parsing and
expansion, in a form |A/B[n]| equivalent to the internal
representation: the denominator |B| is always strictly positive and is
printed even if it has value |1|.
%
\leftedline{|\xintRaw{\the\numexpr 571*987\relax.123e-10/\the\numexpr
-201+59\relax e-7}=|}
%
\leftedline{\dtt{\xintRaw{\the\numexpr
571*987\relax.123e-10/\the\numexpr -201+59\relax e-7}}}
\subsection{\csbh{xintPRaw}}\label{xintPRaw}
|PRaw|\etype{\Ff} stands for ``pretty raw''. It does \emph{not} show the |[n]|
if |n=0| and does \emph{not} show the |B| if |B=1|.
% %
%
\leftedline{|\xintPRaw {123e10/321e10}=|\dtt{\xintPRaw {123e10/321e10}}, %
|\xintPRaw {123e9/321e10}=|\dtt{\xintPRaw {123e9/321e10}}}
% %
%
\leftedline{|\xintPRaw {\xintIrr{861/123}}=|\dtt{\xintPRaw{\xintIrr{861/123}}}\ vz.\
|\xintIrr{861/123}=|\dtt{\xintIrr{861/123}}}
% %
See also \csbxint{Frac} (or \csbxint{FwOver}) for math mode. As is examplified
above the \csbxint{Irr} macro which puts the fraction into irreducible form
does not remove the |/1| if the fraction is an integer. One can use
|\xintNum{f}| or |\xintPRaw{\xintIrr{f}}| which produces the same output only
if |f| is an integer (after simplication).
\subsection{\csbh{xintNumerator}}\label{xintNumerator}
This returns\etype{\Ff} the numerator corresponding to the internal
representation of a fraction, with positive powers of ten converted into zeroes
of this numerator: %
%
\leftedline{|\xintNumerator
{178000/25600000[17]}|\dtt{=\xintNumerator {178000/25600000[17]}}}
%
\leftedline{|\xintNumerator {312.289001/20198.27}|%
\dtt{=\xintNumerator {312.289001/20198.27}}}
%
\leftedline{|\xintNumerator {178000e-3/256e5}|\dtt{=\xintNumerator
{178000e-3/256e5}}} %
%
\leftedline{|\xintNumerator
{178.000/25600000}|\dtt{=\xintNumerator {178.000/25600000}}} As shown by
the examples, no simplification of the input is done. For a result uniquely
associated to the value of the fraction first apply \csa{xintIrr}.
\subsection{\csbh{xintDenominator}}\label{xintDenominator}
This returns\etype{\Ff} the denominator corresponding to the internal
representation of the fraction:%
%
\footnote{recall that the |[]| construct excludes
presence of a decimal point.}
%
\leftedline{|\xintDenominator
{178000/25600000[17]}|\dtt{=\xintDenominator {178000/25600000[17]}}}
%
\leftedline{|\xintDenominator {312.289001/20198.27}|%
\dtt{=\xintDenominator {312.289001/20198.27}}}
%
\leftedline{|\xintDenominator {178000e-3/256e5}|\dtt{=\xintDenominator
{178000e-3/256e5}}} %
%
\leftedline{|\xintDenominator
{178.000/25600000}|\dtt{=\xintDenominator {178.000/25600000}}} As shown
by the examples, no simplification of the input is done. The denominator looks
wrong in the last example, but the numerator was tacitly multiplied by $1000$
through the removal of the decimal point. For a result uniquely associated to
the value of the fraction first apply \csa{xintIrr}.
\subsection{\csbh{xintRawWithZeros}}\label{xintRawWithZeros}
This macro `prints'\etype{\Ff} the
fraction |f| (after its parsing and expansion) in |A/B| form, with |A|
as returned by \csa{xintNumerator}|{f}| and |B| as returned by
\csa{xintDenominator}|{f}|.
%
\leftedline{|\xintRawWithZeros{\the\numexpr 571*987\relax.123e-10/\the\numexpr
-201+59\relax e-7}=|}
%
\leftedline{\dtt{\xintRawWithZeros{\the\numexpr
571*987\relax.123e-10/\the\numexpr -201+59\relax e-7}}}
\subsection{\csbh{xintREZ}}\label{xintREZ}
This command\etype{\Ff} normalizes a fraction by removing the powers of ten from
its numerator and denominator: %
%
\leftedline{|\xintREZ
{178000/25600000[17]}|\dtt{=\xintREZ {178000/25600000[17]}}}
%
\leftedline{|\xintREZ {1780000000000e30/2560000000000e15}|\dtt{=\xintREZ
{1780000000000e30/2560000000000e15}}} As shown by the example, it does not
otherwise simplify the fraction.
\subsection{\csbh{xintFrac}}\label{xintFrac}
This is a \LaTeX{} only command,\etype{\Ff} to be used in math mode only. It
will print a fraction, internally represented as something equivalent to
|A/B[n]| as |\frac {A}{B}10^n|. The power of ten is omitted when |n=0|, the
denominator is omitted when it has value one, the number being separated from
the power of ten by a |\cdot|. |$\xintFrac {178.000/25600000}$| gives $\xintFrac
{178.000/25600000}$, |$\xintFrac {178.000/1}$| gives $\xintFrac {178.000/1}$,
|$\xintFrac {3.5/5.7}$| gives $\xintFrac {3.5/5.7}$, and |$\xintFrac {\xintNum
{\xintiiFac{10}/|\allowbreak|\xintiSqr{\xintiiFac {5}}}}$| gives $\xintFrac
{\xintNum {\xintiiFac{10}/\xintiSqr{\xintiiFac {5}}}}$. As shown by the examples,
simplification of the input (apart from removing the decimal points and moving
the minus sign to the numerator) is not done automatically and must be the
result of macros such as |\xintIrr|, |\xintREZ|, or |\xintNum| (for fractions
being in fact integers.)
\subsection{\csbh{xintSignedFrac}}\label{xintSignedFrac}
This is as \csbxint{Frac}\etype{\Ff} except that a negative fraction has the
sign put in front, not in the numerator. %
%
\leftedline{|\[\xintFrac
{-355/113}=\xintSignedFrac {-355/113}\]|}
\[\xintFrac {-355/113}=\xintSignedFrac {-355/113}\]
\subsection{\csbh{xintFwOver}}\label{xintFwOver}
This does the same as \csa{xintFrac}\etype{\Ff} except that the \csa{over}
primitive is used for the fraction (in case the denominator is not one; and a
pair of braces contains the |A\over B| part). |$\xintFwOver {178.000/25600000}$|
gives $\xintFwOver {178.000/25600000}$, |$\xintFwOver {178.000/1}$| gives
$\xintFwOver {178.000/1}$, |$\xintFwOver {3.5/5.7}$| gives $\xintFwOver
{3.5/5.7}$, and |$\xintFwOver {\xintNum {\xintiiFac{10}/\xintiSqr{\xintiiFac
{5}}}}$| gives $\xintFwOver {\xintNum {\xintiiFac{10}/\xintiSqr{\xintiiFac
{5}}}}$.
\subsection{\csbh{xintSignedFwOver}}\label{xintSignedFwOver}
This is as \csbxint{FwOver}\etype{\Ff} except that a negative fraction has the
sign put in front, not in the numerator. %
%
\leftedline{|\[\xintFwOver
{-355/113}=\xintSignedFwOver {-355/113}\]|}
\[\xintFwOver {-355/113}=\xintSignedFwOver {-355/113}\]
\subsection{\csbh{xintIrr}}\label{xintIrr}
This puts the fraction\etype{\Ff} into its unique irreducible form:
%
\leftedline{|\xintIrr {178.256/256.178}|%
\dtt{=\xintIrr {178.256/256.178}}${}=\xintFrac{\xintIrr
{178.256/256.178}[0]}$}
%
Note that the current implementation does not cleverly first factor powers of 2
and 5, so input such as |\xintIrr {2/3[100]}| will make \xintfracname do the
Euclidean division of |2|\raisebox{.5ex}{|.|}|10^{100}| by |3|, which is a bit
stupid.
Starting with release |1.08|, \csa{xintIrr} does not remove the trailing |/1|
when the output is an integer. This was deemed better for various (stupid?)
reasons and thus the output format is now \emph{always} |A/B| with |B>0|. Use
\csbxint{PRaw} on top of \csa{xintIrr} if it is needed to get rid of a possible
trailing |/1|. For display in math mode, use rather |\xintFrac{\xintIrr {f}}| or
|\xintFwOver{\xintIrr {f}}|.
\subsection{\csbh{xintJrr}}\label{xintJrr}
This also puts the fraction\etype{\Ff} into its unique irreducible form:
%
\leftedline{|\xintJrr {178.256/256.178}|%
\dtt{=\xintJrr {178.256/256.178}}}
%
This is faster than \csa{xintIrr} for fractions having some big common
factor in the numerator and the denominator.\par
{\centering |\xintJrr {\xintiPow{\xintiiFac {15}}{3}/\xintiiPrdExpr
{\xintiiFac{10}}{\xintiiFac{30}}{\xintiiFac{5}}\relax }|\dtt{=%
\xintJrr {\xintiPow{\xintiiFac {15}}{3}/\xintiiPrdExpr
{\xintiiFac{10}}{\xintiiFac{30}}{\xintiiFac{5}}\relax }}\par} But to notice the
difference one would need computations with much bigger numbers than in this
example.
Starting with release |1.08|, \csa{xintJrr} does not remove the trailing |/1|
when the output is an integer.
\subsection{\csbh{xintTrunc}}\label{xintTrunc}
\csa{xintTrunc}|{x}{f}|\etype{\numx\Ff} returns the integral part, a dot, and
then the first |x| digits of the decimal
expansion of the fraction |f|. The
argument |x| should be non-negative.
In the special case when |f| evaluates to $0$, the output is $0$ with no decimal
point nor decimal digits, else the post decimal mark digits are always printed.
A non-zero negative |f| which is smaller in absolute value than |10^{-x}| will
give $-0.000...$.
%
\leftedline{|\xintTrunc
{16}{-803.2028/20905.298}|\dtt{=\xintTrunc {16}{-803.2028/20905.298}}}
%
\leftedline{|\xintTrunc {20}{-803.2028/20905.298}|\dtt{=\xintTrunc
{20}{-803.2028/20905.298}}}
%
\leftedline{|\xintTrunc {10}{\xintPow {-11}{-11}}|\dtt{=\xintTrunc
{10}{\xintPow {-11}{-11}}}}
%
\leftedline{|\xintTrunc {12}{\xintPow {-11}{-11}}|\dtt{=\xintTrunc
{12}{\xintPow {-11}{-11}}}}
%
\leftedline{|\xintTrunc {12}{\xintAdd {-1/3}{3/9}}|\dtt{=\xintTrunc
{12}{\xintAdd {-1/3}{3/9}}}} The digits printed are exact up to and
including the last one.
\subsection{\csbh{xintiTrunc}}\label{xintiTrunc}
\csa{xintiTrunc}|{x}{f}|\etype{\numx\Ff} returns the integer equal to |10^x|
times what \csa{xintTrunc}|{x}{f}| would produce.
%
\leftedline{|\xintiTrunc
{16}{-803.2028/20905.298}|\dtt{=\xintiTrunc {16}{-803.2028/20905.298}}}
%
\leftedline{|\xintiTrunc {10}{\xintPow {-11}{-11}}|\dtt{=\xintiTrunc
{10}{\xintPow {-11}{-11}}}}
%
\leftedline{|\xintiTrunc {12}{\xintPow {-11}{-11}}|\dtt{=\xintiTrunc
{12}{\xintPow {-11}{-11}}}}
%
The difference between \csa{xintTrunc}|{0}{f}| and \csa{xintiTrunc}|{0}{f}| is
that the latter never has the decimal mark always present in the former except
for |f=0|. And \csa{xintTrunc}|{0}{-0.5}| returns ``\dtt{\xintTrunc
0{-0.5}}'' whereas \csa{xintiTrunc}|{0}{-0.5}| simply returns
``\dtt{\xintiTrunc 0{-0.5}}''.
\subsection{\csbh{xintTTrunc}}\label{xintTTrunc}
\csa{xintTTrunc}|{f}|\etype{\Ff} truncates to an integer (truncation towards
zero). This is the same as |\xintiTrunc {0}{f}| and as \csbxint{Num}.
\subsection{\csbh{xintXTrunc}}\label{xintXTrunc}
\csa{xintXTrunc}|{x}{f}|\retype{\numx\Ff} is completely expandable but not
\fexpan dable, as is indicated by the hollow star in the margin. It can not be
used as argument to the other package macros, but is designed to be used inside
an |\edef|, or rather a |\write|. Here is an example session where the user
after some warming up checks that $1/66049=1/257^2$ has period $257*256=65792$
(it is also checked here that this is indeed the smallest period).
\begin{framed}
To use \csa{xintXTrunc} the user must load \xinttoolsname, additionally to
\xintfracname. The interactive session below does not show this because it
was done at a time when \xintname (hence also \xintfracname) automatically
loaded \xinttoolsname. This is not the case anymore. \csa{xintXTrunc} is the
sole dependency of \xintfracname on \xinttoolsname.
\end{framed}
%
\begingroup\small
\everb|@
xxx:_xint $ etex -jobname worksheet-66049
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
restricted \write18 enabled.
**\relax
entering extended mode
*\input xintfrac.sty
(./xintfrac.sty (./xint.sty (./xinttools.sty)))
*\message{\xintTrunc {100}{1/71}}% Warming up!
0.01408450704225352112676056338028169014084507042253521126760563380281690140845
07042253521126760563380
*\message{\xintTrunc {350}{1/71}}% period is 35
0.01408450704225352112676056338028169014084507042253521126760563380281690140845
0704225352112676056338028169014084507042253521126760563380281690140845070422535
2112676056338028169014084507042253521126760563380281690140845070422535211267605
6338028169014084507042253521126760563380281690140845070422535211267605633802816
901408450704225352112676056338028169
*\edef\Z {\xintXTrunc {65792}{1/66049}}% getting serious...
*\def\trim 0.{}\oodef\Z {\expandafter\trim\Z}% removing 0.
*\edef\W {\xintXTrunc {131584}{1/66049}}% a few seconds
*\oodef\W {\expandafter\trim\W}
*\oodef\ZZ {\expandafter\Z\Z}% doubling the period
*\ifx\W\ZZ \message{YES!}\else\message{BUG!}\fi % xint never has bugs...
YES!
*\message{\xintTrunc {260}{1/66049}}% check visually that 256 is not a period
0.00001514027464458205271843631243470756559523989765174340262532362337052794137
6856576178291874214598252812306015231116292449545034746930309315810988811337037
6538630410755651107511090251177156353616254598858423291798513225029902042423049
5541189117170585474420505
*\edef\X {\xintXTrunc {257*128}{1/66049}}% infix here ok, less than 8 tokens
*\oodef\X {\expandafter\trim\X}% we now have the first 257*128 digits
*\oodef\XX {\expandafter\X\X}% was 257*128 a period?
*\ifx\XX\Z \message{257*128 is a period}\else \message{257 * 128 not a period}\fi
257 * 128 not a period
*\immediate\write-1 {1/66049=0.\Z... (repeat)}
*\oodef\ZA {\xintNum {\Z}}% we remove the 0000, or we could use next \xintiMul
*\immediate\write-1 {10\string^65792-1=\xintiiMul {\ZA}{66049}}
*% This was slow :( I should write a multiplication, still completely
*% expandable, but not f-expandable, which could be much faster on such cases.
*\bye
No pages of output.
Transcript written on worksheet-66049.log.
xxx:_xint $
|
\endgroup
\begin{framed}
The |\xintiiMul {\ZA}{66049}| above can sadly \emph{not} be executed with
\xintname 1.2, due to the new limitation to at most about $19950$ digits for
multiplication. On the other hand |\edef\W {\xintXTrunc {131584}{1/66049}}|
produces the $131584$ digits four times faster. The macro \csbxint{XTrunc}
has not yet been adapted to the new integer model underlying the 1.2
\xintcorename macros, and perhaps some future improvements are possible. So
far it only benefits from a faster division routine, in that specific case
for a divisor having more than four but less than nine digits.
\end{framed}
Fraction arguments to |\xintXTrunc| corresponding to a |A/B[N]| with a negative
|N| are treated somewhat less efficiently (additional memory impact) than for positive or zero |N|. This is because the algorithm tries to work with the
smallest denominator hence does not extend |B| with zeroes, and technical
reasons lead to the use of some tricks.%
%
\footnote{Technical note: I do not provide an |\xintXFloat|
because this would almost certainly mean having to clone the entire
core division routines into a ``long division'' variant. But this
could have given another approach to the implementation of
|\xintXTrunc|, especially for the case of a negative |N|. Doing these
things with \TeX{} is an effort. Besides an |\xintXFloat|
would be interesting only if also for example the square root routine
was provided in an |X| version (I have not given thought to that). If
feasible |X| routines would be interesting in the |\xintexpr|
context where things are expanded inside |\csname..\endcsname|.}
Contrarily to \csbxint{Trunc}, in the case of the second argument revealing
itself to be exactly zero, \csbxint{XTrunc} will output $0.000...$, not $0$.
Also, the first argument must be at least $1$.
\subsection{\csbh{xintRound}}\label{xintRound}
\csa{xintRound}|{x}{f}|\etype{\numx\Ff} returns the start of the decimal
expansion of the fraction |f|, rounded to |x| digits precision after the decimal
point. The argument |x| should be non-negative. Only when |f| evaluates exactly
to zero does \csa{xintRound} return |0| without decimal point. When |f| is not
zero, its sign is given in the output, also when the digits printed are all
zero. %
%
\leftedline{|\xintRound {16}{-803.2028/20905.298}|\dtt{=\xintRound
{16}{-803.2028/20905.298}}}
%
\leftedline{|\xintRound {20}{-803.2028/20905.298}|\dtt{=\xintRound
{20}{-803.2028/20905.298}}}
%
\leftedline{|\xintRound {10}{\xintPow {-11}{-11}}|\dtt{=\xintRound
{10}{\xintPow {-11}{-11}}}}
%
\leftedline{|\xintRound {12}{\xintPow {-11}{-11}}|\dtt{=\xintRound
{12}{\xintPow {-11}{-11}}}}
%
\leftedline{|\xintRound {12}{\xintAdd {-1/3}{3/9}}|\dtt{=\xintRound
{12}{\xintAdd {-1/3}{3/9}}}} The identity |\xintRound {x}{-f}=-\xintRound
{x}{f}| holds. And regarding $(-11)^{-11}$ here is some more of its expansion:
%
\leftedline{\dtt{\xintTrunc {50}{\xintPow {-11}{-11}}\dots}}
\subsection{\csbh{xintiRound}}\label{xintiRound}
\csa{xintiRound}|{x}{f}|\etype{\numx\Ff} returns the integer equal to |10^x|
times what \csa{xintRound}|{x}{f}| would return. %
%
\leftedline{|\xintiRound
{16}{-803.2028/20905.298}|\dtt{=\xintiRound {16}{-803.2028/20905.298}}}
%
\leftedline{|\xintiRound {10}{\xintPow {-11}{-11}}|\dtt{=\xintiRound
{10}{\xintPow {-11}{-11}}}}
%
Differences between \csa{xintRound}|{0}{f}| and \csa{xintiRound}|{0}{f}|: the
former cannot be used inside integer-only macros, and the latter removes the
decimal point, and never returns |-0| (and removes all superfluous leading
zeroes.)
\subsection{\csbh{xintFloor}, \csbh{xintiFloor}}
\label{xintFloor}\label{xintiFloor}
|\xintFloor {f}|\etype{\Ff} returns the largest relative integer |N| with
|N|${}\leqslant{}$|f|. %
%
\leftedline{|\xintFloor {-2.13}|\dtt{=\xintFloor
{-2.13}}, |\xintFloor {-2}|\dtt{=\xintFloor {-2}}, |\xintFloor
{2.13}|\dtt{=\xintFloor {2.13}}
%
}
|\xintiFloor {f}|\etype{\Ff} does the same but without adding the
|/1[0]|.
%
\leftedline{|\xintiFloor {-2.13}|\dtt{=\xintiFloor
{-2.13}}, |\xintiFloor {-2}|\dtt{=\xintiFloor {-2}}, |\xintiFloor
{2.13}|\dtt{=\xintiFloor {2.13}}}
\subsection{\csbh{xintCeil}, \csbh{xintiCeil}}
\label{xintCeil}\label{xintiCeil}
|\xintCeil {f}|\etype{\Ff} returns the smallest relative integer |N| with
|N|${}>{}$|f|. %
%
\leftedline{|\xintCeil {-2.13}|\dtt{=\xintCeil {-2.13}},
|\xintCeil {-2}|\dtt{=\xintCeil {-2}}, |\xintCeil
{2.13}|\dtt{=\xintCeil {2.13}}
%
}
|\xintiCeil {f}|\etype{\Ff} does the same but without adding the
|/1[0]|.
\subsection{\csbh{xintTFrac}}\label{xintTFrac}
\csa{xintTFrac}|{f}|\etype{\Ff} returns the fractional part,
|f=trunc(f)+frac(f)|. Thus if |f<0|, then |-1<frac(f)<=0| and if |f>0| one has
|0<= frac(f)<1|. The |T| stands for `Trunc', and there should exist also
similar macros associated respectively with `Round', `Floor', and `Ceil', each
type of rounding to an integer deserving arguably to be associated with a
fractional ``modulo''. By sheer laziness, the package currently implements
only the ``modulo'' associated with `Truncation'. Other types of modulo may be
obtained more cumbersomely via a combination of the rounding with a subsequent
subtraction from |f|.
Notice that the result is filtered through \csbxint{REZ}, and will thus be of
the form |A/B[N]|, where neither |A| nor |B| has trailing zeros. But the
output fraction is not reduced to smallest terms.\MyMarginNote{\noindent
Do\-cu\-men\-ta\-tion updated.}
The function call in expressions (\csbxint{expr}, \csbxint{floatexpr}) is
|frac|. Inside |\xintexpr..\relax|, the function |frac| is mapped to
\csa{xintTFrac}. Inside |\xintfloatexpr..\relax|, |frac| first applies
\csa{xintTFrac} to its argument (which may be an exact fraction with more
digits than the floating point precision) and only in a second stage makes the
conversion to a floating point number with the precision as set by |\xintDigits|
(default is \dtt{16}).
%
\leftedline{|\xintTFrac {1235/97}|\dtt{=\xintTFrac {1235/97}}\quad
|\xintTFrac {-1235/97}|\dtt{=\xintTFrac {-1235/97}}}
%
\leftedline{|\xintTFrac {1235.973}|\dtt{=\xintTFrac {1235.973}}\quad
|\xintTFrac {-1235.973}|\dtt{=\xintTFrac {-1235.973}}}
%
\leftedline{|\xintTFrac {1.122435727e5}|%
\dtt{=\xintTFrac {1.122435727e5}}}
\subsection{\csbh{xintE}}\label{xintE}
|\xintE {f}{x}|\etype{\Ff\numx} multiplies the fraction |f| by $10^x$. The
\emph{second} argument |x| must obey the \TeX{} bounds. Example:
%
\leftedline{|\count 255 123456789 \xintE {10}{\count 255}|\dtt{->\count
255 123456789 \xintE {10}{\count 255}}} Be careful that for obvious reasons
such gigantic numbers should not be given to \csbxint{Num}, or added to
something with a widely different order of magnitude, as the package always
works to get the \emph{exact} result. There is \emph{no problem} using them for
\emph{float} operations:%
%
\leftedline{|\xintFloatAdd
{1e1234567890}{1}|\dtt{=\xintFloatAdd {1e1234567890}{1}}}
\subsection{\csbh{xintAdd}}\label{xintAdd}
Computes the addition\etype{\Ff\Ff} of two fractions. To keep for integers the
integer format on output use \csbxint{iAdd}.
Checks if one denominator is a multiple of the other. Else multiplies the
denominators.
\subsection{\csbh{xintSub}}\label{xintSub}
Computes the difference\etype{\Ff\Ff} of two fractions (|\xintSub{F}{G}|
computes |F-G|). To keep for integers the integer format on output use
\csbxint{iSub}.
Checks if one denominator is a multiple of the other. Else multiplies the
denominators.
\subsection{\csbh{xintMul}}\label{xintMul}
Computes the product\etype{\Ff\Ff} of two fractions. To keep for integers the
integer format on output use \csbxint{iMul}.
No reduction attempted.
\subsection{\csbh{xintSqr}}\label{xintSqr}
Computes the square\etype{\Ff} of one fraction. To maintain for integer input
an integer format on output use \csbxint{iSqr}.
\subsection{\csbh{xintDiv}}\label{xintDiv}
Computes the quotient \etype{\Ff\Ff} of two fractions.
(|\xintDiv{F}{G}| computes |F/G|). To keep for integers the integer format on
output use \csbxint{iMul}.
No reduction attempted.
\subsection{\csbh{xintDivTrunc}, \csbh{xintDivRound}}
\label{xintDivTrunc}
\label{xintDivRound}
Computes the quotient \etype{\Ff\Ff} of the two arguments then either
truncates or rounds to an integer.
\subsection{\csbh{xintiFac}}\label{xintiFac}
With \xintfracname loaded |\xintiFac|\etype{\Numf} is extended to allow a
fraction |f| as input, it will be truncated first to an integer |n| before the
evaluation of the factorial. The output is an integer in strict format,
without a trailing |/1[0]|. See the \hyperref[xintiiFac]{\csa{xintiiFac} doc}
for more info.
\subsection{\csbh{xintiBinomial}}\label{xintiBinomial}
With \xintfracname loaded |\xintiBinomial|\etype{\Numf\Numf} is extended to
allow fractional inputs which will be truncated to integers before the
evaluation of the binomial. The output is an integer in strict format, without
a trailing |/1[0]|. See the
\hyperref[xintiiBinomial]{\csa{xintiiBinomial} doc} for the current allowable
range.
\subsection{\csbh{xintiPFactorial}}\label{xintiPFactorial}
% fait 2015/11/29 pour 1.2f.
With \xintfracname loaded |\xintiPFactorial|\etype{\Numf\Numf} is extended to
allow fractional inputs which will be truncated to integers before the
evaluation of the partial factorial. The output is an integer in strict
format, without a trailing |/1[0]|. See the
\hyperref[xintiiPFactorial]{\csa{xintiiPFactorial} doc} for more info.
\subsection{\csbh{xintPow}}\label{xintPow}
\csa{xintPow}{|{f}{x}|}:\etype{\Ff\Numf} computes |f^x| with |f| a fraction and
|x| possibly also, but |x| will first get truncated to a (positive or negative)
integer.
The output will now always be in the form |A/B[n]| (even when the exponent
vanishes: |\xintPow {2/3}{0}|\dtt{=\xintPow{2/3}{0}}).
The macro handling only integers is available as \csbxint{iPow}. Only
\csa{xintPow} accepts negative exponent, as this produces fractions.
Within an \csbxint{iiexpr}|..\relax| the infix operator |^| is mapped to
\csa{xintiiPow}; within an \csbxint{expr}-ession it is mapped to
\csa{xintPow}.
\subsection{\csbh{xintSum}}\label{xintSum}\label{xintSumExpr}
This\etype{f{$\to$}{\lowast\Ff}} computes the sum of fractions. The output
will now always be in the form |A/B[n]|. The original, for big integers only
(in strict format), is available as \csa{xintiiSum}.
\begin{everbatim*}
\xintSum {{1282/2196921}{-281710/291927}{4028/28612}}
\end{everbatim*}
No simplification attempted.
\subsection{\csbh{xintPrd}}\label{xintPrd}\label{xintPrdExpr}
TThis\etype{f{$\to$}{\lowast\Ff}} computes the product of fractions. The output
will now always be in the form |A/B[n]|. The original, for big integers only
(in strict format), is available as \csa{xintiiPrd}.
\begin{everbatim*}
\xintPrd {{1282/2196921}{-281710/291927}{4028/28612}}
\end{everbatim*}
No simplification attempted.
\subsection{\csbh{xintCmp}}\label{xintCmp}
This\etype{\Ff\Ff} compares two fractions |F| and |G| and produces
|-1|, |0|, or |1| according to |F<G|, |F=G|, |F>G|.
For choosing branches according to the result of comparing |f| and |g|, see
\csbxint{ifCmp}.
\subsection{\csbh{xintIsOne}}
This\etype{\Ff} returns |1| if the fraction is |1| and |0| if not.
\begin{everbatim*}
\xintIsOne {21921379213/21921379213} but \xintIsOne {1.00000000000000000000000000000001}
\end{everbatim*}
\subsection{\csbh{xintGeq}}\label{xintGeq}
This\etype{\Ff\Ff} compares the \emph{absolute values} of two
fractions.|\xintGeq{f}{g}| returns |1| if {\catcode`| 12 $|f|\geqslant|g|$} and |0|
if not.
May be used for expandably branching as:
\verb+\xintSgnFork{\xintGeq{f}{g}}{}{code for |f|<|g|}{code for
|f|+$\geqslant$\verb+|g|}+
\subsection{\csbh{xintMax}}\label{xintMax}
The maximum of two fractions.\etype{\Ff\Ff} But now |\xintMax {2}{3}|
returns \dtt{\xintMax {2}{3}}. The original, for use with (possibly big)
integers only with no need of normalization, is available as \csbxint{iiMax}:
|\xintiiMax {2}{3}=|\dtt{\xintiMax {2}{3}}.\etype{ff}
There is also \csbxint{iMax}\etype{\Numf\Numf} which works with fractions but
first truncates them to integers.
\begin{everbatim*}
\xintMax {2.5}{7.2} but \xintiMax {2.5}{7.2}
\end{everbatim*}
\subsection{\csbh{xintMin}}\label{xintMin}
The maximum of two fractions.\etype{\Ff\Ff} The original, for use with (possibly big)
integers only with no need of normalization, is available as \csbxint{iiMin}:
|\xintiiMin {2}{3}=|\dtt{\xintiMin {2}{3}}.\etype{ff}
There is also \csbxint{iMin}\etype{\Numf\Numf} which works with fractions but first
truncates them to integers.
\begin{everbatim*}
\xintMin {2.5}{7.2} but \xintiMin {2.5}{7.2}
\end{everbatim*}
\subsection{\csbh{xintMaxof}}\label{xintMaxof}
The maximum of any number of fractions, each within braces, and the whole
thing within braces. \etype{f{$\to$}{\lowast\Ff}}
\begin{everbatim*}
\xintMaxof {{1.23}{1.2299}{1.2301}} and \xintMaxof {{-1.23}{-1.2299}{-1.2301}}
\end{everbatim*}
\subsection{\csbh{xintMinof}}\label{xintMinof}
The minimum of any number of fractions, each within braces, and the whole
thing within braces. \etype{f{$\to$}{\lowast\Ff}}
\begin{everbatim*}
\xintMinof {{1.23}{1.2299}{1.2301}} and \xintMinof {{-1.23}{-1.2299}{-1.2301}}
\end{everbatim*}
\subsection{\csbh{xintAbs}}\label{xintAbs}
The absolute value\etype{\Ff}. Note that |\xintAbs {-2}|\dtt{=\xintAbs {-2}}
whereas |\xintiAbs {-2}|\dtt{=\xintiAbs {-2}}.
\subsection{\csbh{xintSgn}}\label{xintSgn}
The sign of a fraction.\etype{\Ff}
\subsection{\csbh{xintOpp}}\label{xintOpp}
The opposite of a fraction.\etype{\Ff}
Note that |\xintOpp {3}| now outputs \dtt{\xintOpp
{3}} whereas |\xintiOpp {3}| returns \dtt{\xintiOpp {3}}.
\subsection{\csbh{xintDigits}, \csbh{xinttheDigits}}
\label{xintDigits}
\label{xinttheDigits}
The syntax |\xintDigits := D;| (where spaces do not matter) assigns the
value of |D| to the number of digits to be used by floating point
operations. The default is |16|. The maximal value is |32767|. The macro
|\xinttheDigits|\etype{} serves to print the current value.
\subsection{\csbh{xintFloat}}\label{xintFloat}
The macro |\xintFloat [P]{f}|\etype{{\upshape[\numx]}\Ff} has an optional argument |P| which replaces
the current value of |\xinttheDigits|. The (rounded truncation of the) fraction
|f| is then printed in scientific form, with |P| digits,
a lowercase |e| and an exponent |N|. The first digit is from |1| to |9|, it is
preceded by an optional minus sign and
is followed by a dot and |P-1| digits, the trailing zeroes
are not trimmed. In the exceptional case where the
rounding went to the next power of ten, the output is |10.0...0eN|
(with a sign, perhaps). The sole exception is for a zero value, which then gets
output as |0.e0| (in an \csa{xintCmp} test it is the only possible output of
\csa{xintFloat} or one of the `Float' macros which will test positive for
equality with zero).
%
\leftedline{|\xintFloat[32]{1234567/7654321}|%
\dtt{=\xintFloat[32]{1234567/7654321}}}
%
\leftedline{|\xintFloat[32]{1/\xintiiFac{100}}|%
\dtt{=\xintFloat[32]{1/\xintiiFac{100}}}}
The argument to \csa{xintFloat} may be an |\xinttheexpr|-ession, like the
other macros; only its final evaluation is submitted to \csa{xintFloat}: the
inner evaluations of chained arguments are not at all done in `floating'
mode. For this one must use |\xintthefloatexpr|.
\subsection{\csbh{xintPFloat}}\label{xintPFloat}
The macro |\xintPFloat [P]{f}|\etype{{\upshape[\numx]}\Ff} is like
\csbxint{Float} but ``pretty-prints'' the output. Its behaviour has changed
with release |1.2f|\IMPORTANT{}: there is only one simplification rule now
which is that decimal notation (with possibly needed extra zeros) is used in
place of scientific notation when the exponent would end up being between
\dtt{-5} and \dtt{5} inclusive.\footnote{In the exceptional case of an input
rounded up towards next power of ten, the exponent referred-to here is the
integer |N| in |10.0..0eN| with a total number of zeroes equal to the
precision.}
If the input vanishes the output will be \dtt{\xintPFloat{0}} with a a decimal
mark\CHANGED{1.2f} (the original version printed \dtt{0} with no decimal
mark).\footnote{Currently there are no subnormal numbers, and no underflow
because the exponent is only limited by the maximal \TeX\ number; thus
underflow situations would manifest themselves via low-level arithmetic
overflow errors.}
\csbxint{thefloatexpr} applies this macro to its output (or each of
its outputs, if comma separated).
Currently trailing zeros are not trimmed.
\begin{everbatim*}
\begingroup\def\test #1{#1${}\to{}$\xintPFloat{#1}}%
\string\xintDigits\ at \xinttheDigits
\begin{itemize}[nosep]
\item \test {0}
\item \test {1.23456789e-7}
\item \test {1.23456789e-6}
\item \test {1.23456789e-5}
\item \test {1.23456789e-4}
\item \test {1.23456789e-3}
\item \test {1.23456789e-2}
\item \test {1.23456789e-1}
\item \test {1.23456789e0}
\item \test {1.23456789e1}
\item \test {1.23456789e2}
\item \test {1.23456789e3}
\item \test {1.23456789e4}
\item \test {1.23456789e5}
\item \test {1.23456789e6}
\item \test {1.23456789e7}
\end{itemize}
\endgroup
\end{everbatim*}
\subsection{\csbh{xintFloatE}}\label{xintFloatE}
|\xintFloatE [P]{f}{x}|\etype{{\upshape[\numx]}\Ff\numx} multiplies the input
|f| by $10^x$, and
converts it to float format according to the optional first argument or current
value of |\xinttheDigits|.
%
\leftedline{|\xintFloatE {1.23e37}{53}|\dtt{=\xintFloatE {1.23e37}{53}}}
\subsection{\csbh{xintFloatAdd}}\label{xintFloatAdd}
|\xintFloatAdd [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f|
and |g| with their float approximations |f'| and |g'| to |P| significant
places or to the precision from |\xintDigits|.\CHANGED{1.2f} It then produces
the sum |f'+g'|, correctly rounded to nearest with the same number of
significant places.
As for \csbxint{Float}, in case of rounding up to next power of ten, the value
may exceptionally come out as |10.0...0eN| with a total of |P+1| digits.
See \autoref{ssec:floatingpoint} for more.
\subsection{\csbh{xintFloatSub}}\label{xintFloatSub}
|\xintFloatSub [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f|
and |g| with their float approximations |f'| and |g'| to |P| significant
places or to the precision from |\xintDigits|.\CHANGED{1.2f} It then produces
the difference |f'-g'| correctly rounded to nearest |P|-float.
As for \csbxint{Float}, in case of rounding up to next power of ten, the value
may exceptionally come out as |10.0...0eN| with a total of |P+1| digits.
See \autoref{ssec:floatingpoint} for more.
\subsection{\csbh{xintFloatMul}}\label{xintFloatMul}
|\xintFloatMul [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f|
and |g| with their float approximations |f'| and |g'| to |P| (or
|\xinttheDigits|) significant places.\CHANGED{1.2f} It then correctly rounds
the product |f'*g'| to nearest |P|-float.
See \autoref{ssec:floatingpoint} for more.
\begin{framed}
It is obviously much needed that the author improves its algorithms to avoid
going through the exact |2P| or |2P-1| digits before
throwing to the waste-bin half of those digits !
% \xintname initially was purely an \emph{exact} arbitrary precision
% arithmetic machine, and the introduction of floating point numbers was an
% after-thought. I got it working in release |1.07 (2013/05/25)| and never had
% time to come back to it.
\end{framed}
\subsection{\csbh{xintFloatDiv}}\label{xintFloatDiv}
|\xintFloatDiv [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f|
and |g| with their float approximations |f'| and |g'| to |P| (or
|\xinttheDigits|) significant places.\CHANGED{1.2f} It then correctly rounds
the fraction |f'/g'| to nearest |P|-float.
See \autoref{ssec:floatingpoint} for more.
\subsection{\csbh{xintFloatFac}}\label{xintFloatFac}
\csa{xintFloatFac}|[P]{f}|\etype{{\upshape[\numx]}\Numf} returns the
factorial with either \csa{xinttheDigits} or |P| digits of precision.
% je devrais vérifier mais j'ai écrit cela fin novembre 2015 début décembre je
% suppose que je savais ce que je disais.
The exact theoretical value differs from the calculated one |Y| by an absolute
error strictly less than |0.6 ulp(Y)|.\NewWith{1.2}
\begin{everbatim*}
$1000!\approx{}$\xintFloatFac [30]{1000}
\end{everbatim*}
The computation proceeds via doing explicitely the product, as
the Stirling formula cannot be used for lack so far of |exp/log|.
The maximal allowed argument is $99999999$, but already $100000!$ currently
takes, for \dtt{16} digits of precision, a few seconds on my laptop (it
returns \dtt{2.824229407960348e456573}).
The |factorial| function is available in \csbxint{floatexpr}:
\begin{everbatim*}
\xintthefloatexpr factorial(1000)\relax % same as 1000!
\end{everbatim*}
\subsection{\csbh{xintFloatBinomial}}\label{xintFloatBinomial}
\csa{xintFloatBinomial}|[P]{x}{y}|\etype{{\upshape[\numx]}\Numf\Numf} computes
binomial coefficients with either \csa{xinttheDigits} or |P| digits of
precision.\NewWith{1.2f}
When |x<0| an out-of-range error is raised. Else, if |y<0| or if |x<y| the macro
evaluates to \dtt{\xintFloatBinomial{1}{-1}}.\CHANGED{1.2h}
The exact theoretical value differs from the calculated one |Y| by an absolute
error strictly less than |0.6 ulp(Y)|.
\begin{everbatim*}
${3000\choose 1500}\approx{}$\xintFloatBinomial [24]{3000}{1500}
\end{everbatim*}
% \begin{everbatim*}
% ${9999\choose 5000}\approx{}$\xintFloatBinomial [24]{9999}{5000}
% \end{everbatim*}
% 2015/11/28
% 7.95895131766219474168799e3007
% aparté: (testé avec Maple 16, 2015/11/28)
% > binomial (9999.,5000.);
% 3008
% 0.795895131768 10
%
% > Digits:=32;
% Digits := 32
%
% > binomial (9999.,5000.);
% 3008
% 0.795895131768 10
% apparemment le binomial de Maple ne sait pas calculer avec plus de
% précision!
% et son dernier chiffre est faux! Pourtant GAMMA(9999.) fonctionne. Sauf si
% je n'ai pas compris quelque chose il me semble donc que le binomial de Maple
% est bogué...binomial(100.,50.); marche lui et binomial(4999.,2000.); aussi,
% bon clairement on a un bug de Maple ! oui binomial(8999.,5000.); ainsi que
% binomial(10999.,5000.); fonctionnent avec Digits:=32 mais **pas**
% binomial(9999.,5000.)... binomial(10000.,5000.); et binomial(9998.,5000.);
% sont OK. Est-ce qu'on gagne quelque chose pour un bug report ?
% > binomial(9999.,5000.);
% 3008
% 0.795895131768 10
% > binomial(10000.,5000.);
% 3009
% 0.1591790263532438948337597273641521 10
% > binomial(9998.,5000.);
% 3008
% 0.3979077671466477799149739359402922 10
% en plus je lui demande 32 chiffres et il m'en sort 34.
The |binomial| function is available in \csbxint{floatexpr}:
\begin{everbatim*}
\xintthefloatexpr binomial(3000,1500)\relax
\end{everbatim*}
The computation is based on the formula |(x-y+1)...x/y!| (here one arranges
|y<=x-y| naturally).
\subsection{\csbh{xintFloatPFactorial}}\label{xintFloatPFactorial}
\csa{xintFloatPFactorial}|[P]{x}{y}|\etype{{\upshape[\numx]}\Numf\Numf}
computes the product |(x+1)...y|.
The inputs |x| and |y| must evaluate to non-negative integers less in absolute
value than
$10^8$.\NewWith{1.2f}
It was a bit unfortunate with |1.2f| that the code deliberately raised an
error if the condition |0<=x<=y<10^8| was violated. See
\autoref{xintiiPFactorial} for the now prevailing rules.\CHANGED{1.2h} Only
for the range |0<= x <= y < 10^8| is it to be considered that the behaviour is
fixed and will not change in the future.
The exact theoretical value differs from the calculated one |Y| by an absolute
error strictly less than |0.6 ulp(Y)|.
The |pfactorial| function is available in \csbxint{floatexpr}:
\begin{everbatim*}
\xintthefloatexpr pfactorial(2500,5000)\relax
\end{everbatim*}
\subsection{\csbh{xintFloatPow}}\label{xintFloatPow}
|\xintFloatPow [P]{f}{x}|\etype{{\upshape[\numx]}\Ff\numx} uses either the
optional argument |P| or the value of |\xinttheDigits|. It computes a floating
approximation to |f^x|. The precision |P| must be at least |1|, naturally.
The exponent |x| will be fed to a |\numexpr|, hence count registers are accepted
on input for this |x|. And the absolute value \verb+|x|+ must obey the \TeX{}
bound. For larger exponents use the slightly slower routine \csbxint{FloatPower}
which allows the exponent to be a fraction simplifying to an integer and does
not limit its size. This slightly slower routine is the one to which |^| is
mapped inside |\xintthefloatexpr...\relax|.
The argument |f| is first rounded to |P| significant places to give
|f'|.\CHANGED{1.2f} The output |Z| is such that the exact |f'^x| differs from
|Z| by an absolute error less than |0.52 ulp(Z)|.
%
\leftedline{|\xintFloatPow [8]{3.1415}{1234567890}|%
\dtt{=\xintFloatPow [8]{3.1415}{1234567890}}}
\subsection{\csbh{xintFloatPower}}\label{xintFloatPower}
\csa{xintFloatPower}|[P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Numf} computes a
floating point value |f^g| where the exponent |g| is not constrained to be at
most the \TeX{} bound \texttt{\number "7FFFFFFF}. It may even be a fraction
|A/B| but must simplify to a (possibly big) integer. The exponent of the
\emph{output} however \emph{must} at any rate obey the \TeX{}
\dtt{\number"7FFFFFFF} bound.
The argument |f| is first rounded to |P| significant places to give
|f'|.\CHANGED{1.2f} The output |Z| is such that the exact |f'^g| differs from
|Z| by an absolute error less than |0.6 ulp(Z)| (actually |0.52
ulp(Z)|).\footnote{For the |0.6 ulp(Z)| bound, earlier releases had
potentially a problem for negative exponents; the final reverse was done
with only two guard digits (due to the implementation of \csbxint{Float}),
and as a result the final error could conceivably exceed |0.6 ulp(Z)|,
although remaining smaller than |0.7 ulp(Z)|.}
%
%
\leftedline{|\xintFloatPower [8]{3.1415}{3e9}|%
\dtt{=\xintFloatPower [8]{3.1415}{3e9}}} Notice that |3e9>2^31|.
Here is another example:
%
\leftedline{|\xintFloatPower [48] {1.1547}{\xintiiPow {2}{35}}|}
%
computes $(1.1547)^{2^{35}}=(1.1547)^{\xintiiPow {2}{35}}$ to be
approximately
%
\leftedline{\dtt{\np{\xintFloatPower [48] {1.1547}{\xintiiPow {2}{35}}}}}
%
Again, $2^{35}$ exceeds \TeX's bound, but \csa{xintFloatPower} allows it, what
counts is the exponent of the result which, while dangerously close to
$2^{31}$ is not quite there yet.\footnote{The printing of the result was done
via the |\numprint| command from the \url{http://ctan.org/pkg/numprint}
package.}
Inside an |\xintfloatexpr|-ession, \csa{xintFloatPower} is the function to
which |^| is mapped.\footnote{I am constantly hesitating about this. In my
testing, switching to \csbxint{FloatPow} would only bring from 5\% to
perhaps 20\% gain for computations with \dtt{16} digits of precision and
moderately sized exponent.}\footnote{Since |1.2f|, the \string^ operator
handles also half-integer exponents.\NewWith {1.2f}} Thus the same
computation as above can be done via the non-expandable assignment
|\xintDigits:=48;| and
%
\leftedline{|\xintthefloatexpr 1.1547^(2^35)\relax|}
%
There is a subtlety here that the |2^35| will be evaluated as a floating point
number but fortunately it only has \dtt{\xintLen{\xintiiPow{2}{35}}} digits,
hence the final evaluation is done with a correct exponent. It is safer, and
also more efficient to code the above rather as:
%
\leftedline{|\xintthefloatexpr 1.1547^\xintiiexpr 2^35\relax\relax|}
%
to guarantee no loss of digits in the exponent.
There is an important difference between |\xintFloatPower [Q]{X}{Y}| and
|\xintthefloatexpr [Q] X^Y \relax|: in the former case the computation is done
with |Q| digits or precision (but if |X| and |Y| themselves stand for some
floating point macros with arguments, their respective evaluations obey the
precision |\xinttheDigits| or as set optionally in the macro calls
themselves), whereas with \csbxint{thefloatexpr}|[Q]| the evaluation of the
expression proceeds with |\xinttheDigits| digits of precision, and the final
result is then rounded to |Q| digits: thus this makes real sense only if used
with |Q<\xinttheDigits|.
\subsection{\csbh{xintFloatSqrt}}\label{xintFloatSqrt}
\csa{xintFloatSqrt}|[P]{f}|\etype{{\upshape[\numx]}\Ff} computes a floating
point approximation of $\sqrt{|f|}$, either using the optional precision |P| or
the value of |\xinttheDigits|.
More precisely the macro achieves so-called \emph{correct
rounding}:\IMPORTANT{} the produced value is the rounding to |P| significant
places of the abstract exact value, \emph{if the input has itself at most |P|
digits} (and an arbitrary exponent).\NewWith{1.2f}
\begin{everbatim*}
\xintFloatSqrt [89]{10}\newline
\xintFloatSqrt [89]{100}\newline
\xintFloatSqrt [89]{123456789}\newline
And now some tests to check that correct rounding applies correctly (sic):\newline
(we observe in passing illustrations that rounding to nearest is not transitive)\newline
\xintFloatSqrt {5625000075000001}\newline
\xintFloatSqrt [24]{5625000075000001}\newline
\xintFloatSqrt [32]{5625000075000001}\newline
\xintFloatSqrt [48]{562500000000000000000000750000000000000000000001}\newline
\xintFloatSqrt [64]{562500000000000000000000750000000000000000000001}\newline
\xintFloatSqrt [80]{562500000000000000000000750000000000000000000001}\par
\end{everbatim*}
\xintDigits:=16;
\subsection{\csbh{xintiDivision}, \csbh{xintiQuo}, \csbh{xintiRem},
\csbh{xintFDg}, \csbh{xintLDg}, \csbh{xintMON}, \csbh{xintMMON},
\csbh{xintOdd}}
These macros\etype{\Ff\Ff} accept a fraction (or two) on input but will
truncate it (them) to an integer using \csbxint{Num} (which is the same as
\csbxint{TTrunc}). On output they produce integers without |/| nor |[N]|.
All have variants from package \xintname whose names start with |xintii|
rather than |xint|; these variants accept on input only integers in the strict
format (they do not use \csbxint{Num}). They thus have less overhead, and may
be used when one is dealing exclusively with (big) integers.
%
\leftedline{|\xintNum {1e80}|}
%
\leftedline{\dtt{\xintNum{1e80}}}
%\etocdepthtag.toc {xintexpr}
\clearpage
\section{Commands of the \xintexprname package}%
\label{sec:expr}
\localtableofcontents
The \xintexprname package was first released with version |1.07|
(|2013/05/25|) of the \xintname bundle. It was substantially enhanced with
release |1.1| from |2014/10/28|.
Release |1.2| removed a limitation to numbers of at most $5000$ digits, and
there is now a float variant of the factorial. Also the ``pseudo-functions''
|qint|, |qfrac|, |qfloat| (|'q'| for quick), were added to handle very big
inputs and avoid scanning it digit per digit.
The package loads automatically \xintfracname and \xinttoolsname (it is now
the only arithmetic package from the \xintname bundle which loads
\xinttoolsname).
\begin{itemize}
\item for using the |gcd| and |lcm| functions, it is necessary to load package
\xintgcdname.
\begin{everbatim*}
\xinttheexpr lcm (2^5*7*13^10*17^5,2^3*13^15*19^3,7^3*13*23^2)\relax
\end{everbatim*}
\item for allowing hexadecimal numbers (uppercase letters) on input, it is necessary
to load package \xintbinhexname.
\begin{everbatim*}
\xinttheexpr "A*"B*"C*"D*"D*"F, "FF.FF, reduce("FF.FFF + 16^-3)\relax
\end{everbatim*}
\end{itemize}
Please refer to \autoref{sec:xintexprsyntax} for a more detailed description
of the syntax elements for expressions.
\subsection{The \csbh{xintexpr} expressions}
\label{xintexpr}
\label{xinttheexpr}
\label{thexintexpr}
\label{xintthe}
An \xintexprname{}ession is a construct
\csbxint{expr}\meta{expandable\_expression}|\relax|\etype{x} where the
expandable expression is read and completely expanded from left to right.
An |\xintexpr...\relax| \emph{must} end in a |\relax| (which will be absorbed).
Like a |\numexpr| expression, it is not printable as is, nor can it be directly
employed as argument to the other package macros. For this one must use one
of the three equivalent forms:
\begin{itemize}
\item \csb{thexintexpr}\meta{expandable\_expression}|\relax|\etype{x}, or
\item \csb{xinttheexpr}\meta{expandable\_expression}|\relax|\etype{x}, or
\item \csb{xintthe}|\xintexpr|\meta{expandable\_expression}|\relax|.\etype{x}
\end{itemize}
The computations are done \emph{exactly}, and with no simplification of the
result. See \csbxint{floatexpr} for a similar parser which rounds each
operation inside the expression to \csbxint{theDigits} digits of precision.
It is possible to wrap the whole expression (or only some portions) inside the
|\xintexpr...\relax| in one of the functions |round|, |trunc|, or |float|: in
|round| and |trunc| the second optional parameter is the number of digits of
the fractional part; in |float| it is the total number of digits of the
mantissa.
The |reduce| will reduce the fraction to smallest terms, or more precisely it
reduces to smallest terms the |A/B| part from its argument evaluating to
|A/B[N]|.
As an alternative and equivalent syntax to
\begin{everbatim}
\xintexpr round(<expression>, D)\relax
\end{everbatim}
there is\footnote{For truncation rather than rounding, one uses
|\xintexpr trunc(<expression>, D)\relax|.}
\begin{everbatim}
\xintiexpr [D] <expression> \relax
\end{everbatim}
The parameter |D| must be zero or positive.\footnote{Notice that |D=0|
corresponds to using |round(<expression>)| not |round(<expression>,0)| which
would leave a trailing dot. Same for |trunc|. There is also function |float|
for floating point rounding to \csbxint{theDigits} or the given number of
significant digits as second argument.} Perhaps some future version will
give a meaning to using a negative |D|.\footnote{Thanks to KT for this
suggestion. Sorry for the delay in implementing it... matter of formatting
the output and corresponding choice of user interface are still in need of
some additional thinking.}
\begin{itemize}
\item the expression may contain arbitrarily many levels of nested parenthesized
sub-expressions.
\item to let sub-contents evaluate as a sub-unit it should be either
\begin{enumerate}
\item parenthesized,
\item or a sub-expression |\xintexpr...\relax|.
\end{enumerate}
\item to either give an expression as argument to the other package macros,
or more generally to macros which expand their arguments, one must use the
|\xinttheexpr...\relax| or |\xintthe\xintexpr...\relax| forms. Similarly,
printing the result itself must be done with these forms.
\item one should not use |\xinttheexpr...\relax| as a sub-constituent of an
|\xintexpr...\relax| but\IMPORTANT{} only the
|\xintexpr...\relax| form which is more efficient in this context.
\item each \xintexprname{}ession, whether prefixed or not with |\xintthe|, is
completely expandable and obtains its result in two expansion steps.
\end{itemize}
\subsection{Expression syntax overview}
\label{ssec:syntax}
An expression is enclosed between either \csbxint{expr}, or \csbxint{iexpr},
or \csbxint{iiexpr}, or \csbxint{floatexpr}, or \csbxint{boolexpr} and a
\emph{mandatory} ending |\relax|. An expression may be a sub-unit of another
one.
Apart from \csbxint{floatexpr} the evaluations of algebraic operations are
\emph{exact}. The variant \csbxint{iiexpr} does not know fractions and is
provided for integer-only calculations. The variant \csbxint{iexpr} is exactly
like \csbxint{expr} except that it either rounds the final result to an
integer, or in case of an optional parameter |[d]|, rounds to a fixed point
number with |d| digits after decimal mark. The variant \csbxint{floatexpr}
does float calculations according to the current value of the precision set by
|\xintDigits|.
The whole expression should be prefixed by |\xintthe| when it is destined to
be printed on the typeset page, or given as argument to a macro (assuming this
macro systematically expands its argument). As a shortcut to
|\xintthe\xintexpr| there is |\xinttheexpr|. One gets used to not forget the
two |t|'s. Well I got used to it after three years of practice but as I am
generous, release |1.2h| now provides |\thexintexpr| etc... \CHANGED{1.2h}
|\xintexpr|-essions and |\xinttheexpr|-essions are completely expandable, in two steps.
\begin{itemize}[parsep=0pt, labelwidth=\leftmarginii,
itemindent=0pt, listparindent=\leftmarginiii, leftmargin=\leftmarginii]
\item An expression is built the standard way with opening and closing
parentheses, infix operators, and (big) numbers, with possibly a fractional
part, and/or scientific notation (except for \csbxint{iiexpr} which only
admits big integers). All variants work with comma separated expressions. On
output each comma will be followed by a space. A decimal number must have
digits either before or after the decimal mark.%\MyMarginNote{Changed!}
\item as everything gets expanded, the characters |.|, |+|, |-|, |*|, |/|, |^|,
|!|, |&|, \verb+|+, |?|, |:|, |<|, |>|, |=|, |(|, |)|, |"|, |]|, |[|, |@|
and the comma |,| should not (if used in the expression) be active. For
example, the French language in |Babel| system, for pdf\LaTeX, activates |!|,
|?|, |;| and |:|. Turn off the activity before the expressions.
Alternatively the command \csbxint{exprSafeCatcodes} resets all
characters potentially needed by \csbxint{expr} to their standard catcodes
and \csbxint{exprRestoreCatcodes} restores the status prevailing at the time
of the previous \csa{xintexprSafeCatcodes}.
\item The infix operators are |+|, |-|, |*|, |/|, |^| (or |**|) for exact or
floating point algebra (currently, only integer and half-integer
exponents are allowed for float power operations), |&&|
and \verb+||+ \footnote{with releases earlier than |1.1|, only single
character operators |&| and \verb+|+ were available, because the parser
did not handle multi-character operators. Their usage in this rôle is now
deprecated,\IMPORTANT{} as they may be assigned some new meaning in the
future.} for combining ``true'' (non zero) and ``false'' (zero)
conditions, as can be formed for example with the |=| (or |==|), |<|, |>|,
|<=|, |>=|, |!=| comparison operators.
\item The |!| is either a
function (the logical not) requiring an argument within parentheses, or a
post-fix operator which does the factorial. In \csbxint{floatexpr} it is
mapped to \csbxint{FloatFac}, else it computes the exact factorial.
\item The |?| may serve either as a function (the truth value) requiring an
argument within parentheses, or as two-way post-fix branching operator
|(cond)?{YES}{NO}|. The false branch will \emph{not} be evaluated. The input
|(cond)?{?}{!}(x)| will confuse the parser as it will think to have found
the |??| branching operator. But |(cond)?{?(x)}{!(x)}| or even
|(cond)?{?(}{!(}x)| are ok.
\item There is also |??| which branches according to the scheme
|(x)??{<0}{=0}{>0}|. The wrong branches are not evaluated.
\item Comma separated lists may be generated with |a..b| and |a..[d]..b| and
they may be manipulated to some extent once put into bracket. See
\autoref{ssec:lists}. There is no real concept of a list object, nor list
operations, although itemwise manipulation are possible. There is no notion
of an ``nuple'' object. The variable |nil| is reserved, it represents an
empty list.
\item Count registers and |\numexpr|-essions are accepted (LaTeX{}'s counters
can be inserted using |\value|) natively without |\the| or |\number| as
prefix. Also dimen registers and control sequences, skip registers and
control sequences (\LaTeX{}'s lengths), |\dimexpr|-essions,
|\glueexpr|-essions are automatically unpacked using |\number|, discarding
the stretch and shrink components and giving the dimension value in |sp|
units ($1/65536$th of a \TeX{} point). Furthermore, tacit multiplication is
implied, when the (count or dimen or glue) register or variable, or the
(|\numexpr| or |\dimexpr| or |\glueexpr|) expression is immediately prefixed
by a (decimal) number.
\item See \autoref{ssec:tacit multiplication} for the complete rules
of tacit multiplication.\IMPORTANT
\item With a macro |\x| defined like this:
%
\leftedline{|\def\x {\xintexpr \a + \b \relax}| or |\edef\x {\xintexpr
\a+\b\relax}|}
%
one may then do |\xintthe\x|, either for printing the result on the page or
to use it in some other macros expanding their arguments. The |\edef| does
the computation immediately but keeps it in an internal private format.
Naturally, the |\edef| is only possible if |\a| and |\b| are already
defined. With both approaches the |\x| can be inserted in other expressions,
as for example (assuming naturally as we use an |\edef| that in the
`yet-to-be computed' case the |\a| and |\b| now have some suitable meaning):
%
\leftedline {|\edef\y {\xintexpr \x^3\relax}|}
\item There is also \csbxint{boolexpr}| ... \relax| and
\csbxint{theboolexpr}| ... \relax|. Same as |\xintexpr| with the final
result converted to $1$ if it is not zero. See also
\csbxint{ifboolexpr} (\autoref{xintifboolexpr}) and the
\hyperlink{item:bool}{discussion} of the |bool| and |togl| functions
in \autoref{sec:expr}. Here is an example:
\catcode`| 12 %
\begin{everbatim*}
\xintNewBoolExpr \AssertionA[3]{ #1 && (#2|#3) }
\xintNewBoolExpr \AssertionB[3]{ #1 || (#2) }
\xintNewBoolExpr \AssertionC[3]{ xor(#1,#2,#3) }
{\centering\normalcolor\xintFor #1 in {0,1} \do {%
\xintFor #2 in {0,1} \do {%
\xintFor #3 in {0,1} \do {%
#1 AND (#2 OR #3) is \textcolor[named]{OrangeRed}{\AssertionA {#1}{#2}{#3}}\hfil
#1 OR (#2 AND #3) is \textcolor[named]{OrangeRed}{\AssertionB {#1}{#2}{#3}}\hfil
#1 XOR #2 XOR #3 is \textcolor[named]{OrangeRed}{\AssertionC {#1}{#2}{#3}}\\}}}}
\end{everbatim*}\catcode`| 13
This example used for efficiency \csbxint{NewBoolExpr}. See also the
\autoref{xintNewExpr}.
\item There is \csbxint{floatexpr}| ... \relax| where the algebra is done
in floating point approximation (also for each intermediate result). Use the
syntax |\xintDigits:=N;| to set the precision. Default: $16$ digits.
%
\leftedline{|\xintthefloatexpr 2^100000\relax:| \dtt{\xintthefloatexpr
2^100000\relax }}
%
The square-root operation can be used in |\xintexpr|, it is computed
as a float with the precision set by |\xintDigits| or by the optional
second argument:
%
\begin{everbatim*}
\xinttheexpr sqrt(2,60)\relax
Here the [60] is to avoid truncation to |\xinttheDigits| of precision on output.
\printnumber{\xintthefloatexpr [60] sqrt(2,60)\relax}
\end{everbatim*}
Floats are quickly indispensable when using the power function , as exact
results will easily have hundreds, if not thousands, of digits.
%
\begin{everbatim*}
\xintDigits:=48;\xintthefloatexpr 2^100000\relax
\end{everbatim*}
Only integer and half-integer exponents are allowed.
\item Hexadecimal \TeX{} number denotations (\emph{i.e.}, with a |"| prefix)
are recognized by the |\xintexpr| parser and its variants. \fbox{This
requires \xintbinhexname}. Except in |\xintiiexpr|, a (possibly empty)
fractional part with the dot |.| as ``hexadecimal'' mark is allowed.
%
\leftedline{|\xinttheexpr "FEDCBA9876543210\relax|$\to$\dtt{\xinttheexpr
"FEDCBA9876543210\relax}}
%
\leftedline{|\xinttheiexpr
16^5-("F75DE.0A8B9+"8A21.F5746+16^-5)\relax|$\to$\dtt{\xinttheiexpr
16^5-("F75DE.0A8B9+"8A21.F5746+16^-5)\relax}}
%
Letters must be uppercased, as with standard \TeX{} hexadecimal
denotations.
\item |2^-10| is perfectly accepted input, no need for parentheses; and
operators of power |^|, division |/|, and subtraction |-| are all
left-associative: |2^4^8| is evaluated as |(2^4)^8|. The minus sign as
prefix has various precedence levels: |\xintexpr -3-4*-5^-7\relax| evaluates
as |(-3)-(4*(-(5^(-7))))| and |-3^-4*-5-7| as |(-((3^(-4))*(-5)))-7|.
An exception to left associativity is applied in case of tacit
multiplication |x/2y| is interpreted as |x/(2y)| and
|(1+2)/(3+4)(5+6)| is computed as |(1+2)/((3+4)*(5+6))|. See
\autoref{ssec:tacit multiplication}.
\item if one uses \emph{macros} within |\xintexpr..\relax| one should
obviously take into account that the parser will \emph{not} see the macro
arguments. This applies also to macros defined via \csbxint{NewExpr}.
Functions declared with \csbxint{deffunc} on the other hand behave exactly
like the native functions of the package.
\end{itemize}
\subsection{More examples with dummy variables}
\label{ssec:moredummies}
These examples were first added to this manual at the time of the |1.1|
release (|2014/10/29|).
\begin{everbatim*}
Prime numbers are always cool
\xinttheiiexpr seq((seq((subs((x/:m)?{(m*m>x)?{1}{0}}{-1},m=2n+1))
??{break(0)}{omit}{break(1)},n=1++))?{x}{omit},
x=10001..[2]..10200)\relax
\end{everbatim*}
The syntax in this last example may look a bit involved. First |x/:m| computes
|x modulo m| (this is the modulo with respect to truncated division, which
here for positive arguments is like Euclidean division; in
|\xintexpr...\relax|, |a/:b| is such that |a = b*(a//b)+a/:b|, with |a//b| the
algebraic quotient |a/b| truncated to an integer.). The |(x)?{yes}{no}|
construct checks if |x| (which \emph{must} be within parentheses) is true or
false, i.e. non zero or zero. It then executes either the |yes| or the |no|
branch, the non chosen branch is \emph{not} evaluated. Thus if |m| divides |x|
we are in the second (``false'') branch. This gives a |-1|. This |-1| is the
argument to a |??| branch which is of the type |(y)??{y<0}{y=0}{y>0}|, thus here
the |y<0|, i.e., |break(0)| is chosen. This |0| is thus given to another |?|
which consequently chooses |omit|, hence the number is not kept in the list.
The numbers which survive are the prime numbers.
\begin{everbatim*}
The first Fibonacci number beyond |2^64| bound is
\xinttheiiexpr subs(iterr(0,1;(@1>N)?{break(i)}{@1+@2},i=1++),N=2^64)\relax{}
and the previous number was its index.
\end{everbatim*}
% A006877 In the `3x+1' problem, these values for the starting value set new
% records for number of steps to reach 1. (Formerly M0748) 14 1, 2, 3, 6, 7,
% 9, 18, 25, 27, 54, 73, 97, 129, 171, 231, 313, 327, 649, 703, 871, 1161,
% 2223, 2463, 2919, 3711, 6171, 10971, 13255, 17647, 23529, 26623, 34239,
% 35655, 52527, 77031, 106239, 142587, 156159, 216367, 230631, 410011, 511935,
% 626331, 837799
One more recursion:
\begin{everbatim*}
\def\syr #1{\xinttheiiexpr rseq(#1; (@<=1)?{break(i)}{odd(@)?{3@+1}{@//2}},i=0++)\relax}
The 3x+1 problem: \syr{231}\par
\end{everbatim*}
OK, a final one:
\begin{everbatim*}
\def\syrMax #1{\xinttheiiexpr iterr(#1,#1;even(i)?
{(@2<=1)?{break(i/2)}{odd(@2)?{3@2+1}{@2//2}}}
{(@1>@2)?{@1}{@2}},i=0++)\relax }
With initial value 1161, the maximal number attained is \syrMax{1161} and that latter
number is the number of steps which was needed to reach 1.\par
\end{everbatim*}
Well, one more:
\begin{everbatim*}
\newcommand\GCD [2]{\xinttheiiexpr rrseq(#1,#2; (@1=0)?{abort}{@2/:@1}, i=1++)\relax }
\GCD {13^10*17^5*29^5}{2^5*3^6*17^2}
\end{everbatim*}
and the ultimate:
\begin{everbatim*}
\newcommand\Factors [1]{\xinttheiiexpr
subs(seq((i/:3=1)?{omit}{[L][i]},i=0..len(L)-1),
L=rseq(#1;(p^2>[@][0])?{([@][0]>1)?{break(1,[@][0],1)}{abort}}
{(([@][0])/:p)?{omit}
{iter(([@][0])//p; (@/:p)?{break(@,p,e)}{@//p},e=1++)}},p=2++))\relax }
\Factors {41^4*59^2*29^3*13^5*17^8*29^2*59^4*37^6}
\end{everbatim*}
This might look a bit scary, I admit.%
%
\footnote{Look at the
\hyperlink{BrentSalamin}{Brent-Salamin algorithm implementation} for a much
saner example.}
%
\xintexprname has minimal tools and
is obstinate about doing everything expandably! We are hampered by absence of a
notion of ``nuple''. The algorithm divides |N| by |2| until no more possible,
then by |3|, then by |4| (which is silly), then by |5|, then by |6| (silly
again), \dots.
The variable |L=rseq(#1;...)| expands, if one follows the steps, to a comma
separated list starting with the initial (evaluated) |N=#1| and then
pseudo-triplets where the first item is |N| trimmed of small primes, the
second item is the last prime divisor found, and the third item is its
exponent in original |N|.
The algorithm needs to keep handy the last computed quotient by prime powers,
hence all of them, but at the very end it will be cleaner to get rid of them
(this corresponds to the first line in the code above). This is achieved in a
cumbersome inefficient way; indeed each item extraction |[L][i]| is costly: it
is not like accessing an array stored in memory, due to expandability, nothing
can be stored in memory! Nevertheless, this step could be done here in a far
less inefficient manner if there was a variant of |seq| which, in the spirit
of \csbxint{iloopindex}, would know how many steps it had been through so far.
This is a feature to be added to |\xintexpr|! (as well as a |++| construct
allowing a non unit step).
Notice that in |iter(([@][0])//p;| the |@| refers to the previous triplet (or
in the first step to |N|), but the latter |@| showing up in |(@/:p)?| refers
to the previous value computed by |iter|.
\begin{snugframed}
Parentheses are essential in |..([y][0])| else the parser will see |..[| and
end up in ultimate confusion, and also in |([@][0])/:p| else the parser will
see the itemwise operator |]/| on lists and again be very confused (I could
implement a |]/:| on lists, but in this situation this would also be very
confusing to the parser.)
\end{snugframed}
For comparison, here is an \fexpan dable macro expanding to the same result,
but coded directly with the \xintname macros. Here |#1| can not be itself an
expression, naturally. But at least we let |\Factorize| \fexpan d its
argument.
\begin{everbatim}
\makeatletter
\newcommand\Factorize [1]
{\romannumeral0\expandafter\factorize\expandafter{\romannumeral-`0#1}}%
\newcommand\factorize [1]{\xintiiifOne{#1}{ 1}{\factors@a #1.{#1};}}%
\def\factors@a #1.{\xintiiifOdd{#1}
{\factors@c 3.#1.}%
{\expandafter\factors@b \expandafter1\expandafter.\romannumeral0\xinthalf{#1}.}}%
\def\factors@b #1.#2.{\xintiiifOne{#2}
{\factors@end {2, #1}}%
{\xintiiifOdd{#2}{\factors@c 3.#2.{2, #1}}%
{\expandafter\factors@b \the\numexpr #1+\@ne\expandafter.%
\romannumeral0\xinthalf{#2}.}}%
}%
\def\factors@c #1.#2.{%
\expandafter\factors@d\romannumeral0\xintiidivision {#2}{#1}{#1}{#2}%
}%
\def\factors@d #1#2#3#4{\xintiiifNotZero{#2}
{\xintiiifGt{#3}{#1}
{\factors@end {#4, 1}}% ultimate quotient is a prime with power 1
{\expandafter\factors@c\the\numexpr #3+\tw@.#4.}}%
{\factors@e 1.#3.#1.}%
}%
\def\factors@e #1.#2.#3.{\xintiiifOne{#3}
{\factors@end {#2, #1}}%
{\expandafter\factors@f\romannumeral0\xintiidivision {#3}{#2}{#1}{#2}{#3}}%
}%
\def\factors@f #1#2#3#4#5{\xintiiifNotZero{#2}
{\expandafter\factors@c\the\numexpr #4+\tw@.#5.{#4, #3}}%
{\expandafter\factors@e\the\numexpr #3+\@ne.#4.#1.}%
}%
\def\factors@end #1;{\xintlistwithsep{, }{\xintRevWithBraces {#1}}}%
\makeatother
\end{everbatim}
The macro |\Factorize| puts a little stress on the input save stack in order
not be bothered with previously gathered things. I timed it to be about seven
times faster than |\Factors| in test cases such as
|16246355912554185673266068721806243461403654781833| and others. Among the
various things explaining the speed-up, there is fact that we step by
increments of two, not one, and also that we divide only once, obtaining
quotient and remainder in one go. These two things already make for a speed-up
factor of about four. Thus, our earlier |\Factors| was not completely
inefficient, and was quite easier to come up with than
|\Factorize|.\footnote{2015/11/18 I have not revisited this code for a long
time, and perhaps I could improve it now with some new techniques.}
If we only considered small integers, we could write pure |\numexpr| methods
which would be very much faster (especially if we had a table of small primes
prepared first) but still ridiculously slow compared to any non expandable
implementation, not to mention use of programming languages directly accessing
the CPU registers\dots
\subsection{The \csbh{xintthecoords} command}
\label{xintthecoords}
It converts a comma separated list into the format for list of coordinates as
expected by the |TikZ| |coordinates| syntax. The code had to work around the
problem that |TikZ| seemingly allows only a maximal number of about one
hundred expansion steps for the list to be entirely produced. Presumably to
catch an infinite loop, but one hundred is ridiculously low a number of
expansion steps for any serious work in \TeX{} for dealing with tokens.
\begin{everbatim*}
{\centering\begin{tikzpicture}[scale=10]\xintDigits:=8;
\clip (-1.1,-.25) rectangle (.3,.25);
\draw [blue] (-1.1,0)--(1,0);
\draw [blue] (0,-1)--(0,+1);
\draw [red] plot[smooth] coordinates {\xintthecoords
% converts into (x1, y1) (x2, y2)... format
\xintfloatexpr seq((x^2-1,mul(x-t,t=-1+[0..4]/2)),x=-1.2..[0.1]..+1.2) \relax };
\end{tikzpicture}\par }
\end{everbatim*}
% Notice: if x goes no take exactly value 1 or -1, the origin appears slightly
% off the curve, not MY fault!!!
\csbxint{thecoords} should be followed immediately by \csbxint{floatexpr} or
\csbxint{iexpr} or \csbxint{iiexpr}, but not |\xintthefloatexpr|, etc\dots
Besides, as |TikZ| will not understand the |A/B[N]| format which is used on
output by |\xintexpr|, |\xintexpr| is not really usable with |\xintthecoords|
for a |TikZ| picture, but one may use it on its own, and the reason for the
spaces in and between coordinate pairs is to allow if necessary to print on
the page for examination with about correct line-breaks.
\begin{everbatim*}
\edef\x{\xintthecoords \xintexpr rrseq(1/2,1/3; @1+@2, x=1..20)\relax }
\meaning\x +++
\end{everbatim*}
\subsection{\texorpdfstring{\texttt{\protect\string\numexpr}}{\textbackslash
numexpr} or \texorpdfstring{\texttt{\protect\string\dimexpr}}{\textbackslash
dimexpr} expressions, count and dimension registers and variables}
\label{ssec:countinexpr}
Count registers, count control sequences, dimen registers, dimen control
sequences (like |\parindent|), skips and skip control sequences, |\numexpr|,
|\dimexpr|, |\glueexpr|, |\fontdimen| can be inserted directly, they will be
unpacked using |\number| which gives the internal value in terms of scaled
points for the dimensional variables: $1$\,|pt|${}=65536$\,|sp| (stretch and
shrink components are thus discarded).
Tacit multiplication (see \autoref{ssec:tacit multiplication}) is implied,
when a number or decimal number prefixes such a register or control sequence.
\LaTeX{} lengths are skip control sequences and \LaTeX{} counters should be
inserted using |\value|.
Release |1.2| of the |\xintexpr| parser also recognizes and prefixes with
|\number| the |\ht|, |\dp|, and |\wd| \TeX{} primitives as well as the
|\fontcharht|, |\fontcharwd|, |\fontchardp| and |\fontcharic| \eTeX{}
primitives.
In the case of numbered registers like |\count255| or |\dimen0| (or |\ht0|),
the resulting digits will be re-parsed, so for example |\count255 0| is like
|100| if |\the\count255| would give |10|. The same happens with inputs such
as |\fontdimen6\font|. And |\numexpr 35+52\relax| will be exactly as if |87|
as been encountered by the parser, thus more digits may follow: |\numexpr
35+52\relax 000| is like |87000|. If a new |\numexpr| follows, it is treated
as what would happen when |\xintexpr| scans a number and finds a non-digit: it
does a tacit multiplication.
\begin{everbatim*}
\xinttheexpr \numexpr 351+877\relax\numexpr 1000-125\relax\relax{} is the same
as \xinttheexpr 1228*875\relax.
\end{everbatim*}
Control sequences however (such as |\parindent|) are picked up as a whole by
|\xintexpr|, and the numbers they define cannot be extended extra digits, a
syntax error is raised if the parser finds digits rather than a legal
operation after such a control sequence.
A token list variable must be prefixed by |\the|, it will not be unpacked
automatically (the parser will actually try |\number|, and thus fail). Do not
use |\the| but only |\number| with a dimen or skip, as the |\xintexpr| parser
doesn't understand |pt| and its presence is a syntax error. To use a dimension
expressed in terms of points or other \TeX{} recognized units, incorporate it in
|\dimexpr...\relax|.
Regarding how dimensional expressions are converted by \TeX{} into scaled points
see also \autoref{sec:Dimensions}.
\subsection{Catcodes and spaces}
Active characters may (and will) break the functioning of \csbxint{expr}.
Inside an expression one may prefix, for example a |:| with |\string|. Or, for
a more radical way, there is \csbxint{exprSafeCatcodes}. This is a
non-expandable step as it changes catcodes.
\subsubsection{\csbh{xintexprSafeCatcodes}}
\label{xintexprSafeCatcodes}
This command sets the catcodes of the relevant characters to safe values. This
is used internally by \csbxint{NewExpr} (restoring the catcodes on exit),
hence \csa{xintNewExpr} does not have to be protected against active
characters.
Attention however that if the whole
\begin{everbatim}
\xintNewExpr \foo [N] {<expression with #1,...>}
\end{everbatim}
has been fetched as a macro argument, it will be too late then for
\csa{xintNewExpr} to sanitize the catcodes of the (active) characters within
the expression.
\subsubsection{\csbh{xintexprRestoreCatcodes}}
\label{xintexprRestoreCatcodes}
Restores the catcodes to the earlier state.
\bigskip
Spaces inside an |\xinttheexpr...\relax| should mostly be
innocuous (except inside macro arguments).
|\xintexpr| and |\xinttheexpr| are for the most part agnostic regarding
catcodes: (unbraced) digits, binary operators, minus and plus signs as
prefixes, dot as decimal mark, parentheses, may be indifferently of catcode
letter or other or subscript or superscript, ..., it doesn't matter.%
%
\footnote{Furthermore, although \csbxint{expr} uses \csa{string}, it is
escape-char agnostic. It should work with any \csa{escapechar} setting
including -1.}
The characters |+|, |-|, |*|, |/|, |^|, |!|, |&|, \verb+|+, |?|, |:|, |<|, |>|,
|=|, |(|, |)|, |"|, |[|, |]|, |;|, the dot and the comma should not be active if
in the expression, as everything is expanded along the way. If one of them is
active, it should be prefixed with |\string|.
The exclamation mark |!| should have its standard catcode: with catcode letter
it is used internally and hence will confuse the parsers if it comes from the
expression.
Digits, slash, square brackets, minus sign, in the output from an
|\xinttheexpr| are all of catcode 12. For |\xintthefloatexpr| the `e' in the
output has its standard catcode ``letter''.
A macro with arguments will expand and grab its arguments before the
parser may get a chance to see them, so the situation with catcodes and spaces
is not the same within such macro arguments.
\subsection{Expandability, \csh{xinteval}}
As is the case with all other package macros |\xintexpr| \fexpan ds (in two
steps) to its final (non-printable) result; and |\xinttheexpr| \fexpan ds (in
two steps) to the chain of digits (and possibly minus sign |-|, decimal mark
|.|, fraction slash |/|, scientific |e|, square brackets |[|, |]|) representing
the result.
Starting with |1.09j|, an |\xintexpr..\relax| can be inserted without
|\xintthe| prefix inside an |\edef|, or a |\write|. It expands to a private
more compact representation (five tokens) than |\xinttheexpr| or
|\xintthe\xintexpr|.
The material between |\xintexpr| and |\relax| should contain only expandable
material.
The once expanded |\xintexpr| is |\romannumeral0\xinteval|. And there is
similarly |\xintieval|, |\xintiieval|, and |\xintfloateval|. For the other
cases one can use |\romannumeral-`0| as prefix. For an example of expandable
algorithms making use of chains of |\xinteval|-uations connected via
|\expandafter| see \autoref{ssec:fibonacci}.
An expression can only be legally finished by a |\relax| token, which
will be absorbed.
It is quite possible to nest expressions among themselves; for example, if one
needs inside an |\xintiiexpr...\relax| to do some computations with fractions,
rounding the final result to an integer, one just has to insert
|\xintiexpr...\relax|. The functioning of the infix operators will not be in
the least affected from the fact that the surrounding ``environment'' is the
|\xintiiexpr| one.
\subsection{Memory considerations}
The parser creates an undefined control sequence for each intermediate
computation evaluation: addition, subtraction, etc\dots Thus, a moderately sized
expression might create 10, or 20 such control sequences. On my \TeX{}
installation, the memory available for such things is of circa \np{200000}
multi-letter control words. So this means that a document containing hundreds,
perhaps even thousands of expressions will compile with no problem.
Besides the hash table, also \TeX{} main memory is impacted. Thus, if
\xintexprname is used for computing plots%
%
\footnote{this is not very probable as so far \xintname does not include
a mathematical library with floating point calculations, but provides
only the basic operations of algebra.}%
%
, this may cause a problem. In my testing and with current |TL2015| memory
settings, I ran into problems after doing about \emph{ten thousand}
evaluations (for example |(#1+#2)*#3-#1*#3-#2*#3)|) each with number having
\emph{hundreds} of digits. Typical error message can be:
\begin{everbatim}
./testaleatoires.tex:243: TeX capacity exceeded, sorry [pool size=6134970].
<argument> ...19140037877484848545931233090884903
\end{everbatim}
There is a (partial) solution.%
%
\footnote{which convinced me that I could stick with the parser
implementation despite its potential impact on the hash-table and
other parts of \TeX{}'s memory.}
A document can possibly do tens of thousands of evaluations only if some
identical formulae are being used repeatedly, with varying arguments (from
previous computations possibly) or coming from data being fetched from a file.
Most certainly, there will be a a few dozens formulae at most, but they will
be used again and again with varying inputs.
With the \csbxint{NewExpr} command, it is possible to convert once and
for all an expression containing parameters into an expandable macro
with parameters. Only this initial definition of this macro actually
activates the \csbxint{expr} parser and will (very moderately) impact
the hash-table: once this unique parsing is done, a macro with
parameters is produced which is built-up recursively from the
\csbxint{Add}, \csbxint{Mul}, etc... macros, exactly as it would be
necessary to do without the facilities of the \xintexprname package.
Notice that since |1.2c| the \csbxint{deffunc} construct allows an alternative
to \csa{xintNewExpr} whose syntax uses arbitrary letters rather than macro
parameters |#1|, |#2|, .... The declared function must still be used inside an
expression, thus the |\csname...\endcsname| problem is not completely
eliminated, but the computation it realizes will need only as many |\csname|'s
as there are arguments to the function and will create only one more to store
the result of the evaluation.
\subsection{The \csbh{xintNewExpr} command}
\label{xintNewExpr}
The command is used as:
%
\leftedline{|\xintNewExpr{\myformula}[n]|\marg{stuff}, where}
\begin{itemize}
\item \meta{stuff} will be inserted inside |\xinttheexpr . . . \relax|,
\item |n| is an integer between zero and nine, inclusive, which is the number
of parameters of |\myformula|,
\item the placeholders |#1|, |#2|, ..., |#n| are used inside \meta{stuff} in
their usual r\^ole,%
%
\catcode`# 12
\footnote{if \csa{xintNewExpr} is used inside a macro,
the |#|'s must be doubled as usual.}
\footnote{the |#|'s will in pratice have their usual
catcode, but category code other |#|'s are accepted too.}
\catcode`# 6
%
\item the |[n]| is \emph{mandatory}, even for |n=0|.%
\footnote{there is some use for \csa{xintNewExpr}|[0]| compared to an
\csa{edef} as \csa{xintNewExpr} has some built-in catcode protection.}
\item the macro |\myformula| is defined without checking if it already exists,
\LaTeX{} users might prefer to do first |\newcommand*\myformula {}| to get a
reasonable error message in case |\myformula| already exists,
\item the protection against active characters is done automatically (as long
as the whole thing has not already been fetched as a macro argument and
the catcodes correspondingly already frozen).
\end{itemize}
It will be a completely expandable macro entirely built-up using |\xintAdd|,
|\xintSub|, |\xintMul|, |\xintDiv|, |\xintPow|, etc\dots as corresponds to the
expression written with the infix operators.
Macros created by |\xintNewExpr| can thus be nested.
\begin{everbatim*}
\xintNewFloatExpr \FA [2]{(#1+#2)^10}
\xintNewFloatExpr \FB [2]{sqrt(#1*#2)}
\begin{enumerate}[nosep]
\item \FA {5}{5}
\item \FB {30}{10}
\item \FA {\FB {30}{10}}{\FB {40}{20}}
\end{enumerate}
\end{everbatim*}
The use of \csbxint{NewExpr} circumvents the impact of the |\xintexpr|
parsers on \TeX's memory: it is useful if one has a formula which has to be
re-evaluated thousands of times with distinct inputs each with dozens, or
hundreds of digits.
A ``formula'' created by |\xintNewExpr| is thus a macro whose parameters are
given to a possibly very complicated combination of the various macros of
\xintname and \xintfracname. Consequently, one can not use at all any infix
notation in the inputs, but only the formats which are recognized by the
\xintfracname macros.
This is thus quite different from a macro with parameters which one would
have defined via a simple |\def| or |\newcommand| as for example:
%
\leftedline{|\newcommand\myformula [1]{\xinttheexpr (#1)^3\relax}|}
%
Such a macro |\myformula|, if it was used tens of thousands of times with
various big inputs would end up populating large parts of \TeX's memory. It
would thus be better for such use cases to go for:
%
\leftedline{|\xintNewExpr\myformula [1]{#1^3\relax}|}
%
Here naturally the situation is over-simplified and it would be even simpler
to go directly for the use of the macro |\xintPow| or |\xintPower|.
|\xintNewExpr| tries to do as many evaluations as are possible at the time the
macro parameters are still parameters. Let's see a few examples. For this I
will use |\meaning| which reveals the contents of a macro.
\begin{enumerate}
\item the examples use a mysterious |\fixmeaning| macro, which is there to get
in the display |\romannumeral`^^@| rather than the frankly cabalistic
|\romannumeral``| which made the admiration of the readers of the
documentation dated |2015/10/19| (the second |`| stood for an ascii code
zero token as per |T1| encoded |newtxtt| font). Thus the true meaning is
``fixed'' to display something different which is how the macro could be
defined in a standard |tex| source file (modulo, as one can see in example,
the use of characters such as |:| as letters in control sequence names).
Prior to |1.2a|, the meaning would have started with a more mundane
|\romannumeral-`0|, but I decided at the time of releasing |1.2a| to imitate
the serious guys and switch for the more hacky yet |\romannumeral`^^@|
everywhere in the source code (not only in the macros produced by
\csbxint{NewExpr}), or to be more precise for an equivalent as the caret has
catcode letter in \xintname's source code, and I had to use another
character.
\item the meaning reveals the use of some private macros from the \xintname
bundle, which should not be directly used. If the things look a bit
complicated, it is because they have to cater for many possibilities.
\item the point of showing the meaning is also to see what has already been
evaluated in the construction of the macros.
\end{enumerate}
\begin{everbatim*}
\xintNewIIExpr\FA [1]{13*25*78*#1+2826*292}\fixmeaning\FA
\end{everbatim*}
\smallskip
\begin{everbatim*}
\xintNewIExpr\FA [2]{(3/5*9/7*13/11*#1-#2)*3^7}
\printnumber{\fixmeaning\FA}
\end{everbatim*}
\smallskip
\begin{everbatim*}
% an example with optional parameter
\xintNewIExpr\FA [3]{[24] (#1+#2)/(#1-#2)^#3}
\printnumber{\fixmeaning\FA}
\end{everbatim*}
\smallskip
\begin{everbatim*}
\xintNewFloatExpr\FA [2]{[12] 3.1415^3*#1-#2^5}
\printnumber{\fixmeaning\FA}
\end{everbatim*}
\smallskip
\begin{everbatim*}
\xintNewExpr\DET[9]{ #1*#5*#9+#2*#6*#7+#3*#4*#8-#1*#6*#8-#2*#4*#9-#3*#5*#7 }
\printnumber{\fixmeaning\DET}
\end{everbatim*}
\unless\ifxetex
Notice that since |1.2c| it is perhaps more natural to do:
\begin{everbatim*}
% attention that «ad» would try to use non-existent variable "ad"
\xintdeffunc det2(a, b, c, d) := a*d - b*c ;
% This is impossible because we must use single letters :
% \xintdeffunc det3(x_11, x_12, x_13, x_21, x_22, x_23, x_31, x_32, x_33) :=
% x_11 * det2 (x_22, x_23, x_32, x_33) + x_21 * det2 (x_32, x_33, x_12, x_13)
% + x_31 * det2 (x_12, x_13, x_22, x_23);
\xintdeffunc det3 (a, b, c, u, v, w, x, y, z) := a*v*z + b*w*x + c*u*y - b*u*z - c*v*x - a*w*y ;
\xinttheexpr det3 (1,1,1,1,2,4,1,3,9), det3 (1,10,100,1,100,10000,1,1000,1000000),
90*900*990, reduce(det3 (1,1/2,1/3,1/2,1/3,1/4,1/3,1/4,1/5))\relax\newline
\xintdeffunc det3bis (a, b, c, u, v, w, x, y, z) :=
a*det2(v,w,y,z)-b*det2(u,w,x,z)+c*det2(u,v,x,y);
\pdfsetrandomseed 123456789 % xint.pdf should be predictable from xint.dtx !
\xinttheexpr subs(subs(subs(subs(subs(subs(subs(subs(subs(
% we use one extra pair of parentheses to hide the commas from the subs
(a, b, c, u, v, w, x, y, z, det3 (a, b, c, u, v, w, x, y, z),
det3bis (a, b, c, u, v, w, x, y, z)),
z=\pdfuniformdeviate 1000), y=\pdfuniformdeviate 1000), x=\pdfuniformdeviate 1000),
w=\pdfuniformdeviate 1000), v=\pdfuniformdeviate 1000), u=\pdfuniformdeviate 1000),
c=\pdfuniformdeviate 1000), b=\pdfuniformdeviate 1000), a=\pdfuniformdeviate 1000)\relax
\end{everbatim*}
The last computation with its nine nested |subs| can be coded more
economically (and efficiently), exploiting the fact that a single dummy
variable can expand to a whole list:
\begin{everbatim*}
\pdfsetrandomseed 123456789 % xint.pdf should be predictable from xint.dtx !
\xinttheexpr subs((L, det3(L), det3bis(L)), % parentheses used to hide the inner commas
L=\pdfuniformdeviate 1000, \pdfuniformdeviate 1000, \pdfuniformdeviate 1000,
\pdfuniformdeviate 1000, \pdfuniformdeviate 1000, \pdfuniformdeviate 1000,
\pdfuniformdeviate 1000, \pdfuniformdeviate 1000, \pdfuniformdeviate 1000)\relax
\end{everbatim*}
\fi % de pas de xetex
With |\xintverbosetrue| we will find in the log:
\begin{everbatim}
Function det3 for \xintexpr parser associated to \XINT_expr_userfunc_det3 w
ith meaning macro:#1,#2,#3,#4,#5,#6,#7,#8,#9,->\xintSub {\xintSub {\xintSub {\x
intAdd {\xintAdd {\xintMul {\xintMul {#1}{#5}}{#9}}{\xintMul {\xintMul {#2}{#6}
}{#7}}}{\xintMul {\xintMul {#3}{#4}}{#8}}}{\xintMul {\xintMul {#2}{#4}}{#9}}}{\
xintMul {\xintMul {#3}{#5}}{#7}}}{\xintMul {\xintMul {#1}{#6}}{#8}}
Package xintexpr Info: (on line 11)
Function det3bis for \xintexpr parser associated to \XINT_expr_userfunc_det
3bis with meaning macro:#1,#2,#3,#4,#5,#6,#7,#8,#9,->\xintAdd {\xintSub {\xintM
ul {#1}{\xintSub {\xintMul {#5}{#9}}{\xintMul {#6}{#8}}}}{\xintMul {#2}{\xintSu
b {\xintMul {#4}{#9}}{\xintMul {#6}{#7}}}}}{\xintMul {#3}{\xintSub {\xintMul {#
4}{#8}}{\xintMul {#5}{#7}}}}
\end{everbatim}
\medskip
Lists, including Python-like selectors, are compatible with
\csa{xintNewExpr}:%
%
\footnote{The |\empty| token is optional here, but it would
be needed in case of \csbxint{NewFloatExpr} or \csbxint{NewIExpr}.}
%
\begin{everbatim*}
\xintNewExpr\Foo[5]{\empty[#1..[#2]..#3][#4:#5]}
\begin{itemize}[nosep]
\item |\Foo{1}{3}{90}{20}{30}|->\Foo{1}{3}{90}{20}{30}
\item |\Foo{1}{3}{90}{-40}{-15}|->\Foo{1}{3}{90}{-40}{-15}
\item |\Foo{1.234}{-0.123}{-10}{3}{7}|->\Foo{1.234}{-0.123}{-10}{3}{7}
\end{itemize}
\fdef\test {\Foo {0}{10}{100}{3}{6}}\meaning\test +++
\end{everbatim*}
In this last example the macro |\Foo| will not be able to handle an empty |#4|
or |#5|: this is only possible in an expression, because the parser identifies
|][:| or |:]| and handles them appropriately. During the construction of |\Foo|
the parser will find |][#4:| and not |][:|.
\begin{framed}
The \csbxint{deffunc}, \csbxint{defiifunc}, \csbxint{deffloatfunc}
declarators added to \xintexprname since release |1.2c| are based on the
same underlying mechanism as \csa{xintNewExpr}, \csa{xintNewIIExpr}, ... The
discussion that follows applies to them too.
\end{framed}
\subsubsection {Conditional operators and \csbh{NewExpr}}
\label{sssec:cond}
The |?| and |??| conditional operators cannot be parsed by |\xintNewExpr| when
they contain macro parameters |#1|,\dots, |#9| within their scope. However
replacing them with the functions |if| and, respectively |ifsgn|, the parsing
should succeed. And the created macro will \emph{not evaluate the branches to
be skipped}, thus behaving exactly like |?| and |??| would have in the
|\xintexpr|.
\begin{everbatim*}
\xintNewExpr\Formula [3]{ if((#1>#2) && (#2>#3), sqrt(#1-#2)*sqrt(#2-#3), #1^2+#3/#2) }%
\printnumber{\fixmeaning\Formula }
\end{everbatim*}
This formula (with its |\xintiiifNotZero|) will gobble the false branch without
evaluating it when used with given arguments.
Remark: the meaning above reveals some of the private macros used by the
package. They are not for direct use.
Another example
\begin{everbatim*}
\xintNewExpr\myformula[3]{ ifsgn(#1,#2/#3,#2-#3,#2*#3) }%
\fixmeaning\myformula
\end{everbatim*}
Again, this macro gobbles the false branches, as would have the operator |??|
inside an |\xintexpr|-ession.
\subsubsection{External macros and \csbh{NewExpr}; the protect function}
\label{sssec:protect}
For macros within such a created \xintname-formula command, there
are two cases:
\begin{itemize}
\item the macro does not involve the numbered parameters in its arguments: it
may then be left as is, and will be evaluated once during the construction of
the formula,
\item it does involve at least one of the macro parameters as argument. Then:
\begin{snugframed}
the whole thing (macro + argument) should be |protect|-ed, not in the
\LaTeX{} sense (!), but in the following way: |protect(\macro {#1})|.\IMPORTANT
\end{snugframed}
\end{itemize}
Here is a silly example illustrating the general principle: the macros here have
equivalent functional forms which are more convenient; but some of the more
obscure package macros of \xintname dealing with integers do not have functions
pre-defined to be in correspondance with them, use this mechanism could be
applied to them.
\begin{everbatim*}
\xintNewExpr\formulaA[2]{protect(\xintRound{#1}{#2}) - protect(\xintTrunc{#1}{#2})}%
\printnumber{\fixmeaning\formulaA}
\xintNewIIExpr\formulaB [3]{rem(#1,quo(protect(\the\numexpr #2\relax),#3))}%
\noindent\printnumber{\fixmeaning\formulaB }
\end{everbatim*}
Only macros involving the |#1|, |#2|, etc\dots should be protected in this
way; the |+|, |*|, etc\dots symbols, the functions from the \csbxint{expr}
syntax, none should ever be included in a protected string.
\subsubsection{Limitations of \csbxint{NewExpr} and \csbxint{deffunc}}
\label{sssec:limitations}
\csa{xintNewExpr} will pre-evaluate everything as long as it does not contain
the macro parameters |#1|, |#2|, ... and the special measures to take when
these are inside branches to |?| and |??| (replace these operators by |if| and
|ifsgn|) or as arguments to macros external to \xintexprname (use |protect|)
were discussed in \autoref{sssec:cond} and \autoref{sssec:protect}.
The main remaining limitation is that expressions with dummy variables are
compatible with \csa{xintNewExpr} only to the extent that the iterated-over
list of values does not depend on the macro parameters |#1|, |#2|, ... For
example, this works:
\begin{everbatim*}
\xintNewExpr \FA [2] {reduce(add((t+#1)/(t+#2), t=0..5))}
\FA {1}{1}, \FA {1}{2}, \FA {2}{3}
\end{everbatim*}
but the |5| can not be abstracted into a third argument |#3|.
There are no restriction on using macro parameters |#1|, |#2|, ... with list
constructs. For example, this works:
\begin{everbatim*}
\xintNewIExpr \FB [3] {[4] `+`([1/3..[#1/3]..#2]*#3)}
\begin{itemize}[nosep]
\item \FB {1}{10/3}{100} % (1/3+2/3+...+10/3)*100
\item \FB {5}{5}{20} % (1/3+6/3+11/3)*20
\item \FB {3}{4}{1} % (1/3+4/3+7/3+10/3)*1
\end{itemize}
\end{everbatim*}
Some simple expressions with |add| or |mul| can be also expressed with |`+`|
and |`*`| and list operations. But there is no hope for |seq|, |iter|, etc...
if the |#1|, |#2|, ... are used inside the list argument:
|seq(x(x+#1)(x+#2),x=1..#3)| is currently not compatible with
\csa{xintNewExpr}. But |seq(x(x+#1)(x+#2), x=1..10)| has no problem.
All the preceeding applies identically for \csbxint{deffunc}, \csbxint{defiifunc},
\csbxint{deffloatfunc} which share the same routines as \csa{xintNewExpr},
\csa{xintNewIIExpr}, ..., replacing the |#1|, |#2|, ... in the discussion by
the letters used as function arguments.
There is a final syntax restriction which however applies only to
\csa{xintNewExpr} et. al., and not to \csa{xintdeffunc}, \csa{xintdefiifunc},
\csa{xintdeffloatfunc} : it is possible to use sub-expressions only if they use
\csa{xintexpr}, those with \csa{xinttheexpr} are illegal.
\begin{everbatim*}
\xintNewExpr \FC [4] {#1+\xintexpr #2*#3\relax + #4}
\printnumber{\fixmeaning\FC}
\end{everbatim*}\newline
works, but already
\begin{everbatim}
\xintNewExpr \FD [1] {#1+\xinttheexpr 1\relax}
\end{everbatim}
doesn't. On the other hand
\begin{everbatim*}
\xintdeffunc FD(t) := t + \xinttheexpr 1\relax ;
\end{everbatim*}
and even
\begin{everbatim*}
\xintdeffunc FE(t,u) := t + \xinttheexpr u\relax ;
\end{everbatim*}
have no issue. Anyway, one should never use |\xinttheexpr| for sub-expressions
but only |\xintexpr|, so this restriction on the \csa{xintNewExpr} syntax
isn't really one.
\subsection{The \csbh{xintNewFunction} command}
See \autoref{xintNewFunction} for its documentation.\NewWith{1.2h}
\subsection{\csbh{xintiexpr}, \csbh{xinttheiexpr}}
\label{xintiexpr}\label{xinttheiexpr}\label{thexintiexpr}
Equivalent\etype{x} to doing |\xintexpr round(...)\relax| (more precisely,
|round| is applied to each one of the evaluated values, if the expression was
comma separated). Thus, only the \emph{final result value} is rounded to an
integer. Half integers are rounded towards $+\infty$ for positive numbers and
towards $-\infty$ for negative ones.
An optional parameter |d>0| within brackets, immediately after |\xintiexpr|
is allowed: it instructs the expression to do its final rounding to the
nearest value with that many digits after the decimal mark, \emph{i.e.},
|\xintiexpr [d] <expression>\relax| is equivalent (in case of a single
expression) to |\xintexpr round(<expression>, d)\relax|.
|\xintiexpr [0] ...| is the same as |\xintiexpr ...|.\footnote{Incidentally
using |round(...,0)| in place of |round(...)| in |\xintexpr| would leave a
trailing dot in the produced value.}
If truncation rather than rounding is needed use (in case of a single
expression, naturally) |\xintexpr trunc(...)\relax| for truncation to an
integer or |\xintexpr trunc(...,d)\relax| for truncation to a decimal number
with |d>0| digits after the decimal mark.
Perhaps in the future some meaning will be given to using negative value for
the optional parameter |d|.\footnote{Thanks to KT for this suggestion.}
|\thexintiexpr| is synonym to |\xinttheiexpr|.\NewWith{1.2h}
\subsection{\csbh{xintiiexpr}, \csbh{xinttheiiexpr}}
\label{xintiiexpr}\label{xinttheiiexpr}\label{thexintiiexpr}
This variant\etype{x} does not know fractions. It deals almost only with long
integers. Comma separated lists of expressions are allowed.
\begin{framed}
It maps |/| to the \emph{rounded} quotient. The operator
|//| is, like in |\xintexpr...\relax|, mapped to \emph{truncated} division.
The euclidean quotient (which for positive operands is like the truncated
quotient) was, prior to release |1.1|, associated to |/|. The function
|quo(a,b)| can still be employed.
\end{framed}
The \csbxint{iiexpr}-essions use the `ii' macros for addition, subtraction,
multiplication, power, square, sums, products, euclidean quotient and
remainder.
The |round|, |trunc|, |floor|, |ceil| functions are still available, and are
about the only places where fractions can be used, but |/| within, if not
somehow hidden will be executed as integer rounded division. To avoid this one
can wrap the input in \dtt{qfrac}: this means however that none of the normal
expression parsing will be executed on the argument.
To understand the illustrative examples, recall that |round| and |trunc| have
a second (non negative) optional argument. In a normal \csbxint{expr}-essions,
|round| and |trunc| are mapped to \csbxint{Round} and \csbxint{Trunc}, in
\csbxint{iiexpr}-essions, they are mapped to \csbxint{iRound} and
\csbxint{iTrunc}.
\begin{everbatim*}
\xinttheiiexpr 5/3, round(5/3,3), trunc(5/3,3), trunc(\xintDiv {5}{3},3),
trunc(\xintRaw {5/3},3)\relax{} are problematic, but
%
\xinttheiiexpr 5/3, round(qfrac(5/3),3), trunc(qfrac(5/3),3), floor(qfrac(5/3)),
ceil(qfrac(5/3))\relax{} work!
\end{everbatim*}
On the other hand decimal numbers and scientific numbers can be used directly
as arguments to the |num|, |round|, or any function producing an integer.
\begin{framed}
Scientific numbers will be
represented with as many zeroes as necessary, thus one does not want to
insert \dtt{num(1e100000)} for example in an \csa{xintiiexpr}ession !
\end{framed}
%
\begin{everbatim*}
\xinttheiiexpr num(13.4567e3)+num(10000123e-3)\relax % should (num truncates) compute 13456+10000
\end{everbatim*}
%
The |reduce| function is not available and will raise un error. The |frac|
function also. The |sqrt| function is mapped to \csbxint{iiSqrt} which gives
a truncated square root. The |sqrtr| function is mapped to \csbxint{iiSqrtR}
which gives a rounded square root.
One can use the Float macros if one is careful to use |num|, or |round|
etc\dots on their output.
\begin{everbatim*}
\xinttheiiexpr \xintFloatSqrt [20]{2}, \xintFloatSqrt [20]{3}\relax % no operations
\noindent The next example requires the |round|, and one could not put the |+| inside it:
\xinttheiiexpr round(\xintFloatSqrt [20]{2},19)+round(\xintFloatSqrt [20]{3},19)\relax
(the second argument of |round| and |trunc| tells how many digits from after the
decimal mark one should keep.)
\end{everbatim*}
The whole point of \csbxint{iiexpr} is to gain some speed in
\emph{integer-only} algorithms, and the above explanations related to how to
nevertheless use fractions therein are a bit peripheral. We observed
(2013/12/18) of the order of $30$\% speed gain when dealing with numbers with
circa one hundred digits (1.2: this info may be obsolete).
|\thexintiiexpr| is synonym to |\xinttheiiexpr|.\NewWith{1.2h}
\subsection{\csbh{xintboolexpr},
\csbh{xinttheboolexpr}}
\label{xintboolexpr}\label{xinttheboolexpr}\label{thexintboolexpr}
Equivalent\etype{x} to doing |\xintexpr ...\relax| and returning $1$ if the
result does not vanish, and $0$ is the result is zero. As |\xintexpr|, this
can be used on comma separated lists of expressions, and will return a
comma separated list of $0$'s and $1$'s.
|\thexintboolexpr| is synonym to |\xinttheboolexpr|.\NewWith{1.2h}
\subsection{\csbh{xintfloatexpr},
\csbh{xintthefloatexpr}}
\label{xintfloatexpr}\label{xintthefloatexpr}\label{thexintfloatexpr}
\csbxint{floatexpr}|...\relax|\etype{x} is exactly like |\xintexpr...\relax|
but with the four binary operations and the power function are mapped to
\csa{xintFloatAdd}, \csa{xintFloatSub}, \csa{xintFloatMul}, \csa{xintFloatDiv}
and \csa{xintFloatPower}, respectively.\footnote{Since |1.2f| the \string^
handles half-integer exponents, contrarily to \csa{xintFloatPower}.}
The target precision for the computation is from the
current setting of |\xintDigits|. Comma separated lists of expressions are
allowed.
An optional (positive) parameter within brackets is allowed: the final float
will have that many digits of precision. This is provided to get rid of
possibly irrelevant last digits, thus makes sense only if this parameter is
less than the |\xinttheDigits| precision.
Since |1.2f| all float operations first round their arguments; a parsed number
is not rounded prior to its use as operand to such a float operation.
|\thexintfloatexpr| is synonym to |\xintthefloatexpr|.\NewWith{1.2h}
|\xintDigits:=36;|\xintDigits:=36;
%
\leftedline{|\xintthefloatexpr
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax|}
%
\leftedline{\dtt{\xintthefloatexpr
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax}}
% 0.00564487459334466559166166079096852897
%
\leftedline{|\xintthefloatexpr\xintexpr
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax\relax|}
%
\leftedline{\dtt{\xintthefloatexpr\xintexpr
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax\relax}}
\xintDigits := 16;
The latter is the rounding of the exact result. The former one has
its last three digits wrong due to the cumulative effect of rounding errors
in the intermediate computations, as compared to exact evaluations.
I recall here from \autoref{ssec:floatingpoint} that with release |1.2f| the
float macros for addition, subtraction, multiplication and division round
their arguments first to |P| significant places with |P| the asked-for
precision of the output;\CHANGED{1.2f} and similarly the power macros and the
square root macro. This does not modify anything for computations with
arguments having at most |P| significant places already.
\subsection{Using an expression parser within another one}
This was already illustrated before. In the following:
\begin{everbatim*}
\xintthefloatexpr \xintexpr add(1/i, i=1234..1243)\relax ^100\relax
\end{everbatim*},
the inner sum is computed exactly. Then it will be rounded to |\xinttheDigits|
significant digits, and then its power will be evaluated as a float operation.
One should avoid the "|\xintthe|" parsers in inner positions as this induces
digit by digit parsing of the inner computation result by the outer parser.
Here is the same computation done with floats all the way:
\begin{everbatim*}
\xintthefloatexpr add(1/i, i=1234..1243)^100\relax
\end{everbatim*}
Not surprisingly this differs from the previous one which was exact until
raising to the |100|th power.
The fact that the inner expression occurs inside a bigger one has nil
influence on its behaviour. There is the limitation though that the outputs
from \csbxint{expr} and \csbxint{floatexpr} can not be used directly in
\csbxint{theiiexpr} integer-only parser. But one can do:
\begin{everbatim*}
\xinttheiiexpr round(\xintfloatexpr 3.14^10\relax)\relax % or trunc
\end{everbatim*}
\subsection{\csbh{xintifboolexpr}}\label{xintifboolexpr}
\csh{xintifboolexpr}|{<expr>}{YES}{NO}|\etype{xnn} does |\xinttheexpr
<expr>\relax| and then executes the |YES| or the |NO| branch depending on
whether the outcome was non-zero or zero. |<expr>| can involve various |&| and
\verb+|+, parentheses, |all|, |any|, |xor|, the |bool| or |togl| operators, but
is not limited to them: the most general computation can be done, the test is on
whether the outcome of the computation vanishes or not.
Will not work on an expression composed of comma separated sub-expressions.
\subsection{\csbh{xintifboolfloatexpr}}\label{xintifboolfloatexpr}
\csh{xintifboolfloatexpr}|{<expr>}{YES}{NO}|\etype{xnn} does |\xintthefloatexpr
<expr>\relax| and then executes the |YES| or the |NO| branch depending on
whether the outcome was non zero or zero.
\subsection{\csbh{xintifbooliiexpr}}\label{xintifbooliiexpr}
\csh{xintifbooliiexpr}|{<expr>}{YES}{NO}|\etype{xnn} does |\xinttheiiexpr
<expr>\relax| and then executes the |YES| or the |NO| branch depending on
whether the outcome was non zero or zero.
\subsection{\csbh{xintNewFloatExpr}}\label{xintNewFloatExpr}
This is exactly like \csbxint{NewExpr} except that the created formulas are
set-up to use |\xintthefloatexpr|. The precision used for the computation will
be the one given by |\xinttheDigits| at the time of use of the created formulas.
However, the numbers hard-wired in the original expression will have been
evaluated with the then current setting for |\xintDigits|.
\begin{everbatim*}
\xintNewFloatExpr \f [1] {sqrt(#1)}
\f {2} (with \xinttheDigits{} of precision).
{\xintDigits := 32;\f {2} (with \xinttheDigits{} of precision).}
\xintNewFloatExpr \f [1] {sqrt(#1)*sqrt(2)}
\f {2} (with \xinttheDigits {} of precision).
{\xintDigits := 32;\f {2} (?? we thought we had a higher precision. Explanation next)}
The sqrt(2) in the second formula was computed with only \xinttheDigits{} of
precision. Setting |\xinttheDigits| to a higher value at the time of definition will
confirm that the result above is from a mismatch of the precision for |sqrt(2)| at
the time of its evaluation and the precision for the new |sqrt(2)| with |#1=2| at
the time of use.
{\xintDigits := 32;\xintNewFloatExpr \f [1] {sqrt(#1)*sqrt(2)}
\f {2} (with \xinttheDigits {} of precision)}
\end{everbatim*}
\subsection{\csbh{xintNewIExpr}}\label{xintNewIExpr}
Like \csbxint{NewExpr} but using |\xinttheiexpr|.
\subsection{\csbh{xintNewIIExpr}}\label{xintNewIIExpr}
Like \csbxint{NewExpr} but using |\xinttheiiexpr|.
\subsection{\csbh{xintNewBoolExpr}}\label{xintNewBoolExpr}
Like \csbxint{NewExpr} but using |\xinttheboolexpr|.
\xintDigits:= 16;
\subsection{Technicalities}
As already mentioned \csa{xintNewExpr}|\myformula[n]| does not check the prior
existence of a macro |\myformula|. And the number of parameters |n| given as
mandatory argument within square brackets should be (at least) equal
to the number of parameters in the expression.
Obviously I should mention that \csa{xintNewExpr} itself can not be used in an
expansion-only context, as it creates a macro.
The |\escapechar| setting may be arbitrary when using |\xintexpr|.
The format of the output of
|\xintexpr|\meta{stuff}|\relax| is a |!| (with catcode 11) followed by various things:
\begin{everbatim*}
\edef\f {\xintexpr 1.23^10\relax }\meaning\f
\end{everbatim*}
\begin{framed}
Note that |\xintexpr| expands in an |\edef|, contrarily
to |\numexpr| which is non-expandable, if not prefixed by |\the|, |\number|,
or |\romannumeral| or in some other context where \TeX{} is building a number. See
\autoref{ssec:fibonacci} for some illustration.
\end{framed}
I decided to put all intermediate results (from each evaluation of an infix
operators, or of a parenthesized subpart of the expression, or from application
of the minus as prefix, or of the exclamation sign as postfix, or any
encountered braced material) inside |\csname...\endcsname|, as this can be done
expandably and encapsulates an arbitrarily long fraction in a single token (left
with undefined meaning), thus providing tremendous relief to the programmer in
his/her expansion control.
\begin{framed}
As the |\xintexpr| computations corresponding to functions and infix
or postfix operators are done inside |\csname...\endcsname|, the
\fexpan dability could possibly be dropped and one could imagine
implementing the basic operations with expandable but not \fexpan
dable macros (as \csbxint{XTrunc}.) I have not investigated that
possibility.
\end{framed}
Syntax errors in the input such as using a one-argument function with two
arguments will generate low-level \TeX{} processing unrecoverable errors, with
cryptic accompanying message.
Some other problems will give rise to `error messages' macros giving some
indication on the location and nature of the problem. Mainly, an attempt has
been made to handle gracefully missing or extraneous parentheses.
However, this mechanism is completely inoperant for parentheses involved in
the syntax of the |seq|, |add|, |mul|, |subs|, |rseq| and |rrseq| functions,
and missing parentheses may cause the parser to fetch tokens beyond the ending
|\relax| necessarily ending up in cryptic low-level \TeX-errors.
Note that the |,<letter>=| part must be visible, it can not arise from
expansion (the equal sign does not have to be an equal sign, it can be any
token and will be gobbled).\IMPORTANT{} However for |iter|, |iterr|, |rseq|,
|rrseq|, the initial values delimited by a |;| are parsed in the normal way,
and in particular may be braced or arise from expansion. This is useful as the
|;| may be hidden from \csa{xintdeffunc} as |{;}| for example. Again, this
remark does \emph{not} apply to the comma |,| which precedes the |<letter>=|
part. The comma will be fetched by delimited macros and must be there. Nesting
is handled by checking (again using suitable delimited macros) that
parentheses are suitably balanced.
Note that |\relax| is \emph{mandatory} (contrarily to the situation for |\numexpr|).
\subsection{Acknowledgements (2013/05/25)}
I was greatly helped in my preparatory thinking, prior to producing such an
expandable parser, by the commented source of the
\href{http://www.ctan.org/pkg/l3kernel}{l3fp} package, specifically the
|l3fp-parse.dtx| file (in the version of April-May 2013; I think there was in
particular a text called ``roadmap'' which was helpful). Also the source of the
|calc| package was instructive, despite the fact that here for |\xintexpr| the
principles are necessarily different due to the aim of achieving expandability.
\clearpage
\section{Commands of the \xintbinhexname package}
\label{sec:binhex}
\localtableofcontents
This package was first included in the |1.08| (|2013/06/07|) release of
\xintname. It provides expandable conversions of arbitrarily big integers to and
from binary and hexadecimal.
The argument is first \fexpan ded. It then may start with an optional minus
sign (unique, of category code other), followed with optional leading zeroes
(arbitrarily many, category code other) and then ``digits'' (hexadecimal
letters may be of category code letter or other, and must be
uppercased). The optional (unique) minus sign (plus sign is not allowed) is
kept in the output. Leading zeroes are allowed, and stripped. The
hexadecimal letters on output are of category code letter, and
uppercased.
% \clearpage
\subsection{\csbh{xintDecToHex}}\label{xintDecToHex}
Converts from decimal to hexadecimal.\etype{f}
\texttt{\string\xintDecToHex \string{\printnumber{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}\string}}\endgraf\noindent\dtt{->\printnumber{\xintDecToHex{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}}}
\subsection{\csbh{xintDecToBin}}\label{xintDecToBin}
Converts from decimal to binary.\etype{f}
\texttt{\string\xintDecToBin \string{\printnumber{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}\string}}\endgraf\noindent\dtt{->\printnumber{\xintDecToBin{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}}}
\subsection{\csbh{xintHexToDec}}\label{xintHexToDec}
Converts from hexadecimal to decimal.\etype{f}
\texttt{\string\xintHexToDec
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent
\dtt{->\printnumber{\xintHexToDec{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}}
\subsection{\csbh{xintBinToDec}}\label{xintBinToDec}
Converts from binary to decimal.\etype{f}
\texttt{\string\xintBinToDec
\string{\printnumber{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}\string}}\endgraf\noindent
\dtt{->\printnumber{\xintBinToDec{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}}}
\subsection{\csbh{xintBinToHex}}\label{xintBinToHex}
Converts from binary to hexadecimal.\etype{f}
\texttt{\string\xintBinToHex
\string{\printnumber{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}\string}}\endgraf\noindent
\dtt{->\printnumber{\xintBinToHex{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}}}
\subsection{\csbh{xintHexToBin}}\label{xintHexToBin}
Converts from hexadecimal to binary.\etype{f}
\texttt{\string\xintHexToBin
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent
\dtt{->\printnumber{\xintHexToBin{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}}
\subsection{\csbh{xintCHexToBin}}\label{xintCHexToBin}
Also converts from hexadecimal to binary.\etype{f} Faster on inputs with at
least one hundred hexadecimal digits.
\texttt{\string\xintCHexToBin
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent
\dtt{->\printnumber{\xintCHexToBin{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}}
\clearpage
\section{Commands of the \xintgcdname package}
\label{sec:gcd}
\localtableofcontents
This package was included in the original release |1.0| (|2013/03/28|) of the
\xintname bundle.
Since release |1.09a| the macros filter their inputs through the \csbxint{Num}
macro, so one can use count registers, or fractions as long as they reduce to
integers.
Since release |1.1|, the two ``|typeset|'' macros require the explicit
loading by the user of package \xinttoolsname.
%% \clearpage
\subsection{\csbh{xintGCD}, \csbh{xintiiGCD}}\label{xintGCD}\label{xintiiGCD}
|\xintGCD|\n\m\etype{\Numf\Numf} computes the greatest common divisor. It is
positive, except when both |N| and |M| vanish, in which case the macro returns
zero.
%
\leftedline{\csa{xintGCD}|{10000}{1113}|\dtt{=\xintGCD{10000}{1113}}}
%
\leftedline{|\xintiiGCD{123456789012345}{9876543210321}=|\dtt
{\xintiiGCD{123456789012345}{9876543210321}}}
\csa{xintiiGCD} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintGCDof}}\label{xintGCDof}
\csa{xintGCDof}|{{a}{b}{c}...}|\etype{f{$\to$}{\lowast\Numf}} computes the greatest common divisor of all
integers |a|, |b|, \dots{} The list argument
may be a macro, it is \fexpan ded first and must contain at least one item.
\subsection{\csbh{xintLCM}, \csbh{xintiiLCM}}\label{xintLCM}\label{xintiiLCM}
|\xintGCD|\n\m\etype{\Numf\Numf} computes the least common multiple. It is
|0| if one of the two integers vanishes.
\csa{xintiiLCM} skips the \csbxint{Num} overhead.\etype{ff}
\subsection{\csbh{xintLCMof}}\label{xintLCMof}
\csa{xintLCMof}|{{a}{b}{c}...}|\etype{f{$\to$}{\lowast\Numf}} computes the least
common multiple of all integers |a|, |b|, \dots{} The list argument may be a
macro, it is \fexpan ded first and must contain at least one item.
\subsection{\csbh{xintBezout}}\label{xintBezout}
\xintAssign{{\xintBezout {10000}{1113}}}\to\X
\xintAssign {\xintBezout {10000}{1113}}\to\A\B\U\V\D
|\xintBezout|\n\m\etype{\Numf\Numf} returns five numbers |A|, |B|, |U|, |V|,
|D| within braces. |A| is the first (expanded, as usual) input number, |B| the
second, |D| is the GCD, and \dtt{UA - VB = D}. %
%
\leftedline{|\xintAssign
{{\xintBezout {10000}{1113}}}\to\X|} %
%
\leftedline{|\meaning\X:
|\dtt{\meaning\X }.}
\noindent{|\xintAssign {\xintBezout {10000}{1113}}\to\A\B\U\V\D|}\\
|\A: |\dtt{\A },
|\B: |\dtt{\B },
|\U: |\dtt{\U },
|\V: |\dtt{\V },
|\D: |\dtt{\D }.\\
\xintAssign {\xintBezout {123456789012345}{9876543210321}}\to\A\B\U\V\D
\noindent{|\xintAssign {\xintBezout {123456789012345}{9876543210321}}\to\A\B\U\V\D
|}\\
|\A: |\dtt{\A },
|\B: |\dtt{\B },
|\U: |\dtt{\U },
|\V: |\dtt{\V },
|\D: |\dtt{\D }.
\subsection{\csbh{xintEuclideAlgorithm}}\label{xintEuclideAlgorithm}
\xintAssign {{\xintEuclideAlgorithm {10000}{1113}}}\to\X
\def\restorebracecatcodes
{\catcode`\{=1 \catcode`\}=2 }
\def\allowlistsplit
{\catcode`\{=12 \catcode`\}=12 \allowlistsplita }
\def\allowlistsplitx {\futurelet\listnext\allowlistsplitxx }
\def\allowlistsplitxx {\ifx\listnext\relax \restorebracecatcodes
\else \expandafter\allowlistsplitxxx \fi }
\begingroup
\catcode`\[=1
\catcode`\]=2
\catcode`\{=12
\catcode`\}=12
\gdef\allowlistsplita #1{[#1\allowlistsplitx {]
\gdef\allowlistsplitxxx {#1}%
[{#1}\hskip 0pt plus 1pt \allowlistsplitx ]
\endgroup
|\xintEuclideAlgorithm|\n\m\etype{\Numf\Numf} applies the Euclide algorithm
and keeps a copy of all quotients and remainders. %
%
\leftedline{|\xintAssign {{\xintEuclideAlgorithm {10000}{1113}}}\to\X|}
|\meaning\X: |\dtt{\expandafter\allowlistsplit\meaning\X\relax .}
The first token is the number of steps, the second is |N|, the
third is the GCD, the fourth is |M| then the first quotient and
remainder, the second quotient and remainder, \dots until the
final quotient and last (zero) remainder.
\subsection{\csbh{xintBezoutAlgorithm}}\label{xintBezoutAlgorithm}
\xintAssign {{\xintBezoutAlgorithm {10000}{1113}}}\to\X
|\xintBezoutAlgorithm|\n\m\etype{\Numf\Numf} applies the Euclide algorithm
and keeps a copy of all quotients and remainders. Furthermore it computes the
entries of the successive products of the 2 by 2 matrices
$\left(\vcenter{\halign {\,#&\,#\cr q & 1 \cr 1 & 0 \cr}}\right)$ formed from
the quotients arising in the algorithm. %
%
\leftedline{|\xintAssign {{\xintBezoutAlgorithm {10000}{1113}}}\to\X|}
|\meaning\X: |\dtt{\expandafter\allowlistsplit\meaning\X \relax .}
The first token is the number of steps, the second is |N|, then
|0|, |1|, the GCD, |M|, |1|, |0|, the first quotient, the first
remainder, the top left entry of the first matrix, the bottom left
entry, and then these four things at each step until the end.
\subsection{\csbh{xintTypesetEuclideAlgorithm}}\label{xintTypesetEuclideAlgorithm}
Requires explicit loading by the user of package \xinttoolsname.
This macro is just an example of how to organize the data returned by
\csa{xintEuclideAlgorithm}.\ntype{\Numf\Numf} Copy the source code to a new
macro and modify it to what is needed.
%
\leftedline{|\xintTypesetEuclideAlgorithm {123456789012345}{9876543210321}|}
\xintTypesetEuclideAlgorithm {123456789012345}{9876543210321}
\subsection{\csbh{xintTypesetBezoutAlgorithm}}%
\label{xintTypesetBezoutAlgorithm}
Requires explicit loading by the user of package \xinttoolsname.
This macro is just an example of how to organize the data returned by
\csa{xintBezoutAlgorithm}.\ntype{\Numf\Numf} Copy the source code to a new
macro and modify it to what is needed.
%
\leftedline{|\xintTypesetBezoutAlgorithm {10000}{1113}|}
\xintTypesetBezoutAlgorithm {10000}{1113}
\clearpage
\section{Commands of the \xintseriesname package}
\label{sec:series}
\localtableofcontents
This package was first released with version |1.03| (|2013/04/14|) of the
\xintname bundle.
The \Ff{} expansion type of various macro arguments is only a \Numf{} if only
\xintname but not \xintfracname is loaded. The macro \csbxint{iSeries} is
special and expects summing big integers obeying the strict format, even if
\xintfracname is loaded.
The arguments serving as indices are of the \numx{} expansion type.
In some cases one or two of the macro arguments are only expanded at a later
stage not immediately.
%% \clearpage
\subsection{\csbh{xintSeries}}\label{xintSeries}
\csa{xintSeries}|{A}{B}{\coeff}|\etype{\numx\numx\Ff} computes
$\sum_{\text{|n=A|}}^{\text{|n=B|}}|\coeff{n}|$. The initial and final indices
must obey the |\numexpr| constraint of expanding to numbers at most |2^31-1|.
The |\coeff| macro must be a one-parameter \fexpan dable command, taking on
input an explicit number |n| and producing some number or fraction |\coeff{n}|;
it is expanded at the time it is
needed.%
%
\footnote{\label{fn:xintiiMON}\csbxint{iiMON} is like \csbxint{MON} but
does not parse its argument through \csbxint{Num}, for efficiency;
other macros of this type are \csbxint{iiAdd}, \csbxint{iiMul},
\csbxint{iiSum}, \csbxint{iiPrd}, \csbxint{iiMMON}, \csbxint{iiLDg},
\csbxint{iiFDg}, \csbxint{iiOdd}, \dots}
\begin{everbatim*}
\def\coeff #1{\xintiiMON{#1}/#1.5} % (-1)^n/(n+1/2)
\fdef\w {\xintSeries {0}{50}{\coeff}} % we want to re-use it
\fdef\z {\xintJrr {\w}[0]} % the [0] for a microsecond gain.
% \xintJrr preferred to \xintIrr: a big common factor is suspected.
% But numbers much bigger would be needed to show the greater efficiency.
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} = \xintFrac\z \]
\end{everbatim*}
The definition of |\coeff| as |\xintiiMON{#1}/#1.5| is quite suboptimal. It
allows |#1| to be a big integer, but anyhow only small integers are accepted
as initial and final indices (they are of the \numx{} type). Second, when the
\xintfracname parser sees the |#1.5| it will remove the dot hence create a
denominator with one digit more. For example |1/3.5| turns internally into
|10/35| whereas it would be more efficient to have |2/7|. For info here is the
non-reduced |\w|:
\[\xintFrac\w\]
It would have been bigger still in releases earlier than |1.1|: now, the
\xintfracname \csbxint{Add} routine does not multiply blindly denominators
anymore, it checks if one is a multiple of the other. However it does not
practice systematic reduction to lowest terms.
A more efficient way to code |\coeff| is illustrated next.
\begin{everbatim*}
\def\coeff #1{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}%
% The [0] in \coeff is a tiny optimization: in its presence the \xintfracname parser
% sees something which is already in internal format.
\fdef\w {\xintSeries {0}{50}{\coeff}}
\[\sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12}=\xintFrac\w\]
\end{everbatim*}
The reduced form |\z| as displayed above only differs from this one by a
factor of \dtt{\xintNum {\xintDenominator\w/\xintDenominator\z}}.
\setlength{\columnsep}{0pt}
\everb|@
\def\coeffleibnitz #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]}
\cnta 1
\loop % in this loop we recompute from scratch each partial sum!
% we can afford that, as \xintSeries is fast enough.
\noindent\hbox to 2em{\hfil\texttt{\the\cnta.} }%
\xintTrunc {12}{\xintSeries {1}{\cnta}{\coeffleibnitz}}\dots
\endgraf
\ifnum\cnta < 30 \advance\cnta 1 \repeat
|
\begin{multicols}{3}
\def\coeffleibnitz #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]} \cnta 1
\loop
\noindent\hbox to 2em{\hfil\dtt{\the\cnta.} }%
\xintTrunc {12}{\xintSeries {1}{\cnta}{\coeffleibnitz}}\dots
\endgraf
\ifnum\cnta < 30 \advance\cnta 1 \repeat
\end{multicols}
\subsection{\csbh{xintiSeries}}\label{xintiSeries}
\def\coeff #1{\xintiTrunc {40}
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}%
\csa{xintiSeries}|{A}{B}{\coeff}|\etype{\numx\numx f} computes
$\sum_{\text{|n=A|}}^{\text{|n=B|}}|\coeff{n}|$ where |\coeff{n}|
must \fexpan d to a (possibly long) integer in the strict format.
\everb|@
\def\coeff #1{\xintiTrunc {40}{\xintMON{#1}/#1.5}}%
% better:
\def\coeff #1{\xintiTrunc {40}
{\the\numexpr 2*\xintiiMON{#1}\relax/\the\numexpr 2*#1+1\relax [0]}}%
% better still:
\def\coeff #1{\xintiTrunc {40}
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}%
% (-1)^n/(n+1/2) times 10^40, truncated to an integer.
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx
\xintTrunc {40}{\xintiSeries {0}{50}{\coeff}[-40]}\dots\]
|
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx \xintTrunc
{40}{\xintiSeries {0}{50}{\coeff}[-40]}\]
We should have cut out at
least the last two digits: truncating errors originating with the first
coefficients of the sum will never go away, and each truncation
introduces an uncertainty in the last digit, so as we have 40 terms, we
should trash the last two digits, or at least round at 38 digits. It is
interesting to compare with the computation where rounding rather than
truncation is used, and with the decimal
expansion of the exactly computed partial sum of the series:
\everb|@
\def\coeff #1{\xintiRound {40} % rounding at 40
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}%
% (-1)^n/(n+1/2) times 10^40, rounded to an integer.
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx
\xintTrunc {40}{\xintiSeries {0}{50}{\coeff}[-40]}\]
\def\exactcoeff #1%
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}%
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12}
= \xintTrunc {50}{\xintSeries {0}{50}{\exactcoeff}}\dots\]
|
\def\coeff #1{\xintiRound {40}
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}%
% (-1)^n/(n+1/2) times 10^40, rounded to an integer.
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx
\xintTrunc {40}{\xintiSeries {0}{50}{\coeff}[-40]}\]
\def\exactcoeff #1%
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}%
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12}
= \xintTrunc {50}{\xintSeries {0}{50}{\exactcoeff}}\dots\]
This shows indeed that our sum of truncated terms
estimated wrongly the 39th and 40th digits of the exact result%
%
\footnote{as the series is alternating, we can roughly expect an error
of $\sqrt{40}$ and the last two digits are off by 4 units, which is
not contradictory to our expectations.}
%
and that the sum of rounded terms fared a bit better.
\subsection{\csbh{xintRationalSeries}}\label{xintRationalSeries}
\noindent \csa{xintRationalSeries}|{A}{B}{f}{\ratio}|\etype{\numx\numx\Ff\Ff}
evaluates $\sum_{\text{|n=A|}}^{\text{|n=B|}}|F(n)|$, where |F(n)| is specified
indirectly via the data of |f=F(A)| and the one-parameter macro |\ratio| which
must be such that |\macro{n}| expands to |F(n)/F(n-1)|. The name indicates that
\csa{xintRationalSeries} was designed to be useful in the cases where
|F(n)/F(n-1)| is a rational function of |n| but it may be anything expanding to
a fraction. The macro |\ratio| must be an expandable-only compatible command and
expand to its value after iterated full expansion of its first token. |A| and
|B| are fed to a |\numexpr| hence may be count registers or arithmetic
expressions built with such; they must obey the \TeX{} bound. The initial term
|f| may be a macro |\f|, it will be expanded to its value representing |F(A)|.
\begin{everbatim*}
\def\ratio #1{2/#1[0]}% 2/n, to compute exp(2)
\cnta 0 % previously declared count
\begin{quote}
\loop \fdef\z {\xintRationalSeries {0}{\cnta}{1}{\ratio }}%
\noindent$\sum_{n=0}^{\the\cnta} \frac{2^n}{n!}=
\xintTrunc{12}\z\dots=
\xintFrac\z=\xintFrac{\xintIrr\z}$\vtop to 5pt{}\par
\ifnum\cnta<20 \advance\cnta 1 \repeat
\end{quote}
\end{everbatim*}
\begin{everbatim*}
\def\ratio #1{-1/#1[0]}% -1/n, comes from the series of exp(-1)
\cnta 0 % previously declared count
\begin{quote}
\loop
\fdef\z {\xintRationalSeries {0}{\cnta}{1}{\ratio }}%
\noindent$\sum_{n=0}^{\the\cnta} \frac{(-1)^n}{n!}=
\xintTrunc{20}\z\dots=\xintFrac{\z}=\xintFrac{\xintIrr\z}$%
\vtop to 5pt{}\par
\ifnum\cnta<20 \advance\cnta 1 \repeat
\end{quote}
\end{everbatim*}
\def\ratioexp #1#2{\xintDiv{#1}{#2}}% #1/#2
\medskip We can incorporate an indeterminate if we define |\ratio| to be
a macro with two parameters: |\def\ratioexp
#1#2{\xintDiv{#1}{#2}}|\texttt{\%}| x/n: x=#1, n=#2|.
Then, if |\x| expands to some fraction |x|, the
command %
%
\leftedline{|\xintRationalSeries {0}{b}{1}{\ratioexp{\x}}|}
will compute $\sum_{n=0}^{n=b} x^n/n!$:\par
\begin{everbatim*}
\cnta 0
\def\ratioexp #1#2{\xintDiv{#1}{#2}}% #1/#2
\loop
\noindent
$\sum_{n=0}^{\the\cnta} (.57)^n/n! = \xintTrunc {50}
{\xintRationalSeries {0}{\cnta}{1}{\ratioexp{.57}}}\dots$
\vtop to 5pt {}\endgraf
\ifnum\cnta<50 \advance\cnta 10 \repeat
\end{everbatim*}
Observe that in this last example the |x| was directly inserted; if it
had been a more complicated explicit fraction it would have been
worthwile to use |\ratioexp\x| with |\x| defined to expand to its value.
In the further situation where this fraction |x| is not explicit but
itself defined via a complicated, and time-costly, formula, it should be
noted that \csa{xintRationalSeries} will do again the evaluation of |\x|
for each term of the partial sum. The easiest is thus when |x| can be
defined as an |\edef|. If however, you are in an expandable-only context
and cannot store in a macro like |\x| the value to be used, a variant of
\csa{xintRationalSeries} is needed which will first evaluate this |\x| and then
use this result without recomputing it. This is \csbxint{RationalSeriesX},
documented next.
Here is a slightly more complicated evaluation:
\begin{everbatim*}
\cnta 1
\begin{multicols}{2}
\loop \fdef\z {\xintRationalSeries
{\cnta}
{2*\cnta-1}
{\xintiPow {\the\cnta}{\cnta}/\xintiiFac{\cnta}}
{\ratioexp{\the\cnta}}}%
\fdef\w {\xintRationalSeries {0}{2*\cnta-1}{1}{\ratioexp{\the\cnta}}}%
\noindent
$\sum_{n=\the\cnta}^{\the\numexpr 2*\cnta-1\relax} \frac{\the\cnta^n}{n!}/%
\sum_{n=0}^{\the\numexpr 2*\cnta-1\relax} \frac{\the\cnta^n}{n!} =
\xintTrunc{8}{\xintDiv\z\w}\dots$ \vtop to 5pt{}\endgraf
\ifnum\cnta<20 \advance\cnta 1 \repeat
\end{multicols}
\end{everbatim*}
\subsection{\csbh{xintRationalSeriesX}}\label{xintRationalSeriesX}
\noindent\csa{xintRationalSeriesX}|{A}{B}{\first}{\ratio}{\g}|%
\etype{\numx\numx\Ff\Ff f} is a parametrized version of \csa{xintRationalSeries}
where |\first| is now a one-parameter macro such that |\first{\g}| gives the
initial term and |\ratio| is a two-parameter macro such that |\ratio{n}{\g}|
represents the ratio of one term to the previous one. The parameter |\g| is
evaluated only once at the beginning of the computation, and can thus itself be
the yet unevaluated result of a previous computation.
Let |\ratio| be such a two-parameter macro; note the subtle differences
between%
%
\leftedline{|\xintRationalSeries {A}{B}{\first}{\ratio{\g}}|}
%
\leftedline{and |\xintRationalSeriesX {A}{B}{\first}{\ratio}{\g}|.} First the
location of braces differ... then, in the former case |\first| is a
\emph{no-parameter} macro expanding to a fractional number, and in the latter,
it is a
\emph{one-parameter} macro which will use |\g|. Furthermore the |X| variant
will expand |\g| at the very beginning whereas the former non-|X| former variant
will evaluate it each time it needs it (which is bad if this
evaluation is time-costly, but good if |\g| is a big explicit fraction
encapsulated in a macro).
The example will use the macro \csbxint{PowerSeries} which computes
efficiently exact partial sums of power series, and is discussed in the
next section.
\begin{everbatim*}
\def\firstterm #1{1[0]}% first term of the exponential series
% although it is the constant 1, here it must be defined as a
% one-parameter macro. Next comes the ratio function for exp:
\def\ratioexp #1#2{\xintDiv {#1}{#2}}% x/n
% These are the (-1)^{n-1}/n of the log(1+h) series:
\def\coefflog #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]}%
% Let L(h) be the first 10 terms of the log(1+h) series and
% let E(t) be the first 10 terms of the exp(t) series.
% The following computes E(L(a/10)) for a=1,...,12.
\begin{multicols}{3}\raggedcolumns
\cnta 0
\loop
\noindent\xintTrunc {18}{%
\xintRationalSeriesX {0}{9}{\firstterm}{\ratioexp}
{\xintPowerSeries{1}{10}{\coefflog}{\the\cnta[-1]}}}\dots
\endgraf
\ifnum\cnta < 12 \advance \cnta 1 \repeat
\end{multicols}
\end{everbatim*}
These completely exact operations rapidly create numbers with many digits. Let
us print in full the raw fractions created by the operation illustrated above:
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm}
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1[-1]}}}
|E(L(1[-1]))=|\dtt{\printnumber{\z}} (length of numerator:
\xintLen {\xintNumerator \z})
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm}
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{12[-2]}}}
|E(L(12[-2]))=|\dtt{\printnumber{\z}} (length of numerator:
\xintLen {\xintNumerator \z})
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm}
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{123[-3]}}}
|E(L(123[-3]))=|\dtt{\printnumber{\z}} (length of numerator:
\xintLen {\xintNumerator \z})
We see that the denominators here remain the same, as our input only had various
powers of ten as denominators, and \xintfracname efficiently assemble (some
only, as we can see) powers of ten. Notice that 1 more digit in an input
denominator seems to mean 90 more in the raw output. We can check that with some
other test cases:
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm}
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1/7}}}
|E(L(1/7))=|\dtt{\printnumber{\z}} (length of numerator:
\xintLen {\xintNumerator \z}; length of denominator:
\xintLen {\xintDenominator \z})
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm}
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1/71}}}
|E(L(1/71))=|\dtt{\printnumber{\z}} (length of numerator:
\xintLen {\xintNumerator \z}; length of denominator:
\xintLen {\xintDenominator \z})
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm}
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1/712}}}
|E(L(1/712))=|\dtt{\printnumber{\z}} (length of numerator:
\xintLen {\xintNumerator \z}; length of denominator:
\xintLen {\xintDenominator \z})
Thus
decimal numbers such as |0.123| (equivalently
|123[-3]|) give less computing intensive tasks than fractions such as |1/712|:
in the case of decimal numbers the (raw) denominators originate in the
coefficients of the series themselves, powers of ten of the input within
brackets being treated separately. And even then the
numerators will grow with the size of the input in a sort of linear way, the
coefficient being given by the order of series: here 10 from the log and 9 from
the exp, so 90. One more digit in the input means 90 more digits in the
numerator of the output: obviously we can not go on composing such partial sums
of series and hope that \xintname will joyfully do all at the speed of light!
Hence, truncating the output (or better, rounding) is the only way to go if one
needs a general calculus of special functions. This is why the package
\xintseriesname provides, besides \csbxint{Series}, \csbxint{RationalSeries}, or
\csbxint{PowerSeries} which compute \emph{exact} sums,
\csbxint{FxPtPowerSeries} for fixed-point computations and a (tentative naive)
\csbxint{FloatPowerSeries}.
\subsection{\csbh{xintPowerSeries}}\label{xintPowerSeries}
\csa{xintPowerSeries}|{A}{B}{\coeff}{f}|\etype{\numx\numx\Ff\Ff}
evaluates the sum
$\sum_{\text{|n=A|}}^{\text{|n=B|}}|\coeff{n}|\cdot |f|^{\text{|n|}}$. The
initial and final indices are given to a |\numexpr| expression. The |\coeff|
macro (which, as argument to \csa{xintPowerSeries} is expanded only at the time
|\coeff{n}| is needed) should be defined as a one-parameter expandable command,
its input will be an explicit number.
The |f| can be either a fraction directly input or a macro |\f| expanding to
such a fraction. It is actually more efficient to encapsulate an explicit
fraction |f| in such a macro, if it has big numerators and denominators (`big'
means hundreds of digits) as it will then take less space in the processing
until being (repeatedly) used.
This macro computes the \emph{exact} result (one can use it also for
polynomial evaluation), using a Horner scheme which helps avoiding a
denominator build-up (this problem however, even if using a naive additive
approach, is much less acute since release |1.1| and its new policy regarding
\csbxint{Add}).
\begin{everbatim*}
\def\geom #1{1[0]} % the geometric series
\def\f {5/17[0]}
\[ \sum_{n=0}^{n=20} \Bigl(\frac 5{17}\Bigr)^n
=\xintFrac{\xintIrr{\xintPowerSeries {0}{20}{\geom}{\f}}}
=\xintFrac{\xinttheexpr (17^21-5^21)/12/17^20\relax}\]
\end{everbatim*}
\begin{everbatim*}
\def\coefflog #1{1/#1[0]}% 1/n
\def\f {1/2[0]}%
\[ \log 2 \approx \sum_{n=1}^{20} \frac1{n\cdot 2^n}
= \xintFrac {\xintIrr {\xintPowerSeries {1}{20}{\coefflog}{\f}}}\]
\[ \log 2 \approx \sum_{n=1}^{50} \frac1{n\cdot 2^n}
= \xintFrac {\xintIrr {\xintPowerSeries {1}{50}{\coefflog}{\f}}}\]
\end{everbatim*}
\begin{everbatim*}
\setlength{\columnsep}{0pt}
\begin{multicols}{3}
\cnta 1 % previously declared count
\loop % in this loop we recompute from scratch each partial sum!
% we can afford that, as \xintPowerSeries is fast enough.
\noindent\hbox to 2em{\hfil\texttt{\the\cnta.} }%
\xintTrunc {12}
{\xintPowerSeries {1}{\cnta}{\coefflog}{\f}}\dots
\endgraf
\ifnum \cnta < 30 \advance\cnta 1 \repeat
\end{multicols}
\end{everbatim*}
\begin{everbatim*}
\def\coeffarctg #1{1/\the\numexpr\ifodd #1 -2*#1-1\else2*#1+1\fi\relax }%
% the above gives (-1)^n/(2n+1). The sign being in the denominator,
% **** no [0] should be added ****,
% else nothing is guaranteed to work (even if it could by sheer luck)
% Notice in passing this aspect of \numexpr:
% **** \numexpr -(1)\relax is ilegal !!! ****
\def\f {1/25[0]}% 1/5^2
\[\mathrm{Arctg}(\frac15)\approx \frac15\sum_{n=0}^{15} \frac{(-1)^n}{(2n+1)25^n}
= \xintFrac{\xintIrr {\xintDiv {\xintPowerSeries {0}{15}{\coeffarctg}{\f}}{5}}}\]
\end{everbatim*}
\subsection{\csbh{xintPowerSeriesX}}\label{xintPowerSeriesX}
%{\small\hspace*{\parindent}New with release |1.04|.\par}
\noindent This is the same as \csbxint{PowerSeries}\ntype{\numx\numx\Ff\Ff}
apart
from the fact that the last parameter |f| is expanded once and for all before
being then used repeatedly. If the |f| parameter is to be an explicit big
fraction with many (dozens) digits, rather than using it directly it is slightly
better to have some macro |\g| defined to expand to the explicit fraction and
then use \csbxint{PowerSeries} with |\g|; but if |f| has not yet been evaluated
and will be the output of a complicated expansion of some |\f|, and if, due to
an expanding only context, doing |\edef\g{\f}| is no option, then
\csa{xintPowerSeriesX} should be used with |\f| as last parameter.
%
\begin{everbatim*}
\def\ratioexp #1#2{\xintDiv {#1}{#2}}% x/n
% These are the (-1)^{n-1}/n of the log(1+h) series:
\def\coefflog #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]}%
% Let L(h) be the first 10 terms of the log(1+h) series and
% let E(t) be the first 10 terms of the exp(t) series.
% The following computes L(E(a/10)-1) for a=1,..., 12.
\begin{multicols}{3}\raggedcolumns
\cnta 1
\loop
\noindent\xintTrunc {18}{%
\xintPowerSeriesX {1}{10}{\coefflog}
{\xintSub
{\xintRationalSeries {0}{9}{1[0]}{\ratioexp{\the\cnta[-1]}}}
{1}}}\dots
\endgraf
\ifnum\cnta < 12 \advance \cnta 1 \repeat
\end{multicols}
\end{everbatim*}
\subsection{\csbh{xintFxPtPowerSeries}}\label{xintFxPtPowerSeries}
\csa{xintFxPtPowerSeries}|{A}{B}{\coeff}{f}{D}|\etype{\numx\numx}
computes
$\sum_{\text{|n=A|}}^{\text{|n=B|}}|\coeff{n}|\cdot |f|^{\,\text{|n|}}$ with each
term of the series truncated to |D| digits\etype{\Ff\Ff\numx}
after the decimal point. As
usual, |A| and |B| are completely expanded through their inclusion in a
|\numexpr| expression. Regarding |D| it will be similarly be expanded each
time it is used inside an \csa{xintTrunc}. The one-parameter macro |\coeff|
is similarly expanded at the time it is used inside the
computations. Idem for |f|. If |f| itself is some complicated macro it is
thus better to use the variant \csbxint{FxPtPowerSeriesX} which expands it
first and then uses the result of that expansion.
The current (|1.04|) implementation is: the first power |f^A| is
computed exactly, then \emph{truncated}. Then each successive power is
obtained from the previous one by multiplication by the exact value of
|f|, and truncated. And |\coeff{n}|\raisebox{.5ex}{|.|}|f^n| is obtained
from that by multiplying by |\coeff{n}| (untruncated) and then
truncating. Finally the sum is computed exactly. Apart from that
\csa{xintFxPtPowerSeries} (where |FxPt| means `fixed-point') is like
\csa{xintPowerSeries}.
There should be a variant for things of the type $\sum c_n \frac {f^n}{n!}$ to
avoid having to compute the factorial from scratch at each coefficient, the same
way \csa{xintFxPtPowerSeries} does not compute |f^n| from scratch at each |n|.
Perhaps in the next package release.
\def\coeffexp #1{1/\xintiiFac {#1}[0]}% [0] for faster parsing
\def\f {-1/2[0]}%
\newcount\cnta
\setlength{\multicolsep}{0pt}
\begin{multicols}{3}[%
\centeredline{$e^{-\frac12}\approx{}$}]%
\cnta 0
\noindent\loop
$\xintFxPtPowerSeries {0}{\cnta}{\coeffexp}{\f}{20}$\\
\ifnum\cnta<19
\advance\cnta 1
\repeat\par
\end{multicols}
\everb|@
\def\coeffexp #1{1/\xintiiFac {#1}[0]}% 1/n!
\def\f {-1/2[0]}% [0] for faster input parsing
\cnta 0 % previously declared \count register
\noindent\loop
$\xintFxPtPowerSeries {0}{\cnta}{\coeffexp}{\f}{20}$\\
\ifnum\cnta<19 \advance\cnta 1 \repeat\par
|
%
\leftedline{|\xintFxPtPowerSeries {0}{19}{\coeffexp}{\f}{25}=|
\dtt{\xintFxPtPowerSeries {0}{19}{\coeffexp}{\f}{25}}}
\fdef\z{\xintIrr {\xintPowerSeries {0}{19}{\coeffexp}{\f}}}
%
\texttt{\hyphenchar\font45 }%
It is no difficulty for \xintfracname to compute exactly, with the help
of \csa{xintPowerSeries}, the nineteenth partial sum, and to then give
(the start of) its exact decimal expansion:
%
\leftedline{|\xintPowerSeries {0}{19}{\coeffexp}{\f}| ${}=
\displaystyle\xintFrac{\z}$%
\vphantom{\vrule height 20pt depth 12pt}}%
%
\leftedline{${}=\xintTrunc {30}{\z}\dots$} Thus, one should always
estimate a priori how many ending digits are not reliable: if there are
|N| terms and |N| has |k| digits, then digits up to but excluding the
last |k| may usually be trusted. If we are optimistic and the series is
alternating we may even replace |N| with $\sqrt{|N|}$ to get the number |k|
of digits possibly of dubious significance.
\subsection{\csbh{xintFxPtPowerSeriesX}}\label{xintFxPtPowerSeriesX}
\noindent\csa{xintFxPtPowerSeriesX}|{A}{B}{\coeff}{\f}{D}|%
\ntype{\numx\numx}
computes, exactly as
\csa{xintFxPtPowerSeries}, the sum of
|\coeff{n}|\raisebox{.5ex}{|.|}|\f^n|\etype{\Ff\Ff\numx} from |n=A| to |n=B| with each term
of the series being \emph{truncated} to |D| digits after the decimal
point. The sole difference is that |\f| is first expanded and it
is the result of this which is used in the computations.
Let us illustrate this on the numerical exploration of the identity
%
\leftedline{|log(1+x) = -log(1/(1+x))|}
%
Let |L(h)=log(1+h)|, and |D(h)=L(h)+L(-h/(1+h))|. Theoretically thus,
|D(h)=0| but we shall evaluate |L(h)| and |-h/(1+h)| keeping only 10
terms of their respective series. We will assume $|h|<0.5$. With only
ten terms kept in the power series we do not have quite 3 digits
precision as $2^{10}=1024$. So it wouldn't make sense to evaluate things
more precisely than, say circa 5 digits after the decimal points.
\begin{everbatim*}
\cnta 0
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% (-1)^{n-1}/n
\def\coeffalt #1{\the\numexpr\ifodd#1 -1\else1\fi\relax [0]}% (-1)^n
\begin{multicols}2
\loop
\noindent \hbox to 2.5cm {\hss\texttt{D(\the\cnta/100): }}%
\xintAdd {\xintFxPtPowerSeriesX {1}{10}{\coefflog}{\the\cnta [-2]}{5}}
{\xintFxPtPowerSeriesX {1}{10}{\coefflog}
{\xintFxPtPowerSeriesX {1}{10}{\coeffalt}{\the\cnta [-2]}{5}}
{5}}\endgraf
\ifnum\cnta < 49 \advance\cnta 7 \repeat
\end{multicols}
\end{everbatim*}
Let's say we evaluate functions on |[-1/2,+1/2]| with values more or less also
in |[-1/2,+1/2]| and we want to keep 4 digits of precision. So, roughly we need
at least 14 terms in series like the geometric or log series. Let's make this
15. Then it doesn't make sense to compute intermediate summands with more than 6
digits precision. So we compute with 6 digits
precision but return only 4 digits (rounded) after the decimal point.
This result with 4 post-decimal points precision is then used as input
to the next evaluation.
\begin{everbatim*}
\begin{multicols}2
\loop
\noindent \hbox to 2.5cm {\hss\texttt{D(\the\cnta/100): }}%
\dtt{\xintRound{4}
{\xintAdd {\xintFxPtPowerSeriesX {1}{15}{\coefflog}{\the\cnta [-2]}{6}}
{\xintFxPtPowerSeriesX {1}{15}{\coefflog}
{\xintRound {4}{\xintFxPtPowerSeriesX {1}{15}{\coeffalt}
{\the\cnta [-2]}{6}}}
{6}}%
}}\endgraf
\ifnum\cnta < 49 \advance\cnta 7 \repeat
\end{multicols}
\end{everbatim*}
Not bad... I have cheated a bit: the `four-digits precise' numeric
evaluations were left unrounded in the final addition. However the inner
rounding to four digits worked fine and made the next step faster than
it would have been with longer inputs. The morale is that one should not
use the raw results of \csa{xintFxPtPowerSeriesX} with the |D| digits
with which it was computed, as the last are to be considered garbage.
Rather, one should keep from the output only some smaller number of
digits. This will make further computations faster and not less precise.
I guess there should be some command to do this final truncating, or
better, rounding, at a given number |D'<D| of digits. Maybe for the next
release.
\subsection{\csbh{xintFloatPowerSeries}}\label{xintFloatPowerSeries}
\noindent\csa{xintFloatPowerSeries}|[P]{A}{B}{\coeff}{f}|%
\ntype{{\upshape[\numx]}\numx\numx}
computes
$\sum_{\text{|n=A|}}^{\text{|n=B|}}|\coeff{n}|\cdot |f|^{\,\text{|n|}}$
with a floating point
precision given by the optional parameter |P| or by the current setting of
|\xintDigits|.\etype{\Ff\Ff}
In the current, preliminary, version, no attempt has been made to try to
guarantee to the final result the precision |P|. Rather, |P| is used for all
intermediate floating point evaluations. So
rounding errors will make some of the last printed digits invalid. The
operations done are first the evaluation of |f^A| using \csa{xintFloatPow}, then
each successive power is obtained from this first one by multiplication by |f|
using \csa{xintFloatMul}, then again with \csa{xintFloatMul} this is multiplied
with |\coeff{n}|, and the sum is done adding one term at a time with
\csa{xintFloatAdd}. To sum up, this is just the naive transformation of
\csa{xintFxPtPowerSeries} from fixed point to floating point.
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}%
\everb+@
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}%
\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}
+
%
\leftedline{\dtt{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}}}
\subsection{\csbh{xintFloatPowerSeriesX}}\label{xintFloatPowerSeriesX}
\noindent\csa{xintFloatPowerSeriesX}|[P]{A}{B}{\coeff}{f}|%
\ntype{{\upshape[\numx]}\numx\numx}
is like
\csa{xintFloatPowerSeries} with the difference that |f| is
expanded once\etype{\Ff\Ff}
and for all at the start of the computation, thus allowing
efficient chaining of such series evaluations.
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}%
\everb+@
\def\coeffexp #1{1/\xintiiFac {#1}[0]}% 1/n! (exact, not float)
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}%
\xintFloatPowerSeriesX [8]{0}{30}{\coeffexp}
{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}}
+
%
\leftedline{\dtt{\xintFloatPowerSeriesX [8]{0}{30}{\coeffexp}
{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}}}}
\subsection{Computing \texorpdfstring{$\log 2$}{log(2)} and \texorpdfstring{$\pi$}{pi}}\label{ssec:Machin}
In this final section, the use of \csbxint{FxPtPowerSeries} (and
\csbxint{PowerSeries}) will be
illustrated on the (expandable... why make things simple when it is so easy to
make them difficult!) computations of the first digits of the decimal expansion
of the familiar constants $\log 2$ and $\pi$.
Let us start with $\log 2$. We will get it from this formula (which is
left as an exercise): %
%
\leftedline{\dtt{log(2)=-2\,log(1-13/256)-%
5\,log(1-1/9)}}
%
The number of terms to be kept in the log series, for a desired
precision of |10^{-D}| was roughly estimated without much theoretical
analysis. Computing exactly the partial sums with \csa{xintPowerSeries}
and then printing the truncated values, from |D=0| up to |D=100| showed
that it worked in terms of quality of the approximation. Because of
possible strings of zeroes or nines in the exact decimal expansion (in
the present case of $\log 2$, strings of zeroes around the fourtieth and
the sixtieth decimals), this
does not mean though that all digits printed were always exact. In
the end one always end up having to compute at some higher level of
desired precision to validate the earlier result.
Then we tried with \csa{xintFxPtPowerSeries}: this is worthwile only for
|D|'s at least 50, as the exact evaluations are faster (with these
short-length |f|'s) for a lower
number of digits. And as expected the degradation in the quality of
approximation was in this range of the order of two or three digits.
This meant roughly that the 3+1=4 ending digits were wrong. Again, we ended
up having to compute with five more digits and compare with the earlier
value to validate it. We use truncation rather than rounding because our
goal is not to obtain the correct rounded decimal expansion but the
correct exact truncated one.
% 693147180559945309417232121458176568075500134360255254120680009493
\begin{everbatim*}
\def\coefflog #1{1/#1[0]}% 1/n
\def\xa {13/256[0]}% we will compute log(1-13/256)
\def\xb {1/9[0]}% we will compute log(1-1/9)
\def\LogTwo #1%
% get log(2)=-2log(1-13/256)- 5log(1-1/9)
{% we want to use \printnumber, hence need something expanding in two steps
% only, so we use here the \romannumeral0 method
\romannumeral0\expandafter\LogTwoDoIt \expandafter
% Nb Terms for 1/9:
{\the\numexpr #1*150/143\expandafter}\expandafter
% Nb Terms for 13/256:
{\the\numexpr #1*100/129\expandafter}\expandafter
% We print #1 digits, but we know the ending ones are garbage
{\the\numexpr #1\relax}% allows #1 to be a count register
}%
\def\LogTwoDoIt #1#2#3%
% #1=nb of terms for 1/9, #2=nb of terms for 13/256,
{% #3=nb of digits for computations, also used for printing
\xinttrunc {#3} % lowercase form to stop the \romannumeral0 expansion!
{\xintAdd
{\xintMul {2}{\xintFxPtPowerSeries {1}{#2}{\coefflog}{\xa}{#3}}}
{\xintMul {5}{\xintFxPtPowerSeries {1}{#1}{\coefflog}{\xb}{#3}}}%
}%
}%
\noindent $\log 2 \approx \LogTwo {60}\dots$\endgraf
\noindent\phantom{$\log 2$}${}\approx{}$\printnumber{\LogTwo {65}}\dots\endgraf
\noindent\phantom{$\log 2$}${}\approx{}$\printnumber{\LogTwo {70}}\dots\endgraf
\end{everbatim*}
Here is the code doing an exact evaluation of the partial sums. We have
added a |+1| to the number of digits for estimating the number of terms
to keep from the log series: we experimented that this gets exactly the
first |D| digits, for all values from |D=0| to |D=100|, except in one
case (|D=40|) where the last digit is wrong. For values of |D|
higher than |100| it is more efficient to use the code using
\csa{xintFxPtPowerSeries}.
\everb|@
\def\LogTwo #1% get log(2)=-2log(1-13/256)- 5log(1-1/9)
{%
\romannumeral0\expandafter\LogTwoDoIt \expandafter
{\the\numexpr (#1+1)*150/143\expandafter}\expandafter
{\the\numexpr (#1+1)*100/129\expandafter}\expandafter
{\the\numexpr #1\relax}%
}%
\def\LogTwoDoIt #1#2#3%
{% #3=nb of digits for truncating an EXACT partial sum
\xinttrunc {#3}
{\xintAdd
{\xintMul {2}{\xintPowerSeries {1}{#2}{\coefflog}{\xa}}}
{\xintMul {5}{\xintPowerSeries {1}{#1}{\coefflog}{\xb}}}%
}%
}%
|
Let us turn now to Pi, computed with the Machin formula (but see also the
approach via the \hyperlink{BrentSalamin}{Brent-Salamin algorithm} with
\csa{xintfloatexpr}) Again the numbers of terms to keep in the two |arctg|
series were roughly estimated, and some experimentations showed that removing
the last three digits was enough (at least for |D=0-100| range). And the
algorithm does print the correct digits when used with |D=1000| (to be
convinced of that one needs to run it for |D=1000| and again, say for
|D=1010|.) A theoretical analysis could help confirm that this algorithm
always gets better than |10^{-D}| precision, but again, strings of zeroes or
nines encountered in the decimal expansion may falsify the ending digits,
nines may be zeroes (and the last non-nine one should be increased) and zeroes
may be nine (and the last non-zero one should be decreased).
\hypertarget{MachinCode}{}
\begin{everbatim*}
\def\coeffarctg #1{\the\numexpr\ifodd#1 -1\else1\fi\relax/%
\the\numexpr 2*#1+1\relax [0]}%
%\def\coeffarctg #1{\romannumeral0\xintmon{#1}/\the\numexpr 2*#1+1\relax }%
\def\xa {1/25[0]}% 1/5^2, the [0] for faster parsing
\def\xb {1/57121[0]}% 1/239^2, the [0] for faster parsing
\def\Machin #1{% #1 may be a count register, \Machin {\mycount} is allowed
\romannumeral0\expandafter\MachinA \expandafter
% number of terms for arctg(1/5):
{\the\numexpr (#1+3)*5/7\expandafter}\expandafter
% number of terms for arctg(1/239):
{\the\numexpr (#1+3)*10/45\expandafter}\expandafter
% do the computations with 3 additional digits:
{\the\numexpr #1+3\expandafter}\expandafter
% allow #1 to be a count register:
{\the\numexpr #1\relax }}%
\def\MachinA #1#2#3#4%
{\xinttrunc {#4}
{\xintSub
{\xintMul {16/5}{\xintFxPtPowerSeries {0}{#1}{\coeffarctg}{\xa}{#3}}}
{\xintMul{4/239}{\xintFxPtPowerSeries {0}{#2}{\coeffarctg}{\xb}{#3}}}%
}}%
\begin{framed}
\[ \pi = \Machin {60}\dots \]
\end{framed}
\end{everbatim*}
Here is a variant|\MachinBis|,
which evaluates the partial sums \emph{exactly} using
\csa{xintPowerSeries}, before their final truncation. No need for a
``|+3|'' then.
\begin{everbatim*}
\def\MachinBis #1{% #1 may be a count register,
% the final result will be truncated to #1 digits post decimal point
\romannumeral0\expandafter\MachinBisA \expandafter
% number of terms for arctg(1/5):
{\the\numexpr #1*5/7\expandafter}\expandafter
% number of terms for arctg(1/239):
{\the\numexpr #1*10/45\expandafter}\expandafter
% allow #1 to be a count register:
{\the\numexpr #1\relax }}%
\def\MachinBisA #1#2#3%
{\xinttrunc {#3} %
{\xintSub
{\xintMul {16/5}{\xintPowerSeries {0}{#1}{\coeffarctg}{\xa}}}
{\xintMul{4/239}{\xintPowerSeries {0}{#2}{\coeffarctg}{\xb}}}%
}}%
\end{everbatim*}
Let us use this variant for a loop showing the build-up of digits:
\begin{everbatim*}
\begin{multicols}{2}
\cnta 0 % previously declared \count register
\loop \noindent
\centeredline{\dtt{\MachinBis{\cnta}}}%
\ifnum\cnta < 30
\advance\cnta 1 \repeat
\end{multicols}
\end{everbatim*}
\hypertarget{Machin1000}{}
%
You want more digits and have some time? compile this copy of the
\hyperlink{MachinCode}{|\Machin|} with |etex| (or |pdftex|):
%
\everb|@
% Compile with e-TeX extensions enabled (etex, pdftex, ...)
\input xintfrac.sty
\input xintseries.sty
% pi = 16 Arctg(1/5) - 4 Arctg(1/239) (John Machin's formula)
\def\coeffarctg #1{\the\numexpr\ifodd#1 -1\else1\fi\relax/%
\the\numexpr 2*#1+1\relax [0]}%
\def\xa {1/25[0]}%
\def\xb {1/57121[0]}%
\def\Machin #1{%
\romannumeral0\expandafter\MachinA \expandafter
{\the\numexpr (#1+3)*5/7\expandafter}\expandafter
{\the\numexpr (#1+3)*10/45\expandafter}\expandafter
{\the\numexpr #1+3\expandafter}\expandafter
{\the\numexpr #1\relax }}%
\def\MachinA #1#2#3#4%
{\xinttrunc {#4}
{\xintSub
{\xintMul {16/5}{\xintFxPtPowerSeries {0}{#1}{\coeffarctg}{\xa}{#3}}}
{\xintMul {4/239}{\xintFxPtPowerSeries {0}{#2}{\coeffarctg}{\xb}{#3}}}%
}}%
\pdfresettimer
\fdef\Z {\Machin {1000}}
\odef\W {\the\pdfelapsedtime}
\message{\Z}
\message{computed in \xintRound {2}{\W/65536} seconds.}
\bye
|
This will log the first 1000 digits of $\pi$ after the decimal point. On my
laptop (a 2012 model) this took about $5.6$ seconds last time I tried.%
%
\footnote{With \texttt{1.09i} and earlier \xintname, this used to be \dtt{42}
seconds; starting with \texttt{1.09j}, and prior to \texttt{1.2}, it was
\dtt{16} seconds (this was probably due to a more efficient division with
denominators at most $9999$). The |1.2| \xintcorename achieves a further
gain at \dtt{5.6} seconds.}
%
\footnote{With |\xintDigits:=1001;|, the non-optimized implementation with the
|iter| of \xintexprname fame using the
\hyperlink{BrentSalamin}{Brent-Salamin algorithm}, took, last time I tried
(1.2g), about \dtt{7.4} seconds on my laptop (the last two digits were
wrong, which is ok as they serve as guard digits), and for obtaining about
\dtt{500} digits, it was of \dtt{1.6}s. This is not bad, taking into account
that the syntax is almost free rolling speech, contrarily to the code above
for the Machin formula computation; we would like to use the quadratically
convergent Brent-Salamin algorithm for more digits, but with such
computations with numbers of one thousand digits we are beyond the border of
the reasonable range for \xintname. Innocent people not knowing what it
means to compute with \TeX, and with the extra constraint of expandability
will wonder why this is at least thousands of times slower than with any
other language (with a little Python program using the |Decimal| library, I
timed the Brent-Salamin algorithm to \dtt{4.4ms} for about |1000| digits and
\dtt{1.14ms} for |500| digits.) I will just say that for example digits are
represented and manipulated via their ascii-code ! all computations must
convert from ascii-code to cpu words; furthermore nothing can be stored
away. And there is no memory storage with |O(1)| time access... if
expandability is to be verified.}
%
As mentioned in the
introduction, the file \href{http://www.ctan.org/pkg/pi}{pi.tex} by \textsc{D.
Roegel} shows that orders of magnitude faster computations are possible within
\TeX{}, but recall our constraints of complete expandability and be merciful,
please.
\textbf{Why truncating rather than rounding?} One of our main competitors
on the market of scientific computing, a canadian product (not
encumbered with expandability constraints, and having barely ever heard
of \TeX{} ;-), prints numbers rounded in the last digit. Why didn't we
follow suit in the macros \csa{xintFxPtPowerSeries} and
\csa{xintFxPtPowerSeriesX}? To round at |D| digits, and excluding a
rewrite or cloning of the division algorithm which anyhow would add to
it some overhead in its final steps, \xintfracname needs to truncate at
|D+1|, then round. And rounding loses information! So, with more time
spent, we obtain a worst result than the one truncated at |D+1| (one
could imagine that additions and so on, done with only |D| digits, cost
less; true, but this is a negligeable effect per summand compared to the
additional cost for this term of having been truncated at |D+1| then
rounded). Rounding is the way to go when setting up algorithms to
evaluate functions destined to be composed one after the other: exact
algebraic operations with many summands and an |f| variable which is a
fraction are costly and create an even bigger fraction; replacing |f|
with a reasonable rounding, and rounding the result, is necessary to
allow arbitrary chaining.
But, for the
computation of a single constant, we are really interested in the exact
decimal expansion, so we truncate and compute more terms until the
earlier result gets validated. Finally if we do want the rounding we can
always do it on a value computed with |D+1| truncation.
\clearpage
\section{Commands of the \xintcfracname package}
\label{sec:cfrac}
\localtableofcontents
This package was first included in release |1.04| (|2013/04/25|) of the
\xintname bundle. It was kept almost unchanged until |1.09m| of |2014/02/26|
which brings some new macros: \csbxint{FtoC}, \csbxint{CtoF}, \csbxint{CtoCv},
dealing with sequences of braced partial quotients rather than comma separated
ones, \csbxint{FGtoC} which is to produce ``guaranteed'' coefficients of some
real number known approximately, and \csbxint{GGCFrac} for displaying arbitrary
material as a continued fraction; also, some changes to existing macros:
\csbxint{FtoCs} and \csbxint{CntoCs} insert spaces after the commas,
\csbxint{CstoF} and \csbxint{CstoCv} authorize spaces in the input also before
the commas.
This section contains:
\begin{enumerate}
\item an \hyperref[ssec:cfracoverview]{overview} of the package functionalities,
\item a description of each one of the package macros,
\item further illustration of their use via the study of the
\hyperref[ssec:e-convergents]{convergents of $e$}.
\end{enumerate}
\subsection{Package overview}\label{ssec:cfracoverview}
The package computes partial quotients and convergents of a fraction, or
conversely start from coefficients and obtain the corresponding fraction; three
macros \csbxint {CFrac}, \csbxint {GCFrac} and \csbxint {GGCFrac} are
for typesetting (the first two assume that the coefficients are numeric
quantities acceptable by the \xintfracname \csbxint{Frac} macro, the
last one will display arbitrary material), the others
can be nested (if applicable) or see their outputs further processed by other
macros from the \xintname bundle, particularly the macros of \xinttoolsname
dealing with sequences of braced items or comma separated lists.
A \emph{simple} continued fraction has coefficients
|[c0,c1,...,cN]| (usually called partial quotients, but I
dislike this entrenched terminology), where |c0| is a positive or
negative integer and the others are positive integers.
Typesetting is usually done via the |amsmath| macro |\cfrac|:
\begin{everbatim*}
\[ c_0 + \cfrac{1}{c_1+\cfrac1{c_2+\cfrac1{c_3+\cfrac1{\ddots}}}}\]
\end{everbatim*}
Here is a concrete example:
\begin{everbatim*}
\[ \xintFrac {208341/66317}=\xintCFrac {208341/66317}\]%
\end{everbatim*}
But it is the command \csbxint{CFrac} which did all the work of \emph{computing}
the continued fraction \emph{and} using |\cfrac| from |amsmath| to typeset
it.
A \emph{generalized} continued fraction has the same structure but the
numerators are not restricted to be $1$, and numbers used in the continued
fraction may be arbitrary, also fractions, irrationals, complex,
indeterminates.%
%
\footnote{\xintcfracname may be used with indeterminates,
for basic conversions from one inline format to another, but not for
actual computations. See \csbxint{GGCFrac}.}
%
The \emph{centered} continued fraction is an
example:
\begin{everbatim*}
\[ \xintFrac {915286/188421}=\xintGCFrac {5+-1/7+1/39+-1/53+-1/13}
=\xintCFrac {915286/188421}\]
\end{everbatim*}
The command \csbxint{GCFrac}, contrarily to
\csbxint{CFrac}, does not compute anything, it just typesets starting from a
generalized continued fraction in inline format, which in this example
was input literally. We also used \csa{xintCFrac}
for comparison of the two types of continued fractions.
To let \TeX{} compute the centered continued fraction of |f| there is
\csbxint{FtoCC}:
\begin{everbatim*}
\[\xintFrac {915286/188421}\to\xintFtoCC {915286/188421}\]
\end{everbatim*}
The package macros are expandable and may be nested (naturally \csa{xintCFrac}
and \csa{xintGCFrac} must be at the top level, as they deal with typesetting).
\begin{everbatim*}
\[\xintGCFrac {\xintFtoCC{915286/188421}}\]
\end{everbatim*}
The `inline' format expected on input by \csbxint{GCFrac} is
%
\leftedline{$a_0+b_0/a_1+b_1/a_2+b_2/a_3+\cdots+b_{n-2}/a_{n-1}+b_{n-1}/a_n$}
%
Fractions among the coefficients are allowed but they must be enclosed
within braces. Signed integers may be left without braces (but the |+|
signs are mandatory). No spaces are allowed around the plus and fraction
symbols. The coefficients may themselves be macros, as long as these
macros are \fexpan dable.
\begin{everbatim*}
\[ \xintFrac{\xintGCtoF {1+-1/57+\xintPow {-3}{7}/\xintiQuo {132}{25}}}
= \xintGCFrac {1+-1/57+\xintPow {-3}{7}/\xintiQuo {132}{25}}\]
\end{everbatim*}
To compute the actual fraction one has \csbxint{GCtoF}:
\begin{everbatim*}
\[\xintFrac{\xintGCtoF {1+-1/57+\xintPow {-3}{7}/\xintiQuo {132}{25}}}\]
\end{everbatim*}
For non-numeric input there is \csbxint{GGCFrac}.
\begin{everbatim*}
\[\xintGGCFrac {a_0+b_0/a_1+b_1/a_2+b_2/\ddots+\ddots/a_{n-1}+b_{n-1}/a_n}\]
\end{everbatim*}
For regular continued fractions, there is a simpler comma separated format:
\begin{everbatim*}
\[-7,6,19,1,33\to\xintFrac{\xintCstoF{-7,6,19,1,33}}=\xintCFrac{\xintCstoF{-7,6,19,1,33}}\]
\end{everbatim*}
The command \csbxint{FtoCs} produces from a fraction |f| the comma separated
list of its coefficients.
\begin{everbatim*}
\[\xintFrac{1084483/398959}=[\xintFtoCs{1084483/398959}]\]
\end{everbatim*}
If one prefers other separators, one can use the two arguments macros
\csbxint{FtoCx} whose first argument is the separator (which may consist of more
than one token) which is to be used.
\begin{everbatim*}
\[\xintFrac{2721/1001}=\xintFtoCx {+1/(}{2721/1001})\cdots)\]
\end{everbatim*}
This allows under Plain \TeX{} with |amstex| to obtain the same effect
as with \LaTeX{}+|\amsmath|+\csbxint{CFrac}:
%
\leftedline{|$$\xintFwOver{2721/1001}=\xintFtoCx {+\cfrac1\\ }{2721/1001}\endcfrac$$|}
As a shortcut to \csa{xintFtoCx} with separator |1+/|, there is
\csbxint{FtoGC}:
\begin{everbatim*}
2721/1001=\xintFtoGC {2721/1001}
\end{everbatim*}
Let us compare in that case with the output of \csbxint{FtoCC}:
\begin{everbatim*}
2721/1001=\xintFtoCC {2721/1001}
\end{everbatim*}
To obtain the coefficients as a sequence of braced numbers, there is
\csbxint{FtoC} (this is a shortcut for |\xintFtoCx {}|). This list
(sequence) may then be manipulated using the various macros of \xinttoolsname
such as the non-expandable macro \csbxint{AssignArray} or the expandable
\csbxint{Apply} and \csbxint{ListWithSep}.
Conversely to go from such a sequence of braced coefficients to the
corresponding fraction there is \csbxint{CtoF}.
The `|\printnumber|' (\autoref{ssec:printnumber}) macro which we use in this
document to print long numbers can also be useful on long continued fractions.
%
\begin{everbatim*}
\printnumber{\xintFtoCC {35037018906350720204351049/244241737886197404558180}}
\end{everbatim*}
%
If we apply \csbxint{GCtoF} to this generalized continued fraction, we
discover that the original fraction was reducible:
%
\leftedline{|\xintGCtoF
{143+1/2+...+-1/9}|\dtt{=\xintGCtoF{143+1/2+1/5+-1/4+-1/4+-1/4+-1/3+1/2+1/2+1/6+-1/22+1/2+1/10+-1/5+-1/11+-1/3+1/4+-1/2+1/2+1/4+-1/2+1/23+1/3+1/8+-1/6+-1/9}}}
\def\mymacro #1{$\xintFrac{#1}=[\xintFtoCs{#1}]$\vtop to 6pt{}}
\begingroup
\catcode`^\active
\def^#1^{\hbox{#1}}%
When a generalized continued fraction is built with integers, and
numerators are only |1|'s or |-1|'s, the produced fraction is
irreducible. And if we compute it again with the last sub-fraction
omitted we get another irreducible fraction related to the bigger one by
a Bezout identity. Doing this here we get:
%
\leftedline{|\xintGCtoF {143+1/2+...+-1/6}|\dtt{=\xintGCtoF{143+1/2+1/5+-1/4+-1/4+-1/4+-1/3+1/2+1/2+1/6+-1/22+1/2+1/10+-1/5+-1/11+-1/3+1/4+-1/2+1/2+1/4+-1/2+1/23+1/3+1/8+-1/6}}}
and indeed:
\[\begin{vmatrix}
^2897319801297630107^ & ^328124887710626729^\\
^20197107104701740^ & ^2287346221788023^
\end{vmatrix} = \mbox{\dtt{\xintiSub {\xintiMul {2897319801297630107}{2287346221788023}}{\xintiMul{20197107104701740}{328124887710626729}}}}\]
\endgroup
The various fractions obtained from the truncation of a continued fraction to
its initial terms are called the convergents. The commands of \xintcfracname
such as \csbxint{FtoCv}, \csbxint{FtoCCv}, and others which compute such
convergents, return them as a list of braced items, with no separator (as does
\csbxint {FtoC} for the partial quotients). Here is an example:
\begin{everbatim*}
\[\xintFrac{915286/188421}\to
\xintListWithSep{,}{\xintApply\xintFrac{\xintFtoCv{915286/188421}}}\]
\end{everbatim*}
\begin{everbatim*}
\[\xintFrac{915286/188421}\to
\xintListWithSep{,}{\xintApply\xintFrac{\xintFtoCCv{915286/188421}}}\]
\end{everbatim*}
%
We thus see that the `centered convergents' obtained with \csbxint{FtoCCv} are
among the fuller list of convergents as returned by \csbxint{FtoCv}.
Here is a more complicated use of \csa{xintApply}
and \csa{xintListWithSep}. We first define a macro which will be applied to each
convergent:%
%
\leftedline{|\newcommand{\mymacro}[1]{$\xintFrac{#1}=[\xintFtoCs{#1}]$\vtop to 6pt{}}|}
%
Next, we use the following code:
%
\leftedline{|$\xintFrac{49171/18089}\to{}$|}
%
\leftedline{|\xintListWithSep {,
}{\xintApply{\mymacro}{\xintFtoCv{49171/18089}}}|}
It produces:\par
\noindent$ \xintFrac{49171/18089}\to {}$\xintListWithSep {,
}{\xintApply{\mymacro}{\xintFtoCv{49171/18089}}}.
The macro \csbxint{CntoF} allows to specify the coefficients as a function given
by a one-parameter macro. The produced values do not have to be integers.
\begin{everbatim*}
\def\cn #1{\xintiiPow {2}{#1}}% 2^n
\[\xintFrac{\xintCntoF {6}{\cn}}=\xintCFrac [l]{\xintCntoF {6}{\cn}}\]
\end{everbatim*}
Notice the use of the optional argument |[l]| to \csa{xintCFrac}. Other
possibilities are |[r]| and (default) |[c]|.
\begin{everbatim*}
\def\cn #1{\xintPow {2}{-#1}}%
\[\xintFrac{\xintCntoF {6}{\cn}}=\xintGCFrac [r]{\xintCntoGC {6}{\cn}}=
[\xintFtoCs {\xintCntoF {6}{\cn}}]\]
\end{everbatim*}
We used \csbxint{CntoGC} as we wanted to display also the continued fraction and
not only the fraction returned by \csa{xintCntoF}.
There are also \csbxint{GCntoF} and \csbxint{GCntoGC} which allow the same for
generalized fractions. An initial portion of a generalized continued
fraction for $\pi$ is obtained like this
\begin{everbatim*}
\def\an #1{\the\numexpr 2*#1+1\relax }%
\def\bn #1{\the\numexpr (#1+1)*(#1+1)\relax }%
\[\xintFrac{\xintDiv {4}{\xintGCntoF {5}{\an}{\bn}}} =
\cfrac{4}{\xintGCFrac{\xintGCntoGC {5}{\an}{\bn}}} =
\xintTrunc {10}{\xintDiv {4}{\xintGCntoF {5}{\an}{\bn}}}\dots\]
\end{everbatim*}
We see that the quality of approximation is not fantastic compared to the simple
continued fraction of $\pi$ with about as many terms:
\begin{everbatim*}
\[\xintFrac{\xintCstoF{3,7,15,1,292,1,1}}=
\xintGCFrac{3+1/7+1/15+1/1+1/292+1/1+1/1}=
\xintTrunc{10}{\xintCstoF{3,7,15,1,292,1,1}}\dots\]
\end{everbatim*}
When studying the continued fraction of some real number, there is always
some doubt about how many terms are valid, when computed starting from some
approximation. If $f\leqslant x\leqslant g$ and $f, g$ both have the
same first $K$ partial quotients, then $x$ also has the same first $K$ quotients
and convergents. The macro \csbxint{FGtoC} outputs as a sequence of braced items
the common partial quotients of its two arguments. We can thus use it to produce
a sure list of valid convergents of $\pi$ for example, starting from some proven
lower and upper bound:
\begin{everbatim*}
$$\pi\to [\xintListWithSep{,}
{\xintFGtoC {3.14159265358979323}{3.14159265358979324}}, \dots]$$
\noindent$\pi\to\xintListWithSep{,\allowbreak\;}
{\xintApply{\xintFrac}
{\xintCtoCv{\xintFGtoC {3.14159265358979323}{3.14159265358979324}}}}, \dots$
\end{everbatim*}
\subsection{\csbh{xintCFrac}}\label{xintCFrac}
\csa{xintCFrac}|{f}|\ntype{\Ff} is a math-mode only, \LaTeX{} with |amsmath|
only, macro which first computes then displays with the help of |\cfrac| the
simple continued fraction corresponding to the given fraction. It admits an
optional argument which may be |[l]|, |[r]| or (the default) |[c]| to specify
the location of the one's in the numerators of the sub-fractions. Each
coefficient is typeset using the \csbxint{Frac} macro from the \xintfracname
package. This macro is \fexpan dable in the sense that it prepares expandably
the whole expression with the multiple |\cfrac|'s, but it is not completely
expandable naturally as |\cfrac| isn't.
\subsection{\csbh{xintGCFrac}}\label{xintGCFrac}
\csa{xintGCFrac}|{a+b/c+d/e+f/g+h/...+x/y}|\ntype{f} uses similarly |\cfrac|
to prepare the typesetting with the |amsmath| |\cfrac| (\LaTeX{}) of a
generalized continued fraction given in inline format (or as macro which
will \fexpan d to it). It admits the
same optional argument as \csa{xintCFrac}. Plain \TeX{} with |amstex|
users, see \csbxint{GCtoGCx}.
\begin{everbatim*}
\[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}}\]
\end{everbatim*}
This is mostly a typesetting macro, although it does provoke the
expansion of the coefficients. See \csbxint{GCtoF} if you are impatient
to see this specific fraction computed.
It admits an optional argument within square brackets which may be
either |[l]|, |[c]| or |[r]|. Default is |[c]| (numerators are centered).
Numerators and denominators are made arguments to the \csbxint{Frac}
macro. This allows them to be themselves fractions or anything \fexpan
dable giving numbers or fractions, but also means however that they can
not be arbitrary material, they can not contain color changing commands
for example. One of the reasons is that \csa{xintGCFrac} tries to
determine the signs of the numerators and chooses accordingly to use
$+$ or $-$.
\subsection{\csbh{xintGGCFrac}}\label{xintGGCFrac}
\csa{xintGGCFrac}|{a+b/c+d/e+f/g+h/...+x/y}|\ntype{f} is a clone of
\csbxint{GCFrac}, hence again \LaTeX{} specific with package
|amsmath|.
It does not assume the coefficients to be numbers as understood by
\xintfracname. The macro can be used for displaying arbitrary content as
a continued fraction with |\cfrac|, using only plus signs though. Note
though that it will first \fexpan d its argument, which may be thus be
one of the \xintcfracname macros producing a (general) continued
fraction in inline format, see \csbxint{FtoCx} for an example. If this
expansion is not wished, it is enough to start the argument with a
space.
\begin{everbatim*}
\[\xintGGCFrac {1+q/1+q^2/1+q^3/1+q^4/1+q^5/\ddots}\]
\end{everbatim*}
\subsection{\csbh{xintGCtoGCx}}\label{xintGCtoGCx}
%{\small New with release |1.05|.\par}
\csa{xintGCtoGCx}|{sepa}{sepb}{a+b/c+d/e+f/...+x/y}|\etype{nnf} returns the list
of the coefficients of the generalized continued fraction of |f|, each one
within a pair of braces, and separated with the help of |sepa| and |sepb|. Thus
%
\leftedline{|\xintGCtoGCx :;{1+2/3+4/5+6/7}| gives \xintGCtoGCx
:;{1+2/3+4/5+6/7}}
%
The following can be used byt Plain \TeX{}+|amstex| users to obtain an
output similar as the ones produced by \csbxint{GCFrac} and
\csbxint{GGCFrac}:\par
\everb|@
$$\xintGCtoGCx {+\cfrac}{\\}{a+b/...}\endcfrac$$
$$\xintGCtoGCx {+\cfrac\xintFwOver}{\\\xintFwOver}{a+b/...}\endcfrac$$
|
\subsection{\csbh{xintFtoC}}\label{xintFtoC}
\csa{xintFtoC}|{f}|\etype{\Ff} computes the
coefficients of the simple continued fraction of |f| and returns them as a list
(sequence) of braced items.
\begin{everbatim*}
\fdef\test{\xintFtoC{-5262046/89233}}\texttt{\meaning\test}
\end{everbatim*}
\subsection{\csbh{xintFtoCs}}\label{xintFtoCs}
\csa{xintFtoCs}|{f}|\etype{\Ff} returns the comma separated list of the
coefficients of the simple continued fraction of |f|. Notice that starting with
|1.09m| a space follows each comma (mainly for usage in text mode, as in math
mode spaces are produced in the typeset output by \TeX{} itself).
\begin{everbatim*}
\[ \xintSignedFrac{-5262046/89233} \to [\xintFtoCs{-5262046/89233}]\]
\end{everbatim*}
\subsection{\csbh{xintFtoCx}}\label{xintFtoCx}
\csa{xintFtoCx}|{sep}{f}|\etype{n\Ff} returns the list of the
coefficients of the simple continued fraction of |f| separated with the
help of |sep|, which may be anything (and is kept unexpanded). For
example, with Plain \TeX{} and |amstex|,
%
\leftedline{|$$\xintFtoCx {+\cfrac1\\ }{-5262046/89233}\endcfrac$$|}
%
will display the continued fraction using
|\cfrac|. Each coefficient is inside a brace pair \hbox{|{ }|}, allowing
a macro to end the separator and fetch it as argument,
for example, again with Plain \TeX{} and |amstex|:
\everb|@
\def\highlight #1{\ifnum #1>200 \textcolor{red}{#1}\else #1\fi}
$$\xintFtoCx {+\cfrac1\\ \highlight}{104348/33215}\endcfrac$$
|
Due to the different and extremely cumbersome syntax of |\cfrac| under
\LaTeX{} it proves a bit tortuous to obtain there the same effect.
Actually, it is partly for this purpose that |1.09m| added \csbxint
{GGCFrac}. We thus use \csa{xintFtoCx} with a suitable separator, and\;
then the whole thing as argument to \csbxint{GGCFrac}:
\begin{everbatim*}
\def\highlight #1{\ifnum #1>200 \fcolorbox{blue}{white}{\boldmath\color{red}$#1$}%
\else #1\fi}
\[\xintGGCFrac {\xintFtoCx {+1/\highlight}{208341/66317}}\]
\end{everbatim*}
\subsection{\csbh{xintFtoGC}}\label{xintFtoGC}
\csa{xintFtoGC}|{f}|\etype{\Ff} does the same as \csa{xintFtoCx}|{+1/}{f}|. Its
output may thus be used in the package macros expecting such an `inline
format'.
% This continued fraction is a \emph{simple} one, not a
% \emph{generalized} one, but as it is produced in the format used for
% user input of generalized continued fractions, the macro was called
% \csa{xintFtoGC} rather than \csa{xintFtoC} for example.
%
\begin{everbatim*}
566827/208524=\xintFtoGC {566827/208524}
\end{everbatim*}
\subsection{\csbh{xintFGtoC}}\label{xintFGtoC}
\csa{xintFGtoC}|{f}{g}|\etype{\Ff\Ff} computes the common initial coefficients
to
two given fractions |f| and |g|. Notice that any real number |f<x<g| or |f>x>g|
will then necessarily share with |f| and |g| these common initial coefficients
for its regular continued fraction. The coefficients are output as a sequence of
braced numbers. This list can then be manipulated via macros from
\xinttoolsname, or other macros of \xintcfracname.
\begin{everbatim*}
\fdef\test{\xintFGtoC{-5262046/89233}{-5314647/90125}}\texttt{\meaning\test}
\end{everbatim*}
\begin{everbatim*}
\fdef\test{\xintFGtoC{3.141592653}{3.141592654}}\texttt{\meaning\test}
\end{everbatim*}
\begin{everbatim*}
\fdef\test{\xintFGtoC{3.1415926535897932384}{3.1415926535897932385}}\meaning\test
\end{everbatim*}
\begin{everbatim*}
\xintRound {30}{\xintCstoF{\xintListWithSep{,}{\test}}}
\end{everbatim*}
\begin{everbatim*}
\xintRound {30}{\xintCtoF{\test}}
\end{everbatim*}
\begin{everbatim*}
\fdef\test{\xintFGtoC{1.41421356237309}{1.4142135623731}}\meaning\test
\end{everbatim*}
\subsection{\csbh{xintFtoCC}}\label{xintFtoCC}
\csa{xintFtoCC}|{f}|\etype{\Ff} returns the `centered' continued fraction of
|f|, in `inline format'. %
\begin{everbatim*}
566827/208524=\xintFtoCC {566827/208524}
\end{everbatim*}
\begin{everbatim*}
\[\xintFrac{566827/208524} = \xintGCFrac{\xintFtoCC{566827/208524}}\]
\end{everbatim*}
\subsection{\csbh{xintCstoF}}\label{xintCstoF}
\csa{xintCstoF}|{a,b,c,d,...,z}|\etype{f} computes the fraction corresponding to
the coefficients, which may be fractions or even macros expanding to such
fractions. The final fraction may then be highly reducible. Starting with
release |1.09m| spaces before commas are allowed and trimmed automatically
(spaces after commas were already silently handled in earlier releases).
\begin{everbatim*}
\[\xintGCFrac {-1+1/3+1/-5+1/7+1/-9+1/11+1/-13}=
\xintSignedFrac{\xintCstoF {-1,3,-5,7,-9,11,-13}}=\xintSignedFrac{\xintGCtoF
{-1+1/3+1/-5+1/7+1/-9+1/11+1/-13}}\]
\end{everbatim*}
\begin{everbatim*}
\[\xintGCFrac{{1/2}+1/{1/3}+1/{1/4}+1/{1/5}}=\xintFrac{\xintCstoF {1/2,1/3,1/4,1/5}}\]
\end{everbatim*}
%
A generalized continued fraction may produce a reducible fraction
(\csa{xintCstoF} tries its best not to accumulate in a silly way superfluous
factors but will not do simplifications which would be obvious to a human, like
simplification by 3 in the result above).
\subsection{\csbh{xintCtoF}}\label{xintCtoF}
\csa{xintCtoF}|{{a}{b}{c}...{z}}|\etype{f} computes the fraction corresponding
to the coefficients, which may be fractions or even macros.
\begin{everbatim*}
\xintCtoF {\xintApply {\xintiiPow 3}{\xintSeq {1}{5}}}
\end{everbatim*}
\begin{everbatim*}
\[ \xintFrac{14946960/4805083}=\xintCFrac {14946960/4805083}\]
\end{everbatim*}
In the example above the power of $3$ was already pre-computed via the expansion
done by |\xintApply|, but if we try with |\xintApply { \xintiiPow 3}| where the
space will stop this expansion, we can check that |\xintCtoF| will itself
provoke the needed coefficient expansion.% ok
\subsection{\csbh{xintGCtoF}}\label{xintGCtoF}
\csa{xintGCtoF}|{a+b/c+d/e+f/g+......+v/w+x/y}|\etype{f} computes the fraction
defined by the inline generalized continued fraction. Coefficients may be
fractions but must then be put within braces. They can be macros. The plus signs
are mandatory.
\begin{everbatim*}
\[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}} =
\xintFrac{\xintGCtoF {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}}} =
\xintFrac{\xintIrr{\xintGCtoF
{1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}}}}\]
\end{everbatim*}
\begin{everbatim*}
\[ \xintGCFrac{{1/2}+{2/3}/{4/5}+{1/2}/{1/5}+{3/2}/{5/3}} =
\xintFrac{\xintGCtoF {{1/2}+{2/3}/{4/5}+{1/2}/{1/5}+{3/2}/{5/3}}} \]
\end{everbatim*}
The macro tries its best not to accumulate superfluous factor in the
denominators, but doesn't reduce the fraction to irreducible form before
returning it and does not do simplifications which would be obvious to a human.
\subsection{\csbh{xintCstoCv}}\label{xintCstoCv}
\csa{xintCstoCv}|{a,b,c,d,...,z}|\etype{f} returns the sequence of the
corresponding convergents, each one within braces.
It is allowed to use fractions as coefficients (the computed
convergents have then no reason to be the real convergents of the final
fraction). When the coefficients are integers, the convergents are irreducible
fractions, but otherwise it is not necessarily the case.
\begin{everbatim*}
\xintListWithSep:{\xintCstoCv{1,2,3,4,5,6}}
\end{everbatim*}
\begin{everbatim*}
\xintListWithSep:{\xintCstoCv{1,1/2,1/3,1/4,1/5,1/6}}
\end{everbatim*}
\begin{everbatim*}
\[\xintListWithSep{\to}{\xintApply\xintFrac{\xintCstoCv {\xintPow
{-.3}{-5},7.3/4.57,\xintCstoF{3/4,9,-1/3}}}}\]
\end{everbatim*}
\subsection{\csbh{xintCtoCv}}\label{xintCtoCv}
\csa{xintCtoCv}|{{a}{b}{c}...{z}}|\etype{f} returns the sequence of the
corresponding convergents, each one within braces.
\begin{everbatim*}
\fdef\test{\xintCtoCv {11111111111}}\texttt{\meaning\test}
\end{everbatim*}
\subsection{\csbh{xintGCtoCv}}\label{xintGCtoCv}
\csa{xintGCtoCv}|{a+b/c+d/e+f/g+......+v/w+x/y}|\etype{f} returns the list of
the corresponding convergents. The coefficients may be fractions, but must then
be inside braces. Or they may be macros, too.
The convergents will in the general case be reducible. To put them into
irreducible form, one needs one more step, for example it can be done
with |\xintApply\xintIrr|.
\begin{everbatim*}
\[\xintListWithSep{,}{\xintApply\xintFrac
{\xintGCtoCv{3+{-2}/{7/2}+{3/4}/12+{-56}/3}}}\]
\[\xintListWithSep{,}{\xintApply\xintFrac{\xintApply\xintIrr
{\xintGCtoCv{3+{-2}/{7/2}+{3/4}/12+{-56}/3}}}}\]
\end{everbatim*}
\subsection{\csbh{xintFtoCv}}\label{xintFtoCv}
\csa{xintFtoCv}|{f}|\etype{\Ff} returns the list of the (braced) convergents of
|f|, with no separator. To be treated with \csbxint{AssignArray} or
\csbxint{ListWithSep}.
\begin{everbatim*}
\[\xintListWithSep{\to}{\xintApply\xintFrac{\xintFtoCv{5211/3748}}}\]
\end{everbatim*}
\subsection{\csbh{xintFtoCCv}}\label{xintFtoCCv}
\csa{xintFtoCCv}|{f}|\etype{\Ff} returns the list of the (braced) centered
convergents of |f|, with no separator. To be treated with \csbxint{AssignArray}
or \csbxint{ListWithSep}.
\begin{everbatim*}
\[\xintListWithSep{\to}{\xintApply\xintFrac{\xintFtoCCv{5211/3748}}}\]
\end{everbatim*}
\subsection{\csbh{xintCntoF}}\label{xintCntoF}
\csa{xintCntoF}|{N}{\macro}|\etype{\numx f} computes the fraction |f| having
coefficients |c(j)=\macro{j}| for |j=0,1,...,N|. The |N| parameter is given to a
|\numexpr|. The values of the coefficients, as returned by |\macro| do not have
to be positive, nor integers, and it is thus not necessarily the case that the
original |c(j)| are the true coefficients of the final |f|.
\begin{everbatim*}
\def\macro #1{\the\numexpr 1+#1*#1\relax} \xintCntoF {5}{\macro}
\end{everbatim*}
This example shows that the fraction is output with a trailing number in square
brackets (representing a power of ten), this is for consistency with what do
most macros of \xintfracname, and does not have to be always this annoying |[0]|
as the coefficients may for example be numbers in scientific notation. To avoid
these trailing square brackets, for example if the coefficients are known to be integers, there is always the possibility to filter the output via
\csbxint{PRaw}, or \csbxint{Irr} (the latter is overkill in the case of integer
coefficients, as the fraction is guaranteed to be irreducible then).
\subsection{\csbh{xintGCntoF}}\label{xintGCntoF}
\csa{xintGCntoF}|{N}{\macroA}{\macroB}|\etype{\numx ff} returns the fraction |f|
corresponding to the inline generalized continued fraction
|a0+b0/a1+b1/a2+....+b(N-1)/aN|, with |a(j)=\macroA{j}| and |b(j)=\macroB{j}|.
The |N| parameter is given to a |\numexpr|.
\begin{everbatim*}
\def\coeffA #1{\the\numexpr #1+4-3*((#1+2)/3)\relax }%
\def\coeffB #1{\the\numexpr \ifodd #1 -\fi 1\relax }% (-1)^n
\[\xintGCFrac{\xintGCntoGC {6}{\coeffA}{\coeffB}} =
\xintFrac{\xintGCntoF {6}{\coeffA}{\coeffB}}\]
\end{everbatim*}
There is also \csbxint{GCntoGC} to get the `inline format' continued
fraction.
\subsection{\csbh{xintCntoCs}}\label{xintCntoCs}
\csa{xintCntoCs}|{N}{\macro}|\etype{\numx f} produces the comma separated list
of the corresponding coefficients, from |n=0| to |n=N|. The |N| is given to a
|\numexpr|. %
\begin{everbatim*}
\xintCntoCs {5}{\macro}
\end{everbatim*}
\begin{everbatim*}
\[ \xintFrac{\xintCntoF{5}{\macro}}=\xintCFrac{\xintCntoF {5}{\macro}}\]
\end{everbatim*}
\subsection{\csbh{xintCntoGC}}\label{xintCntoGC}
%
\csa{xintCntoGC}|{N}{\macro}|\etype{\numx f} evaluates the |c(j)=\macro{j}| from
|j=0| to |j=N| and returns a continued fraction written in inline format:
|{c(0)}+1/{c(1)}+1/...+1/{c(N)}|. The parameter |N| is given to a |\numexpr|.
The coefficients, after expansion, are, as shown, being enclosed in an added
pair of braces, they may thus be fractions.
\begin{everbatim*}
\def\macro #1{\the\numexpr\ifodd#1 -1-#1\else1+#1\fi\relax/\the\numexpr 1+#1*#1\relax}
\fdef\x{\xintCntoGC {5}{\macro}}\meaning\x
\[\xintGCFrac{\xintCntoGC {5}{\macro}}\]
\end{everbatim*}
\subsection{\csbh{xintGCntoGC}}\label{xintGCntoGC}
\csa{xintGCntoGC}|{N}{\macroA}{\macroB}|\etype{\numx ff} evaluates the
coefficients and then returns the corresponding
|{a0}+{b0}/{a1}+{b1}/{a2}+...+{b(N-1)}/{aN}| inline generalized fraction. |N| is
givent to a |\numexpr|. The coefficients are enclosed into pairs
of braces, and may thus be fractions, the fraction slash will not be
confused in further processing by the continued fraction slashes.
%
\begin{everbatim*}
\def\an #1{\the\numexpr #1*#1*#1+1\relax}%
\def\bn #1{\the\numexpr \ifodd#1 -\fi 1*(#1+1)\relax}%
$\xintGCntoGC {5}{\an}{\bn}=\xintGCFrac {\xintGCntoGC {5}{\an}{\bn}} =
\displaystyle\xintFrac {\xintGCntoF {5}{\an}{\bn}}$\par
\end{everbatim*}
\subsection{\csbh{xintCstoGC}}\label{xintCstoGC}
\csa{xintCstoGC}|{a,b,..,z}|\etype{f} transforms a comma separated list (or
something expanding to such a list) into an `inline format' continued fraction
|{a}+1/{b}+1/...+1/{z}|. The coefficients are just copied and put within braces,
without expansion. The output can then be used in \csbxint{GCFrac} for example.
\begin{everbatim*}
\[\xintGCFrac {\xintCstoGC {-1,1/2,-1/3,1/4,-1/5}}=\xintSignedFrac{\xintCstoF {-1,1/2,-1/3,1/4,-1/5}}\]
\end{everbatim*}
\subsection{\csbh{xintiCstoF}, \csbh{xintiGCtoF}, \csbh{xintiCstoCv}, \csbh{xintiGCtoCv}}\label{xintiCstoF}
\label{xintiGCtoF}
\label{xintiCstoCv}
\label{xintiGCtoCv}
Essentially\etype{f} the same as the corresponding macros without the
`i', but for integer-only input. Infinitesimally faster, mainly for
internal use by the package.
\subsection{\csbh{xintGCtoGC}}\label{xintGCtoGC}
\csa{xintGCtoGC}|{a+b/c+d/e+f/g+......+v/w+x/y}|\etype{f} expands (with the
usual meaning) each one of the coefficients and returns an inline continued
fraction of the same type, each expanded coefficient being enclosed within
braces.
%
\begin{everbatim*}
\fdef\x {\xintGCtoGC {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/%
\xintiiFac {6}+\xintCstoF {2,-7,-5}/16}} \meaning\x
\end{everbatim*}
To be honest I have forgotten for which purpose I wrote this macro in the first
place.
\subsection{Euler's number \texorpdfstring{$e$}{e}}\label{ssec:e-convergents}
Let us explore
the convergents of Euler's number $e$.
\smallskip The volume of computation is kept minimal by the following steps:
\begin{itemize}
\item a comma separated list of the first 36 coefficients is produced by
\csbxint{CntoCs},
\item this is then given to \csbxint{iCstoCv} which produces the list of the
convergents (there is also \csbxint{CstoCv}, but our
coefficients being integers we used the infinitesimally
faster \csbxint{iCstoCv}),
\item then the whole list was converted into a sequence of one-line paragraphs,
each convergent becomes the argument to a macro printing it
together with its decimal expansion with 30 digits after the decimal point.
\item A count register |\cnta| was used to give a line count serving as a visual
aid: we could also have done that in an expandable way, but well, let's relax
from time to time\dots
\end{itemize}
\begin{everbatim*}
\def\cn #1{\the\numexpr\ifcase \numexpr #1+3-3*((#1+2)/3)\relax
1\or1\or2*(#1/3)\fi\relax }
% produces the pattern 1,1,2,1,1,4,1,1,6,1,1,8,... which are the
% coefficients of the simple continued fraction of e-1.
\cnta 0
\def\mymacro #1{\advance\cnta by 1
\noindent
\hbox to 3em {\hfil\small\dtt{\the\cnta.} }%
$\xintTrunc {30}{\xintAdd {1[0]}{#1}}\dots=
\xintFrac{\xintAdd {1[0]}{#1}}$}%
\xintListWithSep{\vtop to 6pt{}\vbox to 12pt{}\par}
{\xintApply\mymacro{\xintiCstoCv{\xintCntoCs {35}{\cn}}}}
\end{everbatim*}
\smallskip
% The actual computation of the list of all 36 convergents accounts for
% only 8\% of the total time (total time equal to about 5 hundredths of a second
% in my testing, on my laptop): another 80\% is occupied with the computation of
% the truncated decimal expansions (and the addition of 1 to everything as the
% formula gives the continued fraction of $e-1$).
One can with no problem compute
much bigger convergents. Let's get the 200th convergent. It turns out to
have the same first 268 digits after the decimal point as $e-1$. Higher
convergents get more and more digits in proportion to their index: the 500th
convergent already gets 799 digits correct! To allow speedy compilation of the
source of this document when the need arises, I limit here to the 200th
convergent.
% (getting the 500th took about 1.2s on my laptop last time I tried,
% and the 200th convergent is obtained ten times faster).
\begin{everbatim*}
\fdef\z {\xintCntoF {199}{\cn}}%
\begingroup\parindent 0pt \leftskip 2.5cm
\indent\llap {Numerator = }\printnumber{\xintNumerator\z}\par
\indent\llap {Denominator = }\printnumber{\xintDenominator\z}\par
\indent\llap {Expansion = }\printnumber{\xintTrunc{268}\z}\dots\par\endgroup
\end{everbatim*}
One can also use a centered continued fraction: we get more digits but there are
also more computations as the numerators may be either
$1$ or $-1$.
\ifnum\NoSourceCode=1
\bigskip
\begin{framed}
\small This documentation has been compiled without the source code,
which is available in the separate file:
%
\centeredline{|sourcexint.pdf|,}
%
which should be among the candidates proposed by |texdoc --list xint|. To
produce a single file including both the user documentation and the
source code, run |tex xint.dtx| to generate |xint.tex| (if not already
available), then edit |xint.tex| to set the |\NoSourceCode| toggle to |0|,
then run thrice |latex| on |xint.tex| and finally |dvipdfmx| on |xint.dvi|.
Alternatively, run |pdflatex| either directly on |xint.dtx|, or on
|xint.tex| with |\NoSourceCode| set to |0|.
\end{framed}
\fi
\ifnum\dosourcexint=1
+fi
+catcode`\ 0
\catcode0 15 % retour à la normale, peu importe
\catcode`\+ 12
\etocignoredepthtags
\etocsetnexttocdepth{section}
\tableofcontents
\makeatletter
\@gobble\fi
\StopEventually{\end{document}\endinput}
\ifnum\dosourcexint=1
\renewcommand{\etocaftertochook}{\addvspace{\bigskipamount}}
\etocsettocstyle {}{}
\else
\clearpage
\fi
\def\MARGEPAGENO{1.25em}
\etocsettocdepth{subsubsection}% 2015/09/15
\etocdepthtag.toc {implementation}
\addtocontents{toc}{\gdef\string\sectioncouleur{[named]{RoyalPurple}}}
\makeatletter
\def\storedlinecounts {}
\def\StoreCodelineNo #1{\edef\storedlinecounts{%
\unexpanded\expandafter{\storedlinecounts}%
{{#1}{\the\c@CodelineNo}}}\c@CodelineNo\z@ }
\def\macro@font {\ttbfamily }
\def\MicroFont {\ttzfamily\color[named]{Purple}\makestarlowast }
\makeatother
\MakePercentIgnore
%\def\gardesactifs {^^A
%\catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11 }
%\def\gardesinactifs {^^A
%\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12 }
%\gardesactifs
%\let</dtx>\relax
%\let<*xintkernel>\gardesinactifs
%</dtx>^^A--------------------------------------------------------
%<*xintkernel>^^A-------------------------------------------------
%
% \bigskip
% This is \expandafter|\xintbndlversion| of \expandafter|\xintbndldate|.
%
% \begin{itemize}
% \item Release |1.2| of |2015/10/10| has entirely rewritten the core
% arithmetic routines in \xintcorenameimp. Many macros benefit indirectly
% from the faster core routines. The new model is yet to be extended to
% other portions of the code: for example the routines of \xintbinhexnameimp
% could be made faster for very big inputs if they adopted some techniques
% from the implementation of the basic arithmetic routines.
%
% The parser of \xintexprnameimp is also faster at gathering digits and does
% not have a limit at |5000| digits per number anymore.
%
% \item Extensive changes in release |1.1| of |2014/10/28| were located in
% \xintexprnameimp. Also with that release, packages \xintkernelnameimp and
% \xintcorenameimp were extracted from \xinttoolsnameimp and \xintnameimp,
% and |\xintAdd| was modified to not multiply denominators blindly.
%
% \xinttoolsnameimp is not loaded anymore by \xintnameimp, nor by
% \xintfracnameimp. It is loaded by \xintexprnameimp.
% \end{itemize}
%
% Large portions of the code date back to the initial release, and at that
% time I was learning my trade in expandable TeX macro programming. At some
% point in the future, I will have to re-examine the older parts of the code.
%
% Warning: pay attention to the catcode configuration which is found in
% |\XINT_setcatcodes|. The code has additional temporary configuration
% at some locations. For example |!| is of catcode letter in \xintexprnameimp.
%
% \clearpage
% \section {Package \xintkernelnameimp implementation}
% \label{sec:kernelimp}
%
% \localtableofcontents
%
% This package provides the common minimal code base for loading management
% and catcode control and also a few programming utilities. With |1.2| a few
% more helper macros and all |\chardef|'s have been moved here. The package is
% loaded by both |xintcore.sty| and |xinttools.sty| hence by all other
% packages.
%
% First appeared as a separate package with release |1.1|.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% Starting with version |1.06| of the package, also |`| must be
% catcode-protected, because we replace everywhere in the code the
% twice-expansion done with |\expandafter| by the systematic use of
% |\romannumeral-`0|.
%
% Starting with version |1.06b| I decide that I suffer from an indigestion of @
% signs, so I replace them all with underscores |_|, \`a la \LaTeX 3.
%
% Release |1.09b| is more economical: some macros are defined already in
% |xint.sty| (now in |xintkernel.sty|) and re-used in other modules. All catcode
% changes have been unified and \csa{XINT_storecatcodes} will be used by each
% module to redefine |\XINT_restorecatcodes_endinput| in case catcodes have
% changed in-between the loading of |xint.sty| (now |xintkernel.sty|) and the
% module (not very probable but...).
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\catcode95=11 % _
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\let\z\relax
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintkernel}{\numexpr not available, aborting input}%
\def\z{\endgroup\endinput}%
\else
\expandafter
\ifx\csname XINTsetupcatcodes\endcsname\relax
\else
\y{xintkernel}{I was already loaded, aborting input}%
\def\z{\endgroup\endinput}%
\fi
\fi
\ifx\z\relax\else\expandafter\z\fi%
\def\PrepareCatcodes
{%
\endgroup
\def\XINT_restorecatcodes
{% takes care of all, to allow more economical code in modules
\catcode0=\the\catcode0 %
\catcode59=\the\catcode59 % ; xintexpr
\catcode126=\the\catcode126 % ~ xintexpr
\catcode39=\the\catcode39 % ' xintexpr
\catcode34=\the\catcode34 % " xintbinhex, and xintexpr
\catcode63=\the\catcode63 % ? xintexpr
\catcode124=\the\catcode124 % | xintexpr
\catcode38=\the\catcode38 % & xintexpr
\catcode64=\the\catcode64 % @ xintexpr
\catcode33=\the\catcode33 % ! xintexpr
\catcode93=\the\catcode93 % ] -, xintfrac, xintseries, xintcfrac
\catcode91=\the\catcode91 % [ -, xintfrac, xintseries, xintcfrac
\catcode36=\the\catcode36 % $ xintgcd only
\catcode94=\the\catcode94 % ^
\catcode96=\the\catcode96 % `
\catcode47=\the\catcode47 % /
\catcode41=\the\catcode41 % )
\catcode40=\the\catcode40 % (
\catcode42=\the\catcode42 % *
\catcode43=\the\catcode43 % +
\catcode62=\the\catcode62 % >
\catcode60=\the\catcode60 % <
\catcode58=\the\catcode58 % :
\catcode46=\the\catcode46 % .
\catcode45=\the\catcode45 % -
\catcode44=\the\catcode44 % ,
\catcode35=\the\catcode35 % #
\catcode95=\the\catcode95 % _
\catcode125=\the\catcode125 % }
\catcode123=\the\catcode123 % {
\endlinechar=\the\endlinechar
\catcode13=\the\catcode13 % ^^M
\catcode32=\the\catcode32 %
\catcode61=\the\catcode61\relax % =
}%
\edef\XINT_restorecatcodes_endinput
{%
\XINT_restorecatcodes\noexpand\endinput %
}%
\def\XINT_setcatcodes
{%
\catcode61=12 % =
\catcode32=10 % space
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode95=11 % _ LETTER
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=11 % : LETTER
\catcode60=12 % <
\catcode62=12 % >
\catcode43=12 % +
\catcode42=12 % *
\catcode40=12 % (
\catcode41=12 % )
\catcode47=12 % /
\catcode96=12 % `
\catcode94=11 % ^ LETTER
\catcode36=3 % $
\catcode91=12 % [
\catcode93=12 % ]
\catcode33=12 % !
\catcode64=11 % @ LETTER
\catcode38=7 % & for \romannumeral`&&@ trick.
\catcode124=12 % |
\catcode63=11 % ? LETTER
\catcode34=12 % "
\catcode39=12 % '
\catcode126=3 % ~ MATH
\catcode59=12 % ;
\catcode0=12 % for \romannumeral`&&@ trick
}%
\XINT_setcatcodes
}%
\PrepareCatcodes
% \end{macrocode}
% Other modules could possibly be loaded under a different catcode regime.
% \begin{macrocode}
\def\XINTsetupcatcodes {% for use by other modules
\edef\XINT_restorecatcodes_endinput
{%
\XINT_restorecatcodes\noexpand\endinput %
}%
\XINT_setcatcodes
}%
% \end{macrocode}
% \subsection{Package identification}
%
% Inspired from \textsc{Heiko Oberdiek}'s packages. Modified in |1.09b| to allow
% re-use in the other modules. Also I assume now that if |\ProvidesPackage|
% exists it then does define |\ver@<pkgname>.sty|, code of |HO| for some reason
% escaping me (compatibility with LaTeX 2.09 or other things ??) seems to set
% extra precautions.
%
% |1.09c| uses e-\TeX{} |\ifdefined|.
% \begin{macrocode}
\ifdefined\ProvidesPackage
\let\XINT_providespackage\relax
\else
\def\XINT_providespackage #1#2[#3]%
{\immediate\write-1{Package: #2 #3}%
\expandafter\xdef\csname ver@#2.sty\endcsname{#3}}%
\fi
\XINT_providespackage
\ProvidesPackage {xintkernel}%
[2016/11/20 1.2h Paraphernalia for the xint packages (JFB)]%
% \end{macrocode}
% \subsection{Constants}
% |1.2| decides to move them to \xintkernelnameimp from \xintcorenameimp and
% \xintnameimp. The |\count|'s are left in their respective packages.
% \begin{macrocode}
\chardef\xint_c_ 0
\chardef\xint_c_i 1
\chardef\xint_c_ii 2
\chardef\xint_c_iii 3
\chardef\xint_c_iv 4
\chardef\xint_c_v 5
\chardef\xint_c_vi 6
\chardef\xint_c_vii 7
\chardef\xint_c_viii 8
\chardef\xint_c_ix 9
\chardef\xint_c_x 10
\chardef\xint_c_xiv 14
\chardef\xint_c_xvi 16
\chardef\xint_c_xviii 18
\chardef\xint_c_xxii 22
\chardef\xint_c_ii^v 32
\chardef\xint_c_ii^vi 64
\chardef\xint_c_ii^vii 128
\mathchardef\xint_c_ii^viii 256
\mathchardef\xint_c_ii^xii 4096
\mathchardef\xint_c_x^iv 10000
% \end{macrocode}
% \subsection{Token management utilities}
% \begin{macrocode}
\def\XINT_tmpa { }%
\ifx\XINT_tmpa\space\else
\immediate\write-1{Package xintkernel Warning: ATTENTION!}%
\immediate\write-1{\string\space\XINT_tmpa macro does not have its normal
meaning.}%
\immediate\write-1{\XINT_tmpa\XINT_tmpa\XINT_tmpa\XINT_tmpa
All kinds of catastrophes will ensue!!!!}%
\fi
\def\XINT_tmpb {}%
\ifx\XINT_tmpb\empty\else
\immediate\write-1{Package xintkernel Warning: ATTENTION!}%
\immediate\write-1{\string\empty\XINT_tmpa macro does not have its normal
meaning.}%
\immediate\write-1{\XINT_tmpa\XINT_tmpa\XINT_tmpa\XINT_tmpa
All kinds of catastrophes will ensue!!!!}%
\fi
\let\XINT_tmpa\relax \let\XINT_tmpb\relax
\ifdefined\space\else\def\space { }\fi
\ifdefined\empty\else\def\empty {}\fi
\long\def\xint_gobble_ {}%
\long\def\xint_gobble_i #1{}%
\long\def\xint_gobble_ii #1#2{}%
\long\def\xint_gobble_iii #1#2#3{}%
\long\def\xint_gobble_iv #1#2#3#4{}%
\long\def\xint_gobble_v #1#2#3#4#5{}%
\long\def\xint_gobble_vi #1#2#3#4#5#6{}%
\long\def\xint_gobble_vii #1#2#3#4#5#6#7{}%
\long\def\xint_gobble_viii #1#2#3#4#5#6#7#8{}%
\long\def\xint_firstofone #1{#1}%
\long\def\xint_firstoftwo #1#2{#1}%
\long\def\xint_secondoftwo #1#2{#2}%
\long\def\xint_gobble_thenstop #1{ }%
\long\def\xint_firstofone_thenstop #1{ #1}%
\long\def\xint_firstoftwo_thenstop #1#2{ #1}%
\long\def\xint_secondoftwo_thenstop #1#2{ #2}%
\def\xint_exchangetwo_keepbraces #1#2{{#2}{#1}}%
% \end{macrocode}
% \lverb|&
% It has taken me three years to realize that \romannumeral0 was stopped by a
% minus sign with no side effect. I had here$newline
% \def\xint_minus_thenstop { -}%$newline
% but obviously it has no real utility !
%
% I had already started recently removing spaces in front of braces when I
% spotted them in the old code ... but that story of the minus sign is really
% strange. I knew it for a long time but never bothered looking back.
% I had 35 uses in the code. Removed by 1.2g.
% |
%
% \subsection{``gob til'' macros and UD style fork}
% Some moved here from \xintcorenameimp by release |1.2|.
% \begin{macrocode}
\long\def\xint_gob_til_R #1\R {}%
\long\def\xint_gob_til_W #1\W {}%
\long\def\xint_gob_til_Z #1\Z {}%
\def\xint_gob_til_zero #10{}%
\def\xint_gob_til_one #11{}%
\def\xint_gob_til_zeros_iii #1000{}%
\def\xint_gob_til_zeros_iv #10000{}%
\def\xint_gob_til_eightzeroes #100000000{}%
\def\xint_gob_til_exclam #1!{}% catcode 12 exclam
\def\xint_gob_til_dot #1.{}%
\def\xint_gob_til_G #1G{}%
\def\xint_gob_til_minus #1-{}%
\def\xint_gob_til_relax #1\relax {}%
\def\xint_UDzerominusfork #10-#2#3\krof {#2}%
\def\xint_UDzerofork #10#2#3\krof {#2}%
\def\xint_UDsignfork #1-#2#3\krof {#2}%
\def\xint_UDwfork #1\W#2#3\krof {#2}%
\def\xint_UDXINTWfork #1\XINT_W#2#3\krof {#2}%
\def\xint_UDzerosfork #100#2#3\krof {#2}%
\def\xint_UDonezerofork #110#2#3\krof {#2}%
\def\xint_UDsignsfork #1--#2#3\krof {#2}%
\let\xint_relax\relax
\def\xint_brelax {\xint_relax }%
\long\def\xint_gob_til_xint_relax #1\xint_relax {}%
% \end{macrocode}
% \subsection{\csh{xint_afterfi}}
% \begin{macrocode}
\long\def\xint_afterfi #1#2\fi {\fi #1}%
% \end{macrocode}
% \subsection{\csh{xint_bye}}
% \begin{macrocode}
\long\def\xint_bye #1\xint_bye {}%
% \end{macrocode}
% \subsection{\csh{xintdothis}, \csh{xintorthat}}
% \lverb|New with 1.1. Public names without underscores with 1.2. Used as
% \if..\xint_dothis{..}\fi <multiple times> followed by \xint_orthat{...}. To
% be used with less probable things first.|
% \begin{macrocode}
\long\def\xint_dothis #1#2\xint_orthat #3{\fi #1}% 1.1
\let\xint_orthat \xint_firstofone
\long\def\xintdothis #1#2\xintorthat #3{\fi #1}%
\let\xintorthat \xint_firstofone
% \end{macrocode}
% \subsection{\csh{xint_zapspaces}}
% \lverb|1.1. This little utility zaps leading, intermediate, trailing,
% spaces in completely expanding context (\edef, \csname . . . \endcsname).
% $centeredline$bgroup\xint_zapspaces foo<space>\xint_gobble_i$egroup
%
% Will remove some brace pairs (but not spaces inside them). By the way the
% \zap@spaces of LaTeX2e handles unexpectedly things such as \zap@spaces 1
% {22} 3 4 \@empty (spaces are not all removed). This does not happen with
% \xint_zapspaces.
%
% Explanation: if there are leading spaces, then the first #1 will be empty,
% and the first #2 being undelimited will be stripped from all the remaining
% leading spaces, if there was more than one to start with. Of course
% brace-stripping may occur. And this iterates: each time a #2 is removed,
% either we then have spaces and next #1 will be empty, or we have no spaces
% and #1 will end at the first space. Ultimately #2 will be \xint_gobble_i.
%
% This is not really robust as it may switch the expansion order of macros,
% and the \xint_zapspaces token might end up being fetched up by a macro. But
% it is enough for our purposes, for example:
% $centeredline
% $bgroup\the\numexpr \xint_zapspaces 1 2 \xint_gobble_i\relax$egroup
% expands to 12, and not 12\relax. Imagine also:
% $centeredline
% $bgroup\the\numexpr 1 2\expandafter.\the\numexpr ...$egroup
%
% The spaces will stop the \numexpr, and the \expandafter will not be
% immediately executed. Thus we have to get rid of spaces in
% contexts where arguments are fetched by delimited macros and fed to
% \numexpr (or for any reason can contain spaces). I apply this corrective
% treatment so far only in $xintexprnameimp but perhaps I should in
% $xintfracnameimp too. As said above, perhaps the zapspaces should force
% expansion too, but I leave it standing.
%
% 1.2e adds \xint_zapspaces_o. Expansion of #1 should not gobble a space ! |
% \begin{macrocode}
\def\xint_zapspaces #1 #2{#1#2\xint_zapspaces }% 1.1
\def\xint_zapspaces_o #1{\expandafter\xint_zapspaces#1 \xint_gobble_i}%
% \end{macrocode}
% \subsection{\csh{odef}, \csh{oodef}, \csh{fdef}}
% \lverb|May be prefixed with \global. No parameter text.|
% \begin{macrocode}
\def\xintodef #1{\expandafter\def\expandafter#1\expandafter }%
\def\xintoodef #1{\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter#1%
\expandafter\expandafter\expandafter }%
\def\xintfdef #1#2{\expandafter\def\expandafter#1\expandafter
{\romannumeral`&&@#2}}%
\ifdefined\odef\else\let\odef\xintodef\fi
\ifdefined\oodef\else\let\oodef\xintoodef\fi
\ifdefined\fdef\else\let\fdef\xintfdef\fi
% \end{macrocode}
% \subsection{\csh{xintReverseOrder}}
% \lverb|\xintReverseOrder: does NOT expand its argument. Thus one must use
% some \expandafter if argument is a macro. A faster reverse, but only
% applicable to (many) digit tokens has been provided with
% \csh{xintReverseDigits} from 1.2 xintcore.
%
% 1.2g has (not user documented) \xintCSVReverse in xinttools.sty.|
% \begin{macrocode}
\def\xintReverseOrder {\romannumeral0\xintreverseorder }%
\long\def\xintreverseorder #1%
{%
\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
}%
\long\def\XINT_rord_main #1#2#3#4#5#6#7#8#9%
{%
\xint_bye #9\XINT_rord_cleanup\xint_bye
\XINT_rord_main {#9#8#7#6#5#4#3#2#1}%
}%
\long\edef\XINT_rord_cleanup\xint_bye\XINT_rord_main #1#2\xint_relax
{%
\noexpand\expandafter\space\noexpand\xint_gob_til_xint_relax #1%
}%
% \end{macrocode}
% \subsection{\csh{xintLength}}
% \lverb|\xintLength does NOT expand its argument.
%
% 1.2g has (not user documented) \xintCSVLength in xinttools.sty.|
% \begin{macrocode}
\def\xintLength {\romannumeral0\xintlength }%
\long\def\xintlength #1%
{%
\XINT_length_loop
0.#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\long\def\XINT_length_loop #1.#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_xint_relax #9\XINT_length_finish_a\xint_relax
\expandafter\XINT_length_loop\the\numexpr #1+\xint_c_viii.%
}%
\def\XINT_length_finish_a\xint_relax\expandafter\XINT_length_loop
\the\numexpr #1+\xint_c_viii.#2\xint_bye
{%
\XINT_length_finish_b #2\W\W\W\W\W\W\W\Z {#1}%
}%
\def\XINT_length_finish_b #1#2#3#4#5#6#7#8\Z
{%
\xint_gob_til_W
#1\XINT_length_finish_c \xint_c_
#2\XINT_length_finish_c \xint_c_i
#3\XINT_length_finish_c \xint_c_ii
#4\XINT_length_finish_c \xint_c_iii
#5\XINT_length_finish_c \xint_c_iv
#6\XINT_length_finish_c \xint_c_v
#7\XINT_length_finish_c \xint_c_vi
\W\XINT_length_finish_c \xint_c_vii\Z
}%
\edef\XINT_length_finish_c #1#2\Z #3%
{\noexpand\expandafter\space\noexpand\the\numexpr #3+#1\relax}%
% \end{macrocode}
% \subsection{\csh{xintMessage}, \csh{ifxintverbose}}
% \lverb|1.2c added it for use by \xintdefvar and \xintdeffunc of xintexpr.
% 1.2e uses \write128 rather than \write16 for compatibility with future
% extended range of output streams, in LuaTeX in particular.|
% \begin{macrocode}
\def\xintMessage #1#2#3{%
\immediate\write128{Package #1 #2: (on line \the\inputlineno)}%
\immediate\write128{\space\space\space\space#3}%
}%
\newif\ifxintverbose
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintkernel}
%
%\gardesactifs
%\let</xintkernel>\relax
%\let<*xinttools>\gardesinactifs
%</xintkernel>^^A-------------------------------------------------
%<*xinttools>^^A--------------------------------------------------
% \clearpage
% \section{Package \xinttoolsnameimp implementation}
% \label{sec:toolsimp}
%
% \localtableofcontents
%
% Release |1.09g| of |2013/11/22| splits off |xinttools.sty| from |xint.sty|.
% Starting with |1.1|, \xinttoolsnameimp ceases being loaded automatically by
% \xintnameimp.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xinttools.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintkernel.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xinttools}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xinttools.sty
\ifx\w\relax % but xintkernel.sty not yet loaded.
\def\z{\endgroup\input xintkernel.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintkernel.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintkernel}}%
\fi
\else
\aftergroup\endinput % xinttools already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xinttools}%
[2016/11/20 1.2h Expandable and non-expandable utilities (JFB)]%
% \end{macrocode}
% \lverb|\XINT_toks is used in macros such as \xintFor. It is not used
% elsewhere in the xint bundle.|
% \begin{macrocode}
\newtoks\XINT_toks
\xint_firstofone{\let\XINT_sptoken= } %<- space here!
% \end{macrocode}
% \subsection{\csh{xintgodef}, \csh{xintgoodef}, \csh{xintgfdef}}
% \lverb|1.09i. For use in \xintAssign.|
% \begin{macrocode}
\def\xintgodef {\global\xintodef }%
\def\xintgoodef {\global\xintoodef }%
\def\xintgfdef {\global\xintfdef }%
% \end{macrocode}
% \subsection{\csh{xintRevWithBraces}}
% \lverb|New with 1.06. Makes the expansion of its argument and then reverses
% the resulting tokens or braced tokens, adding a pair of braces to each (thus,
% maintaining it when it was already there.) The reason for
% \xint_relax, here and in other locations, is in case #1 expands to nothing,
% the \romannumeral-`0 must be stopped|
% \begin{macrocode}
\def\xintRevWithBraces {\romannumeral0\xintrevwithbraces }%
\def\xintRevWithBracesNoExpand {\romannumeral0\xintrevwithbracesnoexpand }%
\long\def\xintrevwithbraces #1%
{%
\expandafter\XINT_revwbr_loop\expandafter{\expandafter}%
\romannumeral`&&@#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\long\def\xintrevwithbracesnoexpand #1%
{%
\XINT_revwbr_loop {}%
#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\long\def\XINT_revwbr_loop #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_xint_relax #9\XINT_revwbr_finish_a\xint_relax
\XINT_revwbr_loop {{#9}{#8}{#7}{#6}{#5}{#4}{#3}{#2}#1}%
}%
\long\def\XINT_revwbr_finish_a\xint_relax\XINT_revwbr_loop #1#2\xint_bye
{%
\XINT_revwbr_finish_b #2\R\R\R\R\R\R\R\Z #1%
}%
\def\XINT_revwbr_finish_b #1#2#3#4#5#6#7#8\Z
{%
\xint_gob_til_R
#1\XINT_revwbr_finish_c \xint_gobble_viii
#2\XINT_revwbr_finish_c \xint_gobble_vii
#3\XINT_revwbr_finish_c \xint_gobble_vi
#4\XINT_revwbr_finish_c \xint_gobble_v
#5\XINT_revwbr_finish_c \xint_gobble_iv
#6\XINT_revwbr_finish_c \xint_gobble_iii
#7\XINT_revwbr_finish_c \xint_gobble_ii
\R\XINT_revwbr_finish_c \xint_gobble_i\Z
}%
% \end{macrocode}
% \lverb|1.1c revisited this old code and improved upon the earlier endings.|
% \begin{macrocode}
\edef\XINT_revwbr_finish_c #1#2\Z {\noexpand\expandafter\space #1}%
% \end{macrocode}
% \subsection{\csh{xintZapFirstSpaces}}
% \lverb|1.09f, written [2013/11/01]. Modified (2014/10/21) for release 1.1 to
% correct the bug in case of an empty argument, or argument containing only
% spaces, which had been forgotten in first version. New version is simpler than
% the initial one. This macro does NOT expand its argument.|
% \begin{macrocode}
\def\xintZapFirstSpaces {\romannumeral0\xintzapfirstspaces }%
% \end{macrocode}
% \lverb|defined via an \edef in order to inject space tokens inside.|
% \begin{macrocode}
\long\edef\xintzapfirstspaces #1%
{\noexpand\XINT_zapbsp_a \space #1\xint_relax \space\space\xint_relax }%
\xint_firstofone {\long\edef\XINT_zapbsp_a #1 } %<- space token here
{%
% \end{macrocode}
% \lverb|If the original #1 started with a space, the grabbed #1 is empty. Thus
% _again? will see #1=\xint_bye, and hand over control to _again which will loop
% back into \XINT_zapbsp_a, with one initial space less. If the original #1 did
% not start with a space, or was empty, then the #1 below will be a <sptoken>,
% then an extract of the original #1, not empty and not starting with a space,
% which contains what was up to the first <sp><sp> present in original #1, or,
% if none preexisted, <sptoken> and all of #1 (possibly empty) plus an ending
% \xint_relax. The added initial space will stop later the \romannumeral0. No
% brace stripping is possible. Control is handed over to \XINT_zapbsp_b which
% strips out the ending \xint_relax<sp><sp>\xint_relax|
% \begin{macrocode}
\noexpand\XINT_zapbsp_again? #1\noexpand\xint_bye\noexpand\XINT_zapbsp_b #1\space\space
}%
\long\def\XINT_zapbsp_again? #1{\xint_bye #1\XINT_zapbsp_again }%
\xint_firstofone{\def\XINT_zapbsp_again\XINT_zapbsp_b} {\XINT_zapbsp_a }%
\long\def\XINT_zapbsp_b #1\xint_relax #2\xint_relax {#1}%
% \end{macrocode}
% \subsection{\csh{xintZapLastSpaces}}
% \lverb+1.09f, written [2013/11/01]. +
% \begin{macrocode}
\def\xintZapLastSpaces {\romannumeral0\xintzaplastspaces }%
% \end{macrocode}
% \lverb|Next macro is defined via an \edef for the space tokens.|
% \begin{macrocode}
\long\edef\xintzaplastspaces #1{\noexpand\XINT_zapesp_a {}\noexpand\empty#1%
\space\space\noexpand\xint_bye\xint_relax}%
% \end{macrocode}
% \lverb|The \empty from \xintzaplastspaces is to prevent brace removal in the
% #2 below. The \expandafter chain removes it.|
% \begin{macrocode}
\xint_firstofone {\long\def\XINT_zapesp_a #1#2 } %<- second space here
{\expandafter\XINT_zapesp_b\expandafter{#2}{#1}}%
% \end{macrocode}
% \lverb|Notice again an \empty added here. This is in preparation for possibly looping
% back to \XINT_zapesp_a. If the initial #1 had no <sp><sp>, the stuff however
% will not loop, because #3 will already be <some spaces>\xint_bye. Notice
% that this macro fetches all way to the ending \xint_relax. This looks not
% very efficient, but how often do we have to strip ending spaces from
% something which also has inner stretches of _multiple_ space tokens ?;-). |
% \begin{macrocode}
\long\def\XINT_zapesp_b #1#2#3\xint_relax
{\XINT_zapesp_end? #3\XINT_zapesp_e {#2#1}\empty #3\xint_relax }%
% \end{macrocode}
% \lverb|When we have been over all possible <sp><sp> things, we reach the
% ending space tokens, and #3 will be a bunch of spaces (possibly none)
% followed by \xint_bye. So the #1 in _end? will be \xint_bye. In all other cases
% #1 can not be \xint_bye (assuming naturally this token does nor arise in
% original input), hence control falls back to \XINT_zapesp_e which will loop back
% to \XINT_zapesp_a.|
% \begin{macrocode}
\long\def\XINT_zapesp_end? #1{\xint_bye #1\XINT_zapesp_end }%
% \end{macrocode}
% \lverb|We are done. The #1 here has accumulated all the previous material,
% and is stripped of its ending spaces, if any.|
% \begin{macrocode}
\long\def\XINT_zapesp_end\XINT_zapesp_e #1#2\xint_relax { #1}%
% \end{macrocode}
% \lverb|We haven't yet reached the end, so we need to re-inject two space
% tokens after what we have gotten so far. Then we loop.|
% \begin{macrocode}
\long\edef\XINT_zapesp_e #1{\noexpand \XINT_zapesp_a {#1\space\space}}%
% \end{macrocode}
% \subsection{\csh{xintZapSpaces}}
% \lverb+1.09f, written [2013/11/01]. Modified for 1.1, 2014/10/21 as it has the
% same bug as \xintZapFirstSpaces. We in effect do first \xintZapFirstSpaces,
% then \xintZapLastSpaces.+
% \begin{macrocode}
\def\xintZapSpaces {\romannumeral0\xintzapspaces }%
\long\edef\xintzapspaces #1% like \xintZapFirstSpaces.
{\noexpand\XINT_zapsp_a \space #1\xint_relax \space\space\xint_relax }%
\xint_firstofone {\long\edef\XINT_zapsp_a #1 } %
{\noexpand\XINT_zapsp_again? #1\noexpand\xint_bye\noexpand\XINT_zapsp_b #1\space\space}%
\long\def\XINT_zapsp_again? #1{\xint_bye #1\XINT_zapsp_again }%
\xint_firstofone{\def\XINT_zapsp_again\XINT_zapsp_b} {\XINT_zapsp_a }%
\xint_firstofone{\def\XINT_zapsp_b} {\XINT_zapsp_c }%
\long\edef\XINT_zapsp_c #1\xint_relax #2\xint_relax {\noexpand\XINT_zapesp_a
{}\noexpand \empty #1\space\space\noexpand\xint_bye\xint_relax }%
% \end{macrocode}
% \subsection{\csh{xintZapSpacesB}}
% \lverb+1.09f, written [2013/11/01]. Strips up to one pair of braces (but then
% does not strip spaces inside).+
% \begin{macrocode}
\def\xintZapSpacesB {\romannumeral0\xintzapspacesb }%
\long\def\xintzapspacesb #1{\XINT_zapspb_one? #1\xint_relax\xint_relax
\xint_bye\xintzapspaces {#1}}%
\long\def\XINT_zapspb_one? #1#2%
{\xint_gob_til_xint_relax #1\XINT_zapspb_onlyspaces\xint_relax
\xint_gob_til_xint_relax #2\XINT_zapspb_bracedorone\xint_relax
\xint_bye {#1}}%
\def\XINT_zapspb_onlyspaces\xint_relax
\xint_gob_til_xint_relax\xint_relax\XINT_zapspb_bracedorone\xint_relax
\xint_bye #1\xint_bye\xintzapspaces #2{ }%
\long\def\XINT_zapspb_bracedorone\xint_relax
\xint_bye #1\xint_relax\xint_bye\xintzapspaces #2{ #1}%
% \end{macrocode}
% \subsection{\csh{xintCSVtoList}, \csh{xintCSVtoListNonStripped}}
% \lverb|\xintCSVtoList transforms a,b,..,z into {a}{b}...{z}. The comma
% separated list may be a macro which is first f-expanded. First included in
% release 1.06. Here, use of \Z (and \R) perfectly safe.
%
% [2013/11/02]: Starting with 1.09f, automatically filters items with
% \xintZapSpacesB to strip away all spaces around commas, and spaces at the start
% and end of the list. The original is kept as \xintCSVtoListNonStripped, and is
% faster. But ... it doesn't strip spaces.|
% \begin{macrocode}
\def\xintCSVtoList {\romannumeral0\xintcsvtolist }%
\long\def\xintcsvtolist #1{\expandafter\xintApply
\expandafter\xintzapspacesb
\expandafter{\romannumeral0\xintcsvtolistnonstripped{#1}}}%
\def\xintCSVtoListNoExpand {\romannumeral0\xintcsvtolistnoexpand }%
\long\def\xintcsvtolistnoexpand #1{\expandafter\xintApply
\expandafter\xintzapspacesb
\expandafter{\romannumeral0\xintcsvtolistnonstrippednoexpand{#1}}}%
\def\xintCSVtoListNonStripped {\romannumeral0\xintcsvtolistnonstripped }%
\def\xintCSVtoListNonStrippedNoExpand
{\romannumeral0\xintcsvtolistnonstrippednoexpand }%
\long\def\xintcsvtolistnonstripped #1%
{%
\expandafter\XINT_csvtol_loop_a\expandafter
{\expandafter}\romannumeral`&&@#1%
,\xint_bye,\xint_bye,\xint_bye,\xint_bye
,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z
}%
\long\def\xintcsvtolistnonstrippednoexpand #1%
{%
\XINT_csvtol_loop_a
{}#1,\xint_bye,\xint_bye,\xint_bye,\xint_bye
,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z
}%
\long\def\XINT_csvtol_loop_a #1#2,#3,#4,#5,#6,#7,#8,#9,%
{%
\xint_bye #9\XINT_csvtol_finish_a\xint_bye
\XINT_csvtol_loop_b {#1}{{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
}%
\long\def\XINT_csvtol_loop_b #1#2{\XINT_csvtol_loop_a {#1#2}}%
\long\def\XINT_csvtol_finish_a\xint_bye\XINT_csvtol_loop_b #1#2#3\Z
{%
\XINT_csvtol_finish_b #3\R,\R,\R,\R,\R,\R,\R,\Z #2{#1}%
}%
% \end{macrocode}
% \lverb|1.1c revisits this old code and improves upon the earlier endings.
% But as the _d.. macros have already nine parameters, I needed the
% \expandafter and \xint_gob_til_Z in finish_b (compare \XINT_keep_endb, or
% also \XINT_RQ_end_b).|
% \begin{macrocode}
\def\XINT_csvtol_finish_b #1,#2,#3,#4,#5,#6,#7,#8\Z
{%
\xint_gob_til_R
#1\expandafter\XINT_csvtol_finish_dviii\xint_gob_til_Z
#2\expandafter\XINT_csvtol_finish_dvii \xint_gob_til_Z
#3\expandafter\XINT_csvtol_finish_dvi \xint_gob_til_Z
#4\expandafter\XINT_csvtol_finish_dv \xint_gob_til_Z
#5\expandafter\XINT_csvtol_finish_div \xint_gob_til_Z
#6\expandafter\XINT_csvtol_finish_diii \xint_gob_til_Z
#7\expandafter\XINT_csvtol_finish_dii \xint_gob_til_Z
\R\XINT_csvtol_finish_di \Z
}%
\long\def\XINT_csvtol_finish_dviii #1#2#3#4#5#6#7#8#9{ #9}%
\long\def\XINT_csvtol_finish_dvii #1#2#3#4#5#6#7#8#9{ #9{#1}}%
\long\def\XINT_csvtol_finish_dvi #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}}%
\long\def\XINT_csvtol_finish_dv #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}{#3}}%
\long\def\XINT_csvtol_finish_div #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}{#3}{#4}}%
\long\def\XINT_csvtol_finish_diii #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}{#3}{#4}{#5}}%
\long\def\XINT_csvtol_finish_dii #1#2#3#4#5#6#7#8#9%
{ #9{#1}{#2}{#3}{#4}{#5}{#6}}%
\long\def\XINT_csvtol_finish_di\Z #1#2#3#4#5#6#7#8#9%
{ #9{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
% \end{macrocode}
% \subsection{\csh{xintListWithSep}}
% \lverb|1.04.
% \xintListWithSep {\sep}{{a}{b}...{z}} returns a \sep b \sep ....\sep z. It
% f-expands its second argument. The 'sep' may be \par's: the macro
% \xintlistwithsep etc... are all declared long. 'sep' does not have to be a
% single token. It is not expanded.|
% \begin{macrocode}
\def\xintListWithSep {\romannumeral0\xintlistwithsep }%
\def\xintListWithSepNoExpand {\romannumeral0\xintlistwithsepnoexpand }%
\long\def\xintlistwithsep #1#2%
{\expandafter\XINT_lws\expandafter {\romannumeral`&&@#2}{#1}}%
\long\def\XINT_lws #1#2{\XINT_lws_start {#2}#1\xint_bye }%
\long\def\xintlistwithsepnoexpand #1#2{\XINT_lws_start {#1}#2\xint_bye }%
\long\def\XINT_lws_start #1#2%
{%
\xint_bye #2\XINT_lws_dont\xint_bye
\XINT_lws_loop_a {#2}{#1}%
}%
\long\def\XINT_lws_dont\xint_bye\XINT_lws_loop_a #1#2{ }%
\long\def\XINT_lws_loop_a #1#2#3%
{%
\xint_bye #3\XINT_lws_end\xint_bye
\XINT_lws_loop_b {#1}{#2#3}{#2}%
}%
\long\def\XINT_lws_loop_b #1#2{\XINT_lws_loop_a {#1#2}}%
\long\def\XINT_lws_end\xint_bye\XINT_lws_loop_b #1#2#3{ #1}%
% \end{macrocode}
% \subsection{\csh{xintNthElt}}
% \lverb?First included in release 1.06.
%
% \xintNthElt {i}{stuff f-expanding to {a}{b}...{z}} (or `tokens'
% abcd...z)returns the i th element (one pair of braces removed). The list is
% first f-expanded. The \xintNthEltNoExpand does no expansion of its second
% argument. Both variants expand the first argument inside \numexpr.
%
% With i = 0, the number of items is returned. This is different from \xintLen
% which is only for numbers (particularly, it checks the sign) and different
% from \xintLength which does not f-expand its argument.
%
% Negative values return the |i|th element from the end.
%
% When i is out of range, an empty value is returned.
%
%
% 1.2g does some changes possibly improving a bit the speed of token
% shuffling here (particularly when the first argument is negative).
%
% ?
% \begin{macrocode}
\def\xintNthElt {\romannumeral0\xintnthelt }%
\def\xintNthEltNoExpand {\romannumeral0\xintntheltnoexpand }%
\long\def\xintnthelt #1#2{\expandafter\XINT_nthelt_a\the\numexpr #1\expandafter.%
\expandafter{\romannumeral`&&@#2}}%
\def\xintntheltnoexpand #1{\expandafter\XINT_nthelt_a\the\numexpr #1.}%
\def\XINT_nthelt_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_nthelt_zero }%
0#1{\XINT_nthelt_neg }%
0-{\XINT_nthelt_pos #1}%
\krof
}%
\def\XINT_nthelt_zero .{\xintlength }%
\long\def\XINT_nthelt_neg #1.#2%
{%
\expandafter\XINT_nthelt_neg_a\the\numexpr
\XINT_length_loop
0.#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye +\xint_c_i -#1.%
#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_nthelt_neg_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_nthelt_none }%
0#1{\XINT_nthelt_none }%
0-{\XINT_nthelt_loop_a #1}%
\krof
}%
\long\def\XINT_nthelt_none #1\xint_bye{ }%
\long\def\XINT_nthelt_pos #1.#2%
{%
\XINT_nthelt_loop_a #1.%
#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_nthelt_loop_a #1.%
{%
\ifnum #1>\xint_c_viii
\expandafter\XINT_nthelt_loop_b
\else
\expandafter\XINT_nthelt_getit
\fi #1.%
}%
\long\def\XINT_nthelt_loop_b #1.#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_xint_relax #9\XINT_nthelt_none\xint_relax
\expandafter\XINT_nthelt_loop_a\the\numexpr #1-\xint_c_viii.%
}%
\def\XINT_nthelt_getit #1.%
{%
\expandafter\expandafter\expandafter\XINT_nthelt_finish
\csname xint_gobble_\romannumeral\numexpr#1-\xint_c_i\endcsname
}%
\long\edef\XINT_nthelt_finish #1#2\xint_bye
{\noexpand\xint_gob_til_xint_relax #1\noexpand\expandafter\space
\noexpand\xint_gobble_ii\xint_relax\space #1}%
% \end{macrocode}
% \subsection{\csh{xintKeep}}
% \lverb?&
%
% First included in release 1.09m.
%
% \xintKeep {i}{stuff f-expanding to {a}{b}...{z}} (or `tokens' abcd...z, but
% each naked token ends up braced in the output, if 0<i<length of token list)
% returns (in two expansion steps) the first i items from the list, which
% is first f-expanded. The i is expanded inside \numexpr. The variant
% \xintKeepNoExpand does not expand the list argument.
%
% With 0<i<length, each item ends up *braced* in the output.
%
% With i = 0, the empty sequence is returned.
%
% With |i| equal to or bigger than the length of the (f-expanded) list,
% the full list is returned, with no braces added to items.
%
% With -length<i<0, the last |i| items are returned (in the same order as in
% the original list) AND BRACES ARE NOT ADDED IF NOT ORIGINALLY PRESENT.
%
% 1.2a belatedly corrects the description of what this macro does for i<0 !
%
% I have this nagging feeling I should read this code which might be much
% improvable upon, but I just don't have time now (2015/10/19).
%
% Some cosmetic code improvements for 1.2g, to minimize token handling. And
% the ending (_finish) which was temporary has finally been redone, fleeting
% thoughts of alternative keep escaping me and I was a bit reluctant to the
% method followed in the end, but still probably better than the older one.
% ?
% \begin{macrocode}
\def\xintKeep {\romannumeral0\xintkeep }%
\def\xintKeepNoExpand {\romannumeral0\xintkeepnoexpand }%
\long\def\xintkeep #1#2{\expandafter\XINT_keep_a\the\numexpr #1\expandafter.%
\expandafter{\romannumeral`&&@#2}}%
\def\xintkeepnoexpand #1{\expandafter\XINT_keep_a\the\numexpr #1.}%
\def\XINT_keep_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_keep_keepnone }%
0#1{\XINT_keep_neg }%
0-{\XINT_keep_pos #1}%
\krof
}%
\long\def\XINT_keep_keepnone .#1{ }%
\long\def\XINT_keep_neg #1.#2%
{%
\expandafter\XINT_keep_neg_a\the\numexpr
\XINT_length_loop
0.#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye -#1.%
#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_keep_neg_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_keep_keepall }%
0#1{\XINT_keep_keepall }%
0-{\XINT_trim_loop_a #1}%
\krof
}%
\def\XINT_keep_keepall #1.{\XINT_keep_keepall_a \space}%
\def\XINT_keep_keepall_a #1\xint_relax #2\xint_bye {#1}%
\long\def\XINT_keep_pos #1.#2%
{%
\XINT_keep_loop_a #1.%
{}#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_keep_loop_a #1.%
{%
\ifnum #1>\xint_c_vi
\expandafter\XINT_keep_loop_b
\else
\expandafter\XINT_keep_finish
\fi
#1.%
}%
\long\def\XINT_keep_loop_b #1.#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_xint_relax #9\XINT_keep_enda\xint_relax
\expandafter\XINT_keep_loop_c\the\numexpr #1-\xint_c_vii.%
{{#3}{#4}{#5}{#6}{#7}{#8}{#9}}{#2}%
}%
\long\def\XINT_keep_loop_c #1.#2#3{\XINT_keep_loop_a #1.{#3#2}}%
\long\def\XINT_keep_enda #1.#2#3#4\xint_bye
{%
\XINT_keep_endb #4\W\W\W\W\W\W\Z #2{#3}%
}%
\def\XINT_keep_endb #1#2#3#4#5#6#7\Z
{%
\xint_gob_til_W
#1\XINT_keep_endc_
#2\XINT_keep_endc_i
#3\XINT_keep_endc_ii
#4\XINT_keep_endc_iii
#5\XINT_keep_endc_iv
#6\XINT_keep_endc_v
\W\XINT_keep_endc_vi\Z
}%
\long\def\XINT_keep_endc_ #1\Z #2#3#4#5#6#7#8#9{ #9}%
\long\def\XINT_keep_endc_i #1\Z #2#3#4#5#6#7#8#9{#9{#2}}%
\long\def\XINT_keep_endc_ii #1\Z #2#3#4#5#6#7#8#9{#9{#2}{#3}}%
\long\def\XINT_keep_endc_iii #1\Z #2#3#4#5#6#7#8#9{#9{#2}{#3}{#4}}%
\long\def\XINT_keep_endc_iv #1\Z #2#3#4#5#6#7#8#9{#9{#2}{#3}{#4}{#5}}%
\long\def\XINT_keep_endc_v #1\Z #2#3#4#5#6#7#8#9{#9{#2}{#3}{#4}{#5}{#6}}%
\long\def\XINT_keep_endc_vi\Z #1#2#3#4#5#6#7#8{#8{#1}{#2}{#3}{#4}{#5}{#6}}%
\long\def\XINT_keep_finish #1.#2#3#4#5#6#7#8#9\xint_bye
{%
\XINT_keep_finish_a #1.%
#3\xint_c_ #4\xint_c_i #5\xint_c_ii #6\xint_c_iii #7\xint_c_iv
#8\xint_c_v\xint_relax\xint_c_vi\xint_bye
{#3}{#4}{#5}{#6}{#7}{#8}\xint_bye {#2}%
}%
\long\def\XINT_keep_finish_a #1.#2\xint_relax #3#4\xint_bye
{%
\csname XINT_keep_finish_b\romannumeral\ifnum#1>#3#3\else#1\fi\endcsname
}%
\long\def\XINT_keep_finish_b #1\xint_bye #2{ #2}%
\long\def\XINT_keep_finish_bi #1#2\xint_bye #3{#3{#1}}%
\long\def\XINT_keep_finish_bii #1#2#3\xint_bye #4{#4{#1}{#2}}%
\long\def\XINT_keep_finish_biii#1#2#3#4\xint_bye #5{#5{#1}{#2}{#3}}%
\long\def\XINT_keep_finish_biv #1#2#3#4#5\xint_bye #6{#6{#1}{#2}{#3}{#4}}%
\long\def\XINT_keep_finish_bv #1#2#3#4#5#6\xint_bye #7{#7{#1}{#2}{#3}{#4}{#5}}%
\long\def\XINT_keep_finish_bvi #1\xint_bye #2{#2#1}%
% \end{macrocode}
% \subsection{\csh{xintKeepUnbraced}}
% \lverb?1.2a. Same as \xintKeep but will *not* add (or maintain) brace pairs
% around the kept items upfront.
%
% There was actually a bug as \xintkeepunbracednoexpand was never defined,
% rather it is \xintkeepnoexpand which got re-defined... belatedly corrected
% for 1.2g?
% \begin{macrocode}
\def\xintKeepUnbraced {\romannumeral0\xintkeepunbraced }%
\def\xintKeepUnbracedNoExpand {\romannumeral0\xintkeepunbracednoexpand }%
\long\def\xintkeepunbraced #1#2%
{\expandafter\XINT_keepunbr_a\the\numexpr #1\expandafter.%
\expandafter{\romannumeral`&&@#2}}%
\def\xintkeepunbracednoexpand #1%
{\expandafter\XINT_keepunbr_a\the\numexpr #1.}%
\def\XINT_keepunbr_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_keep_keepnone }%
0#1{\XINT_keep_neg }%
0-{\XINT_keepunbr_pos #1}%
\krof
}%
\long\def\XINT_keepunbr_pos #1.#2%
{%
\XINT_keepunbr_loop_a #1.%
{}#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_keepunbr_loop_a #1.%
{%
\ifnum #1>\xint_c_vi
\expandafter\XINT_keepunbr_loop_b
\else
\expandafter\XINT_keepunbr_finish
\fi
#1.%
}%
\long\def\XINT_keepunbr_loop_b #1.#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_xint_relax #9\XINT_keepunbr_enda\xint_relax
\expandafter\XINT_keepunbr_loop_c\the\numexpr #1-\xint_c_vii.%
{#3}{#4}{#5}{#6}{#7}{#8}{#9}.{#2}%
}%
\long\def\XINT_keepunbr_loop_c #1.#2#3#4#5#6#7#8.#9%
{\XINT_keepunbr_loop_a #1.{#9#2#3#4#5#6#7#8}}%
\long\def\XINT_keepunbr_enda #1.#2.#3#4\xint_bye
{%
\XINT_keepunbr_endb #4\W\W\W\W\W\W\Z #2{#3}%
}%
\def\XINT_keepunbr_endb #1#2#3#4#5#6#7\Z
{%
\xint_gob_til_W
#1\XINT_keepunbr_endc_
#2\XINT_keepunbr_endc_i
#3\XINT_keepunbr_endc_ii
#4\XINT_keepunbr_endc_iii
#5\XINT_keepunbr_endc_iv
#6\XINT_keepunbr_endc_v
\W\XINT_keepunbr_endc_vi\Z
}%
\long\def\XINT_keepunbr_endc_ #1\Z #2#3#4#5#6#7#8#9{ #9}%
\long\def\XINT_keepunbr_endc_i #1\Z #2#3#4#5#6#7#8#9{ #9#2}%
\long\def\XINT_keepunbr_endc_ii #1\Z #2#3#4#5#6#7#8#9{ #9#2#3}%
\long\def\XINT_keepunbr_endc_iii #1\Z #2#3#4#5#6#7#8#9{ #9#2#3#4}%
\long\def\XINT_keepunbr_endc_iv #1\Z #2#3#4#5#6#7#8#9{ #9#2#3#4#5}%
\long\def\XINT_keepunbr_endc_v #1\Z #2#3#4#5#6#7#8#9{ #9#2#3#4#5#6}%
\long\def\XINT_keepunbr_endc_vi\Z #1#2#3#4#5#6#7#8{ #8#1#2#3#4#5#6}%
\long\def\XINT_keepunbr_finish #1.#2#3#4#5#6#7#8#9\xint_bye
{%
\XINT_keepunbr_finish_a #1.%
#3\xint_c_ #4\xint_c_i #5\xint_c_ii #6\xint_c_iii #7\xint_c_iv
#8\xint_c_v\xint_relax\xint_c_vi\xint_bye
{#3}{#4}{#5}{#6}{#7}{#8}\xint_bye {#2}%
}%
\long\def\XINT_keepunbr_finish_a #1.#2\xint_relax #3#4\xint_bye
{%
\csname XINT_keepunbr_finish_b\romannumeral\ifnum#1>#3#3\else#1\fi\endcsname
}%
\long\def\XINT_keepunbr_finish_b #1\xint_bye #2{ #2}%
\long\def\XINT_keepunbr_finish_bi #1#2\xint_bye #3{ #3#1}%
\long\def\XINT_keepunbr_finish_bii #1#2#3\xint_bye #4{ #4#1#2}%
\long\def\XINT_keepunbr_finish_biii#1#2#3#4\xint_bye #5{ #5#1#2#3}%
\long\def\XINT_keepunbr_finish_biv #1#2#3#4#5\xint_bye #6{ #6#1#2#3#4}%
\long\def\XINT_keepunbr_finish_bv #1#2#3#4#5#6\xint_bye #7{ #7#1#2#3#4#5}%
\long\def\XINT_keepunbr_finish_bvi #1#2#3#4#5#6\xint_bye #7{ #7#1#2#3#4#5#6}%
% \end{macrocode}
% \subsection{\csh{xintTrim}}
% \lverb?&
%
% First included in release 1.09m.
%
% \xintTrim {i}{stuff f-expanding to {a}{b}...{z}} (or `tokens' abcd...z)
% returns (in two expansion steps) the sequence with the first i elements
% omitted. The list is first f-expanded. The i is expanded inside \numexpr.
% Variant \xintTrimNoExpand does not expand the list argument.
%
% With i = 0, the original (expanded) list is returned.
%
% With i<0, the last |i| items are suppressed. In that case the kept elements
% (coming form the head) will be braced on output.
%
% With i>0, the fist |i| items are suppressed: the remaining ones are left as
% is with no added brace pairs.
%
% With |i| equal to or bigger than the length of the (f-expanded) list,
% the empty list is returned.
%
% Cosmetic code improvements (which naturally did cost me time, nothing is
% easy with TeX) for 1.2g to speed up some aspects of token processing.
% ?
% \begin{macrocode}
\def\xintTrim {\romannumeral0\xinttrim }%
\def\xintTrimNoExpand {\romannumeral0\xinttrimnoexpand }%
\long\def\xinttrim #1#2{\expandafter\XINT_trim_a\the\numexpr #1\expandafter.%
\expandafter{\romannumeral`&&@#2}}%
\def\xinttrimnoexpand #1{\expandafter\XINT_trim_a\the\numexpr #1.}%
\def\XINT_trim_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_trim_trimnone }%
0#1{\XINT_trim_neg }%
0-{\XINT_trim_pos #1}%
\krof
}%
\long\def\XINT_trim_trimnone .#1{ #1}%
\long\def\XINT_trim_neg #1.#2%
{%
\expandafter\XINT_trim_neg_a\the\numexpr
\XINT_length_loop
0.#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye -#1.%
{}#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_trim_neg_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_trim_trimall }%
0#1{\XINT_trim_trimall }%
0-{\XINT_keep_loop_a #1}%
\krof
}%
\long\def\XINT_trim_trimall #1\xint_bye { }%
\long\def\XINT_trim_pos #1.#2%
{%
\XINT_trim_loop_a #1.%
#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_trim_loop_a #1.%
{%
\ifnum #1>\xint_c_vii
\expandafter\XINT_trim_loop_b
\else
\expandafter\XINT_trim_finish
\fi
#1.%
}%
\long\def\XINT_trim_loop_b #1.#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_xint_relax #9\XINT_trim_silentend\xint_relax
\expandafter\XINT_trim_loop_a\the\numexpr #1-\xint_c_viii.%
}%
\def\XINT_trim_silentend #1\xint_bye { }%
\def\XINT_trim_finish #1.%
{%
\expandafter\expandafter\expandafter\XINT_trim_finish_a
\expandafter\expandafter\expandafter\space % avoids brace removal
\csname xint_gobble_\romannumeral#1\endcsname
}%
\long\def\XINT_trim_finish_a #1\xint_relax #2\xint_bye {#1}%
% \end{macrocode}
% \subsection{\csh{xintTrimUnbraced}}
% \lverb?1.2a
%
% Missing long for \xinttrimunbraced added belatedly with 1.2g, which also
% modifies a bit the coding style, to match new versions of \xintKeep and
% \xintTrim.
% ?
% \begin{macrocode}
\def\xintTrimUnbraced {\romannumeral0\xinttrimunbraced }%
\def\xintTrimUnbracedNoExpand {\romannumeral0\xinttrimunbracednoexpand }%
\long\def\xinttrimunbraced #1#2%
{\expandafter\XINT_trimunbr_a\the\numexpr #1\expandafter.%
\expandafter{\romannumeral`&&@#2}}%
\def\xinttrimunbracednoexpand #1%
{\expandafter\XINT_trimunbr_a\the\numexpr #1.}%
\def\XINT_trimunbr_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_trim_trimnone }%
0#1{\XINT_trimunbr_neg }%
0-{\XINT_trim_pos #1}%
\krof
}%
\long\def\XINT_trimunbr_neg #1.#2%
{%
\expandafter\XINT_trimunbr_neg_a\the\numexpr
\XINT_length_loop
0.#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye -#1.%
{}#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_trimunbr_neg_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_trim_trimall }%
0#1{\XINT_trim_trimall }%
0-{\XINT_keepunbr_loop_a #1}%
\krof
}%
% \end{macrocode}
% \subsection{\csh{xintApply}}
% \lverb|\xintApply {\macro}{{a}{b}...{z}} returns {\macro{a}}...{\macro{b}}
% where each instance of \macro is f-expanded. The list itself is first
% f-expanded and may thus be a macro. Introduced with release 1.04.|
% \begin{macrocode}
\def\xintApply {\romannumeral0\xintapply }%
\def\xintApplyNoExpand {\romannumeral0\xintapplynoexpand }%
\long\def\xintapply #1#2%
{%
\expandafter\XINT_apply\expandafter {\romannumeral`&&@#2}%
{#1}%
}%
\long\def\XINT_apply #1#2{\XINT_apply_loop_a {}{#2}#1\xint_bye }%
\long\def\xintapplynoexpand #1#2{\XINT_apply_loop_a {}{#1}#2\xint_bye }%
\long\def\XINT_apply_loop_a #1#2#3%
{%
\xint_bye #3\XINT_apply_end\xint_bye
\expandafter
\XINT_apply_loop_b
\expandafter {\romannumeral`&&@#2{#3}}{#1}{#2}%
}%
\long\def\XINT_apply_loop_b #1#2{\XINT_apply_loop_a {#2{#1}}}%
\long\def\XINT_apply_end\xint_bye\expandafter\XINT_apply_loop_b
\expandafter #1#2#3{ #2}%
% \end{macrocode}
% \subsection{\csh{xintApplyUnbraced}}
% \lverb|\xintApplyUnbraced {\macro}{{a}{b}...{z}} returns \macro{a}...\macro{z}
% where each instance of \macro is f-expanded using \romannumeral-`0. The second
% argument may be a macro as it is itself also f-expanded. No braces
% are added: this allows for example a non-expandable \def in \macro, without
% having to do \gdef. Introduced with release 1.06b.|
% \begin{macrocode}
\def\xintApplyUnbraced {\romannumeral0\xintapplyunbraced }%
\def\xintApplyUnbracedNoExpand {\romannumeral0\xintapplyunbracednoexpand }%
\long\def\xintapplyunbraced #1#2%
{%
\expandafter\XINT_applyunbr\expandafter {\romannumeral`&&@#2}%
{#1}%
}%
\long\def\XINT_applyunbr #1#2{\XINT_applyunbr_loop_a {}{#2}#1\xint_bye }%
\long\def\xintapplyunbracednoexpand #1#2%
{\XINT_applyunbr_loop_a {}{#1}#2\xint_bye }%
\long\def\XINT_applyunbr_loop_a #1#2#3%
{%
\xint_bye #3\XINT_applyunbr_end\xint_bye
\expandafter\XINT_applyunbr_loop_b
\expandafter {\romannumeral`&&@#2{#3}}{#1}{#2}%
}%
\long\def\XINT_applyunbr_loop_b #1#2{\XINT_applyunbr_loop_a {#2#1}}%
\long\def\XINT_applyunbr_end\xint_bye\expandafter\XINT_applyunbr_loop_b
\expandafter #1#2#3{ #2}%
% \end{macrocode}
% \subsection{\csh{xintSeq}}
% \lverb|1.09c. Without the optional argument puts stress on the input stack,
% should not be used to generated thousands of terms then.|
% \begin{macrocode}
\def\xintSeq {\romannumeral0\xintseq }%
\def\xintseq #1{\XINT_seq_chkopt #1\xint_bye }%
\def\XINT_seq_chkopt #1%
{%
\ifx [#1\expandafter\XINT_seq_opt
\else\expandafter\XINT_seq_noopt
\fi #1%
}%
\def\XINT_seq_noopt #1\xint_bye #2%
{%
\expandafter\XINT_seq\expandafter
{\the\numexpr#1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_seq #1#2%
{%
\ifcase\ifnum #1=#2 0\else\ifnum #2>#1 1\else -1\fi\fi\space
\expandafter\xint_firstoftwo_thenstop
\or
\expandafter\XINT_seq_p
\else
\expandafter\XINT_seq_n
\fi
{#2}{#1}%
}%
\def\XINT_seq_p #1#2%
{%
\ifnum #1>#2
\expandafter\expandafter\expandafter\XINT_seq_p
\else
\expandafter\XINT_seq_e
\fi
\expandafter{\the\numexpr #1-\xint_c_i}{#2}{#1}%
}%
\def\XINT_seq_n #1#2%
{%
\ifnum #1<#2
\expandafter\expandafter\expandafter\XINT_seq_n
\else
\expandafter\XINT_seq_e
\fi
\expandafter{\the\numexpr #1+\xint_c_i}{#2}{#1}%
}%
\def\XINT_seq_e #1#2#3{ }%
\def\XINT_seq_opt [\xint_bye #1]#2#3%
{%
\expandafter\XINT_seqo\expandafter
{\the\numexpr #2\expandafter}\expandafter
{\the\numexpr #3\expandafter}\expandafter
{\the\numexpr #1}%
}%
\def\XINT_seqo #1#2%
{%
\ifcase\ifnum #1=#2 0\else\ifnum #2>#1 1\else -1\fi\fi\space
\expandafter\XINT_seqo_a
\or
\expandafter\XINT_seqo_pa
\else
\expandafter\XINT_seqo_na
\fi
{#1}{#2}%
}%
\def\XINT_seqo_a #1#2#3{ {#1}}%
\def\XINT_seqo_o #1#2#3#4{ #4}%
\def\XINT_seqo_pa #1#2#3%
{%
\ifcase\ifnum #3=\xint_c_ 0\else\ifnum #3>\xint_c_ 1\else -1\fi\fi\space
\expandafter\XINT_seqo_o
\or
\expandafter\XINT_seqo_pb
\else
\xint_afterfi{\expandafter\space\xint_gobble_iv}%
\fi
{#1}{#2}{#3}{{#1}}%
}%
\def\XINT_seqo_pb #1#2#3%
{%
\expandafter\XINT_seqo_pc\expandafter{\the\numexpr #1+#3}{#2}{#3}%
}%
\def\XINT_seqo_pc #1#2%
{%
\ifnum #1>#2
\expandafter\XINT_seqo_o
\else
\expandafter\XINT_seqo_pd
\fi
{#1}{#2}%
}%
\def\XINT_seqo_pd #1#2#3#4{\XINT_seqo_pb {#1}{#2}{#3}{#4{#1}}}%
\def\XINT_seqo_na #1#2#3%
{%
\ifcase\ifnum #3=\xint_c_ 0\else\ifnum #3>\xint_c_ 1\else -1\fi\fi\space
\expandafter\XINT_seqo_o
\or
\xint_afterfi{\expandafter\space\xint_gobble_iv}%
\else
\expandafter\XINT_seqo_nb
\fi
{#1}{#2}{#3}{{#1}}%
}%
\def\XINT_seqo_nb #1#2#3%
{%
\expandafter\XINT_seqo_nc\expandafter{\the\numexpr #1+#3}{#2}{#3}%
}%
\def\XINT_seqo_nc #1#2%
{%
\ifnum #1<#2
\expandafter\XINT_seqo_o
\else
\expandafter\XINT_seqo_nd
\fi
{#1}{#2}%
}%
\def\XINT_seqo_nd #1#2#3#4{\XINT_seqo_nb {#1}{#2}{#3}{#4{#1}}}%
% \end{macrocode}
%\subsection{\csh{xintloop}, \csh{xintbreakloop}, \csh{xintbreakloopanddo},
% \csh{xintloopskiptonext}}
% \lverb|1.09g [2013/11/22]. Made long with 1.09h.|
% \begin{macrocode}
\long\def\xintloop #1#2\repeat {#1#2\xintloop_again\fi\xint_gobble_i {#1#2}}%
\long\def\xintloop_again\fi\xint_gobble_i #1{\fi
#1\xintloop_again\fi\xint_gobble_i {#1}}%
\long\def\xintbreakloop #1\xintloop_again\fi\xint_gobble_i #2{}%
\long\def\xintbreakloopanddo #1#2\xintloop_again\fi\xint_gobble_i #3{#1}%
\long\def\xintloopskiptonext #1\xintloop_again\fi\xint_gobble_i #2{%
#2\xintloop_again\fi\xint_gobble_i {#2}}%
% \end{macrocode}
% \subsection{\csh{xintiloop}, \csh{xintiloopindex}, \csh{xintouteriloopindex},
% \csh{xintbreakiloop}, \csh{xintbreakiloopanddo}, \csh{xintiloopskiptonext},
% \csh{xintiloopskipandredo}}
% \lverb|1.09g [2013/11/22]. Made long with 1.09h.|
% \begin{macrocode}
\def\xintiloop [#1+#2]{%
\expandafter\xintiloop_a\the\numexpr #1\expandafter.\the\numexpr #2.}%
\long\def\xintiloop_a #1.#2.#3#4\repeat{%
#3#4\xintiloop_again\fi\xint_gobble_iii {#1}{#2}{#3#4}}%
\def\xintiloop_again\fi\xint_gobble_iii #1#2{%
\fi\expandafter\xintiloop_again_b\the\numexpr#1+#2.#2.}%
\long\def\xintiloop_again_b #1.#2.#3{%
#3\xintiloop_again\fi\xint_gobble_iii {#1}{#2}{#3}}%
\long\def\xintbreakiloop #1\xintiloop_again\fi\xint_gobble_iii #2#3#4{}%
\long\def\xintbreakiloopanddo
#1.#2\xintiloop_again\fi\xint_gobble_iii #3#4#5{#1}%
\long\def\xintiloopindex #1\xintiloop_again\fi\xint_gobble_iii #2%
{#2#1\xintiloop_again\fi\xint_gobble_iii {#2}}%
\long\def\xintouteriloopindex #1\xintiloop_again
#2\xintiloop_again\fi\xint_gobble_iii #3%
{#3#1\xintiloop_again #2\xintiloop_again\fi\xint_gobble_iii {#3}}%
\long\def\xintiloopskiptonext #1\xintiloop_again\fi\xint_gobble_iii #2#3{%
\expandafter\xintiloop_again_b \the\numexpr#2+#3.#3.}%
\long\def\xintiloopskipandredo #1\xintiloop_again\fi\xint_gobble_iii #2#3#4{%
#4\xintiloop_again\fi\xint_gobble_iii {#2}{#3}{#4}}%
% \end{macrocode}
% \subsection{\csh{XINT_xflet}}
% \lverb|1.09e [2013/10/29]: we f-expand unbraced tokens and swallow arising
% space tokens until the dust settles.|
% \begin{macrocode}
\def\XINT_xflet #1%
{%
\def\XINT_xflet_macro {#1}\XINT_xflet_zapsp
}%
\def\XINT_xflet_zapsp
{%
\expandafter\futurelet\expandafter\XINT_token
\expandafter\XINT_xflet_sp?\romannumeral`&&@%
}%
\def\XINT_xflet_sp?
{%
\ifx\XINT_token\XINT_sptoken
\expandafter\XINT_xflet_zapsp
\else\expandafter\XINT_xflet_zapspB
\fi
}%
\def\XINT_xflet_zapspB
{%
\expandafter\futurelet\expandafter\XINT_tokenB
\expandafter\XINT_xflet_spB?\romannumeral`&&@%
}%
\def\XINT_xflet_spB?
{%
\ifx\XINT_tokenB\XINT_sptoken
\expandafter\XINT_xflet_zapspB
\else\expandafter\XINT_xflet_eq?
\fi
}%
\def\XINT_xflet_eq?
{%
\ifx\XINT_token\XINT_tokenB
\expandafter\XINT_xflet_macro
\else\expandafter\XINT_xflet_zapsp
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintApplyInline}}
% \lverb|1.09a: \xintApplyInline\macro{{a}{b}...{z}} has the same effect as
% executing \macro{a} and then applying again \xintApplyInline to the shortened
% list {{b}...{z}} until nothing is left. This is a non-expandable command
% which will result in quicker code than using \xintApplyUnbraced. It f-expands
% its second (list) argument first, which may thus be encapsulated in a macro.
%
% Rewritten in 1.09c. Nota bene: uses catcode 3 Z as privated list terminator.|
% \begin{macrocode}
\catcode`Z 3
\long\def\xintApplyInline #1#2%
{%
\long\expandafter\def\expandafter\XINT_inline_macro
\expandafter ##\expandafter 1\expandafter {#1{##1}}%
\XINT_xflet\XINT_inline_b #2Z% this Z has catcode 3
}%
\def\XINT_inline_b
{%
\ifx\XINT_token Z\expandafter\xint_gobble_i
\else\expandafter\XINT_inline_d\fi
}%
\long\def\XINT_inline_d #1%
{%
\long\def\XINT_item{{#1}}\XINT_xflet\XINT_inline_e
}%
\def\XINT_inline_e
{%
\ifx\XINT_token Z\expandafter\XINT_inline_w
\else\expandafter\XINT_inline_f\fi
}%
\def\XINT_inline_f
{%
\expandafter\XINT_inline_g\expandafter{\XINT_inline_macro {##1}}%
}%
\long\def\XINT_inline_g #1%
{%
\expandafter\XINT_inline_macro\XINT_item
\long\def\XINT_inline_macro ##1{#1}\XINT_inline_d
}%
\def\XINT_inline_w #1%
{%
\expandafter\XINT_inline_macro\XINT_item
}%
% \end{macrocode}
% \subsection{\csh{xintFor}, \csh{xintFor*}, \csh{xintBreakFor}, \csh{xintBreakForAndDo}}
% \lverb|1.09c [2013/10/09]: a new kind of loop which uses macro parameters
% #1, #2, #3, #4 rather than macros; while not expandable it survives executing
% code closing groups, like what happens in an alignment with the $& character.
% When inserted in a macro for later use, the # character must be doubled.
%
% The non-star variant works on a csv list, which it expands once, the
% star variant works on a token list, which it (repeatedly) f-expands.
%
% 1.09e adds \XINT_forever with \xintintegers, \xintdimensions, \xintrationals
% and \xintBreakFor, \xintBreakForAndDo, \xintifForFirst, \xintifForLast. On
% this occasion \xint_firstoftwo and \xint_secondoftwo are made long.
%
% 1.09f: rewrites large parts of \xintFor code in order to filter the comma
% separated list via \xintCSVtoList which gets rid of spaces. The #1 in
% \XINT_for_forever? has an initial space token which serves two purposes:
% preventing brace stripping, and stopping the expansion made by \xintcsvtolist.
% If the \XINT_forever branch is taken, the added space will not be a problem
% there.
%
% 1.09f rewrites (2013/11/03) the code which now allows all macro parameters
% from #1 to #9 in \xintFor, \xintFor*, and \XINT_forever.|
% \begin{macrocode}
\def\XINT_tmpa #1#2{\ifnum #2<#1 \xint_afterfi {{#########2}}\fi}%
\def\XINT_tmpb #1#2{\ifnum #1<#2 \xint_afterfi {{#########2}}\fi}%
\def\XINT_tmpc #1%
{%
\expandafter\edef \csname XINT_for_left#1\endcsname
{\xintApplyUnbraced {\XINT_tmpa #1}{123456789}}%
\expandafter\edef \csname XINT_for_right#1\endcsname
{\xintApplyUnbraced {\XINT_tmpb #1}{123456789}}%
}%
\xintApplyInline \XINT_tmpc {123456789}%
\long\def\xintBreakFor #1Z{}%
\long\def\xintBreakForAndDo #1#2Z{#1}%
\def\xintFor {\let\xintifForFirst\xint_firstoftwo
\futurelet\XINT_token\XINT_for_ifstar }%
\def\XINT_for_ifstar {\ifx\XINT_token*\expandafter\XINT_forx
\else\expandafter\XINT_for \fi }%
\catcode`U 3 % with numexpr
\catcode`V 3 % with xintfrac.sty (xint.sty not enough)
\catcode`D 3 % with dimexpr
\def\XINT_flet_zapsp
{%
\futurelet\XINT_token\XINT_flet_sp?
}%
\def\XINT_flet_sp?
{%
\ifx\XINT_token\XINT_sptoken
\xint_afterfi{\expandafter\XINT_flet_zapsp\romannumeral0}%
\else\expandafter\XINT_flet_macro
\fi
}%
\long\def\XINT_for #1#2in#3#4#5%
{%
\expandafter\XINT_toks\expandafter
{\expandafter\XINT_for_d\the\numexpr #2\relax {#5}}%
\def\XINT_flet_macro {\expandafter\XINT_for_forever?\space}%
\expandafter\XINT_flet_zapsp #3Z%
}%
\def\XINT_for_forever? #1Z%
{%
\ifx\XINT_token U\XINT_to_forever\fi
\ifx\XINT_token V\XINT_to_forever\fi
\ifx\XINT_token D\XINT_to_forever\fi
\expandafter\the\expandafter\XINT_toks\romannumeral0\xintcsvtolist {#1}Z%
}%
\def\XINT_to_forever\fi #1\xintcsvtolist #2{\fi \XINT_forever #2}%
\long\def\XINT_forx *#1#2in#3#4#5%
{%
\expandafter\XINT_toks\expandafter
{\expandafter\XINT_forx_d\the\numexpr #2\relax {#5}}%
\XINT_xflet\XINT_forx_forever? #3Z%
}%
\def\XINT_forx_forever?
{%
\ifx\XINT_token U\XINT_to_forxever\fi
\ifx\XINT_token V\XINT_to_forxever\fi
\ifx\XINT_token D\XINT_to_forxever\fi
\XINT_forx_empty?
}%
\def\XINT_to_forxever\fi #1\XINT_forx_empty? {\fi \XINT_forever }%
\catcode`U 11
\catcode`D 11
\catcode`V 11
\def\XINT_forx_empty?
{%
\ifx\XINT_token Z\expandafter\xintBreakFor\fi
\the\XINT_toks
}%
\long\def\XINT_for_d #1#2#3%
{%
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}%
\XINT_toks {{#3}}%
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname
\the\XINT_toks \csname XINT_for_right#1\endcsname }%
\XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_for_d #1{#2}}%
\futurelet\XINT_token\XINT_for_last?
}%
\long\def\XINT_forx_d #1#2#3%
{%
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}%
\XINT_toks {{#3}}%
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname
\the\XINT_toks \csname XINT_for_right#1\endcsname }%
\XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo\XINT_forx_d #1{#2}}%
\XINT_xflet\XINT_for_last?
}%
\def\XINT_for_last?
{%
\let\xintifForLast\xint_secondoftwo
\ifx\XINT_token Z\let\xintifForLast\xint_firstoftwo
\xint_afterfi{\xintBreakForAndDo{\XINT_x\xint_gobble_i Z}}\fi
\the\XINT_toks
}%
% \end{macrocode}
% \subsection{\csh{XINT_forever}, \csh{xintintegers}, \csh{xintdimensions}, \csh{xintrationals}}
% \lverb|New with 1.09e. But this used inadvertently \xintiadd/\xintimul which
% have the unnecessary \xintnum overhead. Changed in 1.09f to use
% \xintiiadd/\xintiimul which do not have this overhead. Also 1.09f uses
% \xintZapSpacesB for the \xintrationals case to get rid of leading and ending
% spaces in the #4 and #5 delimited parameters of \XINT_forever_opt_a
% (for \xintintegers and \xintdimensions this is not necessary, due to the use
% of \numexpr resp. \dimexpr in \XINT_?expr_Ua, resp.\XINT_?expr_Da).|
% \begin{macrocode}
\catcode`U 3
\catcode`D 3
\catcode`V 3
\let\xintegers U%
\let\xintintegers U%
\let\xintdimensions D%
\let\xintrationals V%
\def\XINT_forever #1%
{%
\expandafter\XINT_forever_a
\csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi a\expandafter\endcsname
\csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi i\expandafter\endcsname
\csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi \endcsname
}%
\catcode`U 11
\catcode`D 11
\catcode`V 11
\def\XINT_?expr_Ua #1#2%
{\expandafter{\expandafter\numexpr\the\numexpr #1\expandafter\relax
\expandafter\relax\expandafter}%
\expandafter{\the\numexpr #2}}%
\def\XINT_?expr_Da #1#2%
{\expandafter{\expandafter\dimexpr\number\dimexpr #1\expandafter\relax
\expandafter s\expandafter p\expandafter\relax\expandafter}%
\expandafter{\number\dimexpr #2}}%
\catcode`Z 11
\def\XINT_?expr_Va #1#2%
{%
\expandafter\XINT_?expr_Vb\expandafter
{\romannumeral`&&@\xintrawwithzeros{\xintZapSpacesB{#2}}}%
{\romannumeral`&&@\xintrawwithzeros{\xintZapSpacesB{#1}}}%
}%
\catcode`Z 3
\def\XINT_?expr_Vb #1#2{\expandafter\XINT_?expr_Vc #2.#1.}%
\def\XINT_?expr_Vc #1/#2.#3/#4.%
{%
\xintifEq {#2}{#4}%
{\XINT_?expr_Vf {#3}{#1}{#2}}%
{\expandafter\XINT_?expr_Vd\expandafter
{\romannumeral0\xintiimul {#2}{#4}}%
{\romannumeral0\xintiimul {#1}{#4}}%
{\romannumeral0\xintiimul {#2}{#3}}%
}%
}%
\def\XINT_?expr_Vd #1#2#3{\expandafter\XINT_?expr_Ve\expandafter {#2}{#3}{#1}}%
\def\XINT_?expr_Ve #1#2{\expandafter\XINT_?expr_Vf\expandafter {#2}{#1}}%
\def\XINT_?expr_Vf #1#2#3{{#2/#3}{{0}{#1}{#2}{#3}}}%
\def\XINT_?expr_Ui {{\numexpr 1\relax}{1}}%
\def\XINT_?expr_Di {{\dimexpr 0pt\relax}{65536}}%
\def\XINT_?expr_Vi {{1/1}{0111}}%
\def\XINT_?expr_U #1#2%
{\expandafter{\expandafter\numexpr\the\numexpr #1+#2\relax\relax}{#2}}%
\def\XINT_?expr_D #1#2%
{\expandafter{\expandafter\dimexpr\the\numexpr #1+#2\relax sp\relax}{#2}}%
\def\XINT_?expr_V #1#2{\XINT_?expr_Vx #2}%
\def\XINT_?expr_Vx #1#2%
{%
\expandafter\XINT_?expr_Vy\expandafter
{\romannumeral0\xintiiadd {#1}{#2}}{#2}%
}%
\def\XINT_?expr_Vy #1#2#3#4%
{%
\expandafter{\romannumeral0\xintiiadd {#3}{#1}/#4}{{#1}{#2}{#3}{#4}}%
}%
\def\XINT_forever_a #1#2#3#4%
{%
\ifx #4[\expandafter\XINT_forever_opt_a
\else\expandafter\XINT_forever_b
\fi #1#2#3#4%
}%
\def\XINT_forever_b #1#2#3Z{\expandafter\XINT_forever_c\the\XINT_toks #2#3}%
\long\def\XINT_forever_c #1#2#3#4#5%
{\expandafter\XINT_forever_d\expandafter #2#4#5{#3}Z}%
\def\XINT_forever_opt_a #1#2#3[#4+#5]#6Z%
{%
\expandafter\expandafter\expandafter
\XINT_forever_opt_c\expandafter\the\expandafter\XINT_toks
\romannumeral`&&@#1{#4}{#5}#3%
}%
\long\def\XINT_forever_opt_c #1#2#3#4#5#6{\XINT_forever_d #2{#4}{#5}#6{#3}Z}%
\long\def\XINT_forever_d #1#2#3#4#5%
{%
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#5}%
\XINT_toks {{#2}}%
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname
\the\XINT_toks \csname XINT_for_right#1\endcsname }%
\XINT_x
\let\xintifForFirst\xint_secondoftwo
\expandafter\XINT_forever_d\expandafter #1\romannumeral`&&@#4{#2}{#3}#4{#5}%
}%
% \end{macrocode}
% \subsection{\csh{xintForpair}, \csh{xintForthree}, \csh{xintForfour}}
% \lverb|1.09c.
%
% [2013/11/02] 1.09f \xintForpair delegate to \xintCSVtoList and its
% \xintZapSpacesB the handling of spaces. Does not share code with \xintFor
% anymore.
%
% [2013/11/03] 1.09f: \xintForpair extended to accept #1#2, #2#3 etc... up to
% #8#9, \xintForthree, #1#2#3 up to #7#8#9, \xintForfour id. |
% \begin{macrocode}
\catcode`j 3
\long\def\xintForpair #1#2#3in#4#5#6%
{%
\let\xintifForFirst\xint_firstoftwo
\XINT_toks {\XINT_forpair_d #2{#6}}%
\expandafter\the\expandafter\XINT_toks #4jZ%
}%
\long\def\XINT_forpair_d #1#2#3(#4)#5%
{%
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}%
\XINT_toks \expandafter{\romannumeral0\xintcsvtolist{ #4}}%
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname
\the\XINT_toks \csname XINT_for_right\the\numexpr#1+\xint_c_i\endcsname}%
\let\xintifForLast\xint_secondoftwo
\ifx #5j\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi
{\let\xintifForLast\xint_firstoftwo
\xintBreakForAndDo {\XINT_x \xint_gobble_i Z}}%
\XINT_x
\let\xintifForFirst\xint_secondoftwo\XINT_forpair_d #1{#2}%
}%
\long\def\xintForthree #1#2#3in#4#5#6%
{%
\let\xintifForFirst\xint_firstoftwo
\XINT_toks {\XINT_forthree_d #2{#6}}%
\expandafter\the\expandafter\XINT_toks #4jZ%
}%
\long\def\XINT_forthree_d #1#2#3(#4)#5%
{%
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}%
\XINT_toks \expandafter{\romannumeral0\xintcsvtolist{ #4}}%
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname
\the\XINT_toks \csname XINT_for_right\the\numexpr#1+\xint_c_ii\endcsname}%
\let\xintifForLast\xint_secondoftwo
\ifx #5j\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi
{\let\xintifForLast\xint_firstoftwo
\xintBreakForAndDo {\XINT_x \xint_gobble_i Z}}%
\XINT_x
\let\xintifForFirst\xint_secondoftwo\XINT_forthree_d #1{#2}%
}%
\long\def\xintForfour #1#2#3in#4#5#6%
{%
\let\xintifForFirst\xint_firstoftwo
\XINT_toks {\XINT_forfour_d #2{#6}}%
\expandafter\the\expandafter\XINT_toks #4jZ%
}%
\long\def\XINT_forfour_d #1#2#3(#4)#5%
{%
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}%
\XINT_toks \expandafter{\romannumeral0\xintcsvtolist{ #4}}%
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname
\the\XINT_toks \csname XINT_for_right\the\numexpr#1+\xint_c_iii\endcsname}%
\let\xintifForLast\xint_secondoftwo
\ifx #5j\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi
{\let\xintifForLast\xint_firstoftwo
\xintBreakForAndDo {\XINT_x \xint_gobble_i Z}}%
\XINT_x
\let\xintifForFirst\xint_secondoftwo\XINT_forfour_d #1{#2}%
}%
\catcode`Z 11
\catcode`j 11
% \end{macrocode}
% \subsection{\csh{xintAssign}, \csh{xintAssignArray}, \csh{xintDigitsOf}}
% \lverb|\xintAssign {a}{b}..{z}\to\A\B...\Z resp. \xintAssignArray
% {a}{b}..{z}\to\U.
%
% \xintDigitsOf=\xintAssignArray.
%
% 1.1c 2015/09/12 has (belatedly) corrected some "features" of
% \xintAssign which didn't like the case of a space right before the "\to", or
% the case with the first token not an opening brace and the subsequent
% material containing brace groups. The new code handles gracefully these
% situations.|
% \begin{macrocode}
\def\xintAssign{\def\XINT_flet_macro {\XINT_assign_fork}\XINT_flet_zapsp }%
\def\XINT_assign_fork
{%
\let\XINT_assign_def\def
\ifx\XINT_token[\expandafter\XINT_assign_opt
\else\expandafter\XINT_assign_a
\fi
}%
\def\XINT_assign_opt [#1]%
{%
\ifcsname #1def\endcsname
\expandafter\let\expandafter\XINT_assign_def \csname #1def\endcsname
\else
\expandafter\let\expandafter\XINT_assign_def \csname xint#1def\endcsname
\fi
\XINT_assign_a
}%
\long\def\XINT_assign_a #1\to
{%
\def\XINT_flet_macro{\XINT_assign_b}%
\expandafter\XINT_flet_zapsp\romannumeral`&&@#1\xint_relax\to
}%
\long\def\XINT_assign_b
{%
\ifx\XINT_token\bgroup
\expandafter\XINT_assign_c
\else\expandafter\XINT_assign_f
\fi
}%
\long\def\XINT_assign_f #1\xint_relax\to #2%
{%
\XINT_assign_def #2{#1}%
}%
\long\def\XINT_assign_c #1%
{%
\def\xint_temp {#1}%
\ifx\xint_temp\xint_brelax
\expandafter\XINT_assign_e
\else
\expandafter\XINT_assign_d
\fi
}%
\long\def\XINT_assign_d #1\to #2%
{%
\expandafter\XINT_assign_def\expandafter #2\expandafter{\xint_temp}%
\XINT_assign_c #1\to
}%
\def\XINT_assign_e #1\to {}%
\def\xintRelaxArray #1%
{%
\edef\XINT_restoreescapechar {\escapechar\the\escapechar\relax}%
\escapechar -1
\expandafter\def\expandafter\xint_arrayname\expandafter {\string #1}%
\XINT_restoreescapechar
\xintiloop [\csname\xint_arrayname 0\endcsname+-1]
\global
\expandafter\let\csname\xint_arrayname\xintiloopindex\endcsname\relax
\ifnum \xintiloopindex > \xint_c_
\repeat
\global\expandafter\let\csname\xint_arrayname 00\endcsname\relax
\global\let #1\relax
}%
\def\xintAssignArray{\def\XINT_flet_macro {\XINT_assignarray_fork}%
\XINT_flet_zapsp }%
\def\XINT_assignarray_fork
{%
\let\XINT_assignarray_def\def
\ifx\XINT_token[\expandafter\XINT_assignarray_opt
\else\expandafter\XINT_assignarray
\fi
}%
\def\XINT_assignarray_opt [#1]%
{%
\ifcsname #1def\endcsname
\expandafter\let\expandafter\XINT_assignarray_def \csname #1def\endcsname
\else
\expandafter\let\expandafter\XINT_assignarray_def
\csname xint#1def\endcsname
\fi
\XINT_assignarray
}%
\long\def\XINT_assignarray #1\to #2%
{%
\edef\XINT_restoreescapechar {\escapechar\the\escapechar\relax }%
\escapechar -1
\expandafter\def\expandafter\xint_arrayname\expandafter {\string #2}%
\XINT_restoreescapechar
\def\xint_itemcount {0}%
\expandafter\XINT_assignarray_loop \romannumeral`&&@#1\xint_relax
\csname\xint_arrayname 00\expandafter\endcsname
\csname\xint_arrayname 0\expandafter\endcsname
\expandafter {\xint_arrayname}#2%
}%
\long\def\XINT_assignarray_loop #1%
{%
\def\xint_temp {#1}%
\ifx\xint_brelax\xint_temp
\expandafter\def\csname\xint_arrayname 0\expandafter\endcsname
\expandafter{\the\numexpr\xint_itemcount}%
\expandafter\expandafter\expandafter\XINT_assignarray_end
\else
\expandafter\def\expandafter\xint_itemcount\expandafter
{\the\numexpr\xint_itemcount+\xint_c_i}%
\expandafter\XINT_assignarray_def
\csname\xint_arrayname\xint_itemcount\expandafter\endcsname
\expandafter{\xint_temp }%
\expandafter\XINT_assignarray_loop
\fi
}%
\def\XINT_assignarray_end #1#2#3#4%
{%
\def #4##1%
{%
\romannumeral0\expandafter #1\expandafter{\the\numexpr ##1}%
}%
\def #1##1%
{%
\ifnum ##1<\xint_c_
\xint_afterfi {\xintError:ArrayIndexIsNegative\space }%
\else
\xint_afterfi {%
\ifnum ##1>#2
\xint_afterfi {\xintError:ArrayIndexBeyondLimit\space }%
\else\xint_afterfi
{\expandafter\expandafter\expandafter\space\csname #3##1\endcsname}%
\fi}%
\fi
}%
}%
\let\xintDigitsOf\xintAssignArray
% \end{macrocode}
%\subsection{CSV (non user documented) variants of Trim, Keep, NthElt, Reverse, Length}
%
% These routines are for use by |\xintListSel:f:csv| from \xintexprnameimp. We
% don't take any precaution here regarding brace stripping or spaces. And the
% macros are short. They will remain undocumented in the user manual for the
% time being for the reasons above and to preserve the possibility to modify
% the interface in case some evolution on the \xintexprnameimp side requires
% it.
%
% Nevertheless, directly usable names are also provided.
%
% All these macros are in the |O(N^2)| style when they need to accumulate
% things. They handle comma separated values. There is no final comma, neither
% on input nor on output. Special care has been taken to handle safely the
% case of an empty list.
%
%\subsubsection{\csh{xintTrim:f:csv}}
% \lverb|1.2g 2016/03/17.
%
%|
% \begin{macrocode}
\def\xintTrim:f:csv {\romannumeral0\xinttrim:f:csv }%
\def\xinttrim:f:csv #1#2%
{%
\expandafter\XINT_trim:f:csv_a\the\numexpr #1\expandafter.%
\romannumeral`&&@#2\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
}%
\def\XINT_trim:f:csv_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_trim:f:csv_zero }%
0#1{\XINT_trim:f:csv_neg }%
0-{\XINT_trim:f:csv_loop_a #1}%
\krof
}%
\def\XINT_trim:f:csv_zero .#1\xint_relax #2\xint_bye{ #1}%
\def\XINT_trim:f:csv_neg #1.#2\xint_relax%
{%
\expandafter\XINT_trim:f:csv_neg_b
\the\numexpr\XINT_length:f:csv_a #2%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
-#1.#2\xint_relax
}%
\def\XINT_trim:f:csv_neg_b #1%
{%
\xint_UDzerominusfork
#1-{\expandafter\space\xint_bye }%
0#1{\expandafter\space\xint_bye }%
0-{\XINT_keep:f:csv_pos #1}%
\krof
}%
\def\XINT_trim:f:csv_loop_a #1.%
{%
\ifnum #1>\xint_c_vii
\expandafter\XINT_trim:f:csv_loop_b
\else
\expandafter\XINT_trim:f:csv_finish
\fi
#1.%
}%
\def\XINT_trim:f:csv_loop_b #1.#2,#3,#4,#5,#6,#7,#8,#9,%
{%
\xint_gob_til_xint_relax #9\XINT_trim:f:csv_silentend\xint_relax
\expandafter\XINT_trim:f:csv_loop_a\the\numexpr #1-\xint_c_viii.%
}%
\def\XINT_trim:f:csv_silentend #1\xint_bye { }%
\def\XINT_trim:f:csv_finish #1.%
{%
\expandafter\XINT_trim:f:csv_finish_a
\romannumeral`&&@\csname xint_gobble:csv_\romannumeral#1\endcsname
}%
\def\xint_gobble:csv_ {}%
\def\xint_gobble:csv_i #1,{}%
\def\xint_gobble:csv_ii #1,#2,{}%
\def\xint_gobble:csv_iii #1,#2,#3,{}%
\def\xint_gobble:csv_iv #1,#2,#3,#4,{}%
\def\xint_gobble:csv_v #1,#2,#3,#4,#5,{}%
\def\xint_gobble:csv_vi #1,#2,#3,#4,#5,#6,{}%
\def\xint_gobble:csv_vii #1,#2,#3,#4,#5,#6,#7,{}%
\def\XINT_trim:f:csv_finish_a #1\xint_relax #2\xint_bye { #1}%
% \end{macrocode}
%\subsubsection{\csh{xintKeep:f:csv}}
% \lverb|1.2g 2016/03/17.
%|
% \begin{macrocode}
\def\xintKeep:f:csv {\romannumeral0\xintkeep:f:csv }%
\def\xintkeep:f:csv #1#2%
{%
\expandafter\XINT_keep:f:csv_a\the\numexpr #1\expandafter.%
\romannumeral`&&@#2\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
}%
\def\XINT_keep:f:csv_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_keep:f:csv_zero }%
0#1{\XINT_keep:f:csv_neg }%
0-{\XINT_keep:f:csv_pos #1}%
\krof
}%
\def\XINT_keep:f:csv_zero .#1\xint_bye{ }%
\def\XINT_keep:f:csv_neg #1.#2\xint_relax%
{%
\expandafter\XINT_keep:f:csv_neg_b
\the\numexpr\XINT_length:f:csv_a #2%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
-#1.#2\xint_relax
}%
\def\XINT_keep:f:csv_neg_b #1%
{%
\xint_UDzerominusfork
#1-{\XINT_keep:f:csv_all }%
0#1{\XINT_keep:f:csv_all }%
0-{\XINT_trim:f:csv_loop_a #1}%
\krof
}%
\def\XINT_keep:f:csv_all #1.#2\xint_relax #3\xint_bye { #2}%
\def\XINT_keep:f:csv_pos #1.{\expandafter\xint_gobble_thenstop
\romannumeral`&&@\XINT_keep:f:csv_loop_a #1.{}}%
\def\XINT_keep:f:csv_loop_a #1.%
{%
\ifnum #1>\xint_c_vi
\expandafter\XINT_keep:f:csv_loop_b
\else
\expandafter\XINT_keep:f:csv_finish
\fi
#1.%
}%
\def\XINT_keep:f:csv_loop_b #1.#2#3,#4,#5,#6,#7,#8,#9,%
{%
\xint_gob_til_xint_relax #9\XINT_keep:f:csv_enda\xint_relax
\expandafter\XINT_keep:f:csv_loop_c\the\numexpr #1-\xint_c_vii.%
{,#3,#4,#5,#6,#7,#8,#9}{#2}%
}%
\def\XINT_keep:f:csv_loop_c #1.#2#3{\XINT_keep:f:csv_loop_a #1.{#3#2}}%
\def\XINT_keep:f:csv_enda #1.#2#3#4\xint_bye
{%
\XINT_keep:f:csv_endb #2\xint_bye {#3}%
}%
\def\XINT_keep:f:csv_endb #1\xint_relax #2\xint_bye #3{ #3#1}%
\def\XINT_keep:f:csv_finish #1.#2#3,#4,#5,#6,#7,#8,#9\xint_bye
{%
\csname XINT_keep:f:csv_finish_\romannumeral#1\endcsname
,#3,#4,#5,#6,#7,#8,\Z {#2}%
}%
\def\XINT_keep:f:csv_finish_ #1\Z #2{#2}%
\def\XINT_keep:f:csv_finish_i ,#1,#2\Z
{\XINT_keep:f:csv_finish_f ,#1\xint_relax\Z}%
\def\XINT_keep:f:csv_finish_ii ,#1,#2,#3\Z
{\XINT_keep:f:csv_finish_f ,#1,#2\xint_relax\Z}%
\def\XINT_keep:f:csv_finish_iii ,#1,#2,#3,#4\Z
{\XINT_keep:f:csv_finish_f ,#1,#2,#3\xint_relax\Z}%
\def\XINT_keep:f:csv_finish_iv ,#1,#2,#3,#4,#5\Z
{\XINT_keep:f:csv_finish_f ,#1,#2,#3,#4\xint_relax\Z}%
\def\XINT_keep:f:csv_finish_v ,#1,#2,#3,#4,#5,#6\Z
{\XINT_keep:f:csv_finish_f ,#1,#2,#3,#4,#5\xint_relax\Z}%
\def\XINT_keep:f:csv_finish_vi ,#1,#2,#3,#4,#5,#6,#7\Z
{\XINT_keep:f:csv_finish_f ,#1,#2,#3,#4,#5,#6\xint_relax\Z}%
\def\XINT_keep:f:csv_finish_f #1\xint_relax #2\Z #3{#3#1}%
% \end{macrocode}
% \subsubsection{\csh{xintNthEltPy:f:csv}}
% \lverb|1.2g. 2016/03/17. Counts like Python starting at zero.
% |
% \begin{macrocode}
\def\xintNthEltPy:f:csv {\romannumeral0\xintntheltpy:f:csv }%
\def\xintntheltpy:f:csv #1{\expandafter\XINT_ntheltpy:f:csv\the\numexpr #1.}%
\def\XINT_ntheltpy:f:csv #1%
{%
\xint_UDsignfork
#1{\XINT_nthelt:f:csv_neg }%
-{\XINT_nthelt:f:csv_pos #1}%
\krof
}%
\long\def\XINT_nthelt:f:csv_neg #1.#2%
{%
\expandafter\XINT_nthelt:f:csv_neg_a
\the\numexpr\expandafter\XINT_length:f:csv_a\romannumeral`&&@#2%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
-#1+\xint_c_i\expandafter.\romannumeral`&&@#2%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
}%
\def\XINT_nthelt:f:csv_neg_a #1%
{%
\xint_UDzerominusfork
#1-{\XINT_nthelt:f:csv_none }%
0#1{\XINT_nthelt:f:csv_none }%
0-{\XINT_nthelt:f:csv_loop_a #1}%
\krof
}%
\def\XINT_nthelt:f:csv_none #1\xint_bye { }%
\long\def\XINT_nthelt:f:csv_pos #1.#2%
{%
\expandafter\XINT_nthelt:f:csv_loop_a\the\numexpr #1+\xint_c_i\expandafter.%
\romannumeral`&&@#2%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
}%
\def\XINT_nthelt:f:csv_loop_a #1.%
{%
\ifnum #1>\xint_c_viii
\expandafter\XINT_nthelt:f:csv_loop_b
\else
\expandafter\XINT_nthelt:f:csv_getit
\fi #1.%
}%
\long\def\XINT_nthelt:f:csv_loop_b #1.#2,#3,#4,#5,#6,#7,#8,#9,%
{%
\xint_gob_til_xint_relax #9\XINT_nthelt:f:csv_none\xint_relax
\expandafter\XINT_nthelt:f:csv_loop_a\the\numexpr #1-\xint_c_viii.%
}%
\def\XINT_nthelt:f:csv_getit #1.%
{%
\expandafter\XINT_nthelt:f:csv_finish
\romannumeral`&&@\csname xint_gobble:csv_\romannumeral
\numexpr#1-\xint_c_i\endcsname
}%
\def\XINT_nthelt:f:csv_finish #1,#2\xint_bye
{%
\XINT_nthelt:f:csv_finishb #1\xint_relax\xint_bye
}%
\def\XINT_nthelt:f:csv_finishb #1\xint_relax #2\xint_bye { #1}%
% \end{macrocode}
% \subsubsection{\csh{xintReverse:f:csv}}
% \lverb|1.2g. Contrarily to \xintReverseOrder from xintkernel.sty, this
% one expands its argument. Handles empty list too. 2016/03/17.
% |
% \begin{macrocode}
\def\xintReverse:f:csv {\romannumeral0\xintreverse:f:csv }%
\def\xintreverse:f:csv #1%
{%
\expandafter\XINT_reverse:f:csv_loop
\expandafter{\expandafter}\romannumeral`&&@#1,%
\xint_relax,%
\xint_bye,\xint_bye,\xint_bye,\xint_bye,%
\xint_bye,\xint_bye,\xint_bye,\xint_bye,%
\xint_relax
}%
\def\XINT_reverse:f:csv_loop #1#2,#3,#4,#5,#6,#7,#8,#9,%
{%
\xint_bye #9\XINT_reverse:f:csv_cleanup\xint_bye
\XINT_reverse:f:csv_loop {,#9,#8,#7,#6,#5,#4,#3,#2#1}%
}%
\def\XINT_reverse:f:csv_cleanup\xint_bye\XINT_reverse:f:csv_loop #1#2\xint_relax
{%
\XINT_reverse:f:csv_finish #1%
}%
\def\XINT_reverse:f:csv_finish #1\xint_relax,{ }%
% \end{macrocode}
% \subsubsection{\csh{xintLength:f:csv}}
% \lverb|1.2g. Contrarily to ancestor \xintLength from xintkernel.sty, this
% one expands its argument. 2016/03/17.
% |
% \begin{macrocode}
\def\xintLength:f:csv {\romannumeral0\xintlength:f:csv }%
\def\xintlength:f:csv #1%
{%
\expandafter\XINT_length:f:csv_a
\romannumeral`&&@#1\xint_relax,\xint_relax,\xint_relax,\xint_relax,%
\xint_relax,\xint_relax,\xint_relax,\xint_relax,\xint_bye
}%
\def\XINT_length:f:csv_a #1%
{%
\xint_gob_til_xint_relax #1\XINT_length:f:csv_empty\xint_relax
\XINT_length:f:csv_loop 0.#1%
}%
\def\XINT_length:f:csv_empty #1\xint_bye { 0}%
\def\XINT_length:f:csv_loop #1.#2,#3,#4,#5,#6,#7,#8,#9,%
{%
\xint_gob_til_xint_relax #9\XINT_length:f:csv_finish_a\xint_relax
\expandafter\XINT_length:f:csv_loop\the\numexpr #1+\xint_c_viii.%
}%
\def\XINT_length:f:csv_finish_a\xint_relax
\expandafter\XINT_length:f:csv_loop\the\numexpr #1+\xint_c_viii.#2\xint_bye
{%
\XINT_length:f:csv_finish_b #2\W,\W,\W,\W,\W,\W,\W,\Z {#1}%
}%
\def\XINT_length:f:csv_finish_b #1,#2,#3,#4,#5,#6,#7,#8\Z
{%
\xint_gob_til_W
#1\XINT_length:f:csv_finish_c \xint_c_i
#2\XINT_length:f:csv_finish_c \xint_c_ii
#3\XINT_length:f:csv_finish_c \xint_c_iii
#4\XINT_length:f:csv_finish_c \xint_c_iv
#5\XINT_length:f:csv_finish_c \xint_c_v
#6\XINT_length:f:csv_finish_c \xint_c_vi
#7\XINT_length:f:csv_finish_c \xint_c_vii
\W\XINT_length:f:csv_finish_c \xint_c_viii\Z
}%
\edef\XINT_length:f:csv_finish_c #1#2\Z #3%
{\noexpand\expandafter\space\noexpand\the\numexpr #3+#1\relax}%
% \end{macrocode}
% \subsubsection{Public names for the undocumented csv macros}
% \lverb|1.2g. 2016/03/17.|
% \begin{macrocode}
\let\xintCSVTrim \xintTrim:f:csv
\let\xintCSVKeep \xintKeep:f:csv
\let\xintCSVNthEltPy \xintNthEltPy:f:csv
\let\xintCSVReverse \xintReverse:f:csv
\let\xintCSVLength \xintLength:f:csv
\let\XINT_tmpa\relax \let\XINT_tmpb\relax \let\XINT_tmpc\relax
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xinttools}
%
%\gardesactifs
%\let</xinttools>\relax
%\let<*xintcore>\gardesinactifs
%</xinttools>^^A--------------------------------------------------
%<*xintcore>^^A---------------------------------------------------
% \clearpage
% \section{Package \xintcorenameimp implementation}
% \label{sec:coreimp}
%
% \localtableofcontents
%
% Got split off from \xintnameimp with release |1.1|, which also added
% the new macro |\xintiiDivRound|.
%
% \begin{framed}
% The core arithmetic routines have been entirely rewritten for release
% |1.2|.
%
% The commenting continues (\xintdocdate) to be very sparse: actually it got
% worse than ever with release |1.2|. I will possibly add comments at a
% later date, but for the time being the new routines are not commented at
% all.
% \end{framed}
%
% Also, starting with |1.2|, |\xintAdd| etc... are defined only via
% \xintfracnameimp. Only |\xintiAdd| and |\xintiiAdd| (etc...) are provided
% via \xintcorenameimp.
%
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xintcore.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintkernel.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintcore}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintcore.sty
\ifx\w\relax % but xintkernel.sty not yet loaded.
\def\z{\endgroup\input xintkernel.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintkernel.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintkernel}}%
\fi
\else
\aftergroup\endinput % xintkernel already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintcore}%
[2016/11/20 1.2h Expandable arithmetic on big integers (JFB)]%
% \end{macrocode}
% \subsection{Counts for holding needed constants}
% \begin{macrocode}
\ifdefined\m@ne\let\xint_c_mone\m@ne
\else\csname newcount\endcsname\xint_c_mone \xint_c_mone -1 \fi
\newcount\xint_c_x^viii \xint_c_x^viii 100000000
\newcount\xint_c_x^ix \xint_c_x^ix 1000000000
\newcount\xint_c_x^viii_mone \xint_c_x^viii_mone 99999999
\newcount\xint_c_xii_e_viii \xint_c_xii_e_viii 1200000000
\newcount\xint_c_xi_e_viii_mone \xint_c_xi_e_viii_mone 1099999999
\newcount\xint_c_xii_e_viii_mone\xint_c_xii_e_viii_mone 1199999999
% \end{macrocode}
% \subsection{\csh{xintNum}}
% \lverb|&
% For example \xintNum {----+-+++---+----000000000000003}$\
% |
% \begin{macrocode}
\def\xintiNum {\romannumeral0\xintinum }%
\def\xintinum #1%
{%
\expandafter\XINT_num_loop
\romannumeral`&&@#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z
}%
\let\xintNum\xintiNum \let\xintnum\xintinum
\def\XINT_num #1%
{%
\XINT_num_loop #1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z
}%
\def\XINT_num_loop #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_xint_relax #8\XINT_num_end\xint_relax
\XINT_num_NumEight #1#2#3#4#5#6#7#8%
}%
\edef\XINT_num_end\xint_relax\XINT_num_NumEight #1\xint_relax #2\Z
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1+\xint_c_\relax
}%
\def\XINT_num_NumEight #1#2#3#4#5#6#7#8%
{%
\ifnum \numexpr #1#2#3#4#5#6#7#8+\xint_c_= \xint_c_
\xint_afterfi {\expandafter\XINT_num_keepsign_a
\the\numexpr #1#2#3#4#5#6#7#81\relax}%
\else
\xint_afterfi {\expandafter\XINT_num_finish
\the\numexpr #1#2#3#4#5#6#7#8\relax}%
\fi
}%
\def\XINT_num_keepsign_a #1%
{%
\xint_gob_til_one#1\XINT_num_gobacktoloop 1\XINT_num_keepsign_b
}%
\def\XINT_num_gobacktoloop 1\XINT_num_keepsign_b {\XINT_num_loop }%
\def\XINT_num_keepsign_b #1{\XINT_num_loop -}%
\def\XINT_num_finish #1\xint_relax #2\Z { #1}%
% \end{macrocode}
% \subsection{Zeroes}
% \lverb|Everything had to be changed for 1.2 as it does computations by
% blocks of eight digits rather than four.
%
% Currently many macros are launched by a \romannumeral0. Perhaps I should
% have used \romannumeral and end expansion by \z@ (\xint_c_).
%
% \XINT_cuz_small removes leading zeroes from the first eight digits. Supposed
% to have been launched by a \romannumeral0. At least one digit is produced.|
% \begin{macrocode}
\edef\XINT_cuz_small #1#2#3#4#5#6#7#8%
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8\relax
}%
% \end{macrocode}
% \lverb|This iterately removes all leading zeroes from a sequence of 8N
% digits ended by \R.
%
% Note 2015/11/28: with only four digits the gob_til_fourzeroes had proved
% in some old testing faster than \ifnum test. But with eight digits, the
% execution times are much closer, as I tested only now. Thus, one could as
% well use \ifnum test here. Besides the tests were not exactly for a
% situation like here where \XINT_cuz_z has two 00000000 blocks to grab.|
% \begin{macrocode}
\def\XINT_cuz #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_cuz_e \R
\xint_gob_til_eightzeroes #1#2#3#4#5#6#7#8\XINT_cuz_z 00000000%
\XINT_cuz_done #1#2#3#4#5#6#7#8#9%
}%
\def\XINT_cuz_z 00000000\XINT_cuz_done 00000000{\XINT_cuz }%
\edef\XINT_cuz_done #1#2#3#4#5#6#7#8#9\R
{\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8\relax #9}%
\edef\XINT_cuz_e\R #1\XINT_cuz_done #2\R
{\noexpand\expandafter\space\noexpand\the\numexpr #2\relax }%
% \end{macrocode}
% \lverb|This removes eight by eight leading zeroes from a sequence of 8N digits
% ended by \R. Thus, we still have 8N digits on output.|
% \begin{macrocode}
\def\XINT_cuz_byviii #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_cuz_byviii_e \R
\xint_gob_til_eightzeroes #1#2#3#4#5#6#7#8\XINT_cuz_byviii_z 00000000%
\XINT_cuz_byviii_done #1#2#3#4#5#6#7#8#9%
}%
\def\XINT_cuz_byviii_z 00000000\XINT_cuz_byviii_done 00000000{\XINT_cuz_byviii}%
\def\XINT_cuz_byviii_done #1\R { #1}%
\def\XINT_cuz_byviii_e\R #1\XINT_cuz_byviii_done #2\R{ #2}%
% \end{macrocode}
% \subsection{Blocks of eight digits}
% \lverb|Lingua of release 1.2.
%
% \romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W$newline
% produces a string of k 0's such that k+length(#1) is smallest bigger multiple
% of eight.|
% \begin{macrocode}
\def\XINT_zeroes_forviii #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_R #8\XINT_zeroes_forviii_end\R\XINT_zeroes_forviii
}%
\edef\XINT_zeroes_forviii_end\R\XINT_zeroes_forviii #1#2#3#4#5#6#7#8#9\W
{%
\noexpand\expandafter\space\noexpand\xint_gob_til_one #2#3#4#5#6#7#8%
}%
% \end{macrocode}
% \lverb|This is used as$bgroup$obeyspaces$obeylines
% \the\numexpr1\XINT_rsepbyviii <8Ndigits>$%
% \XINT_rsepbyviii_end_A 2345678$%
% \XINT_rsepbyviii_end_B 2345678\relax UV$egroup
%
% $noindent
% and will produce 1<8digits>!1<8digits>.1<8digits>!... where the original
% digits are organized by eight, and the order inside successive pairs of
% blocks separated by ! has been reversed. The output ends with a final 1U. or
% 1V. The former happens when we had an even number of eight blocks, the
% latter an odd number: 1<8d>!1<8d>.1U. or 1<8d>!1<8d>.1<8d>.1V.|
% \begin{macrocode}
\def\XINT_rsepbyviii #1#2#3#4#5#6#7#8%
{%
\XINT_rsepbyviii_b {#1#2#3#4#5#6#7#8}%
}%
\def\XINT_rsepbyviii_b #1#2#3#4#5#6#7#8#9%
{%
#2#3#4#5#6#7#8#9\expandafter!\the\numexpr
1#1\expandafter.\the\numexpr 1\XINT_rsepbyviii
}%
\def\XINT_rsepbyviii_end_B #1\relax #2#3{#2.}%
\def\XINT_rsepbyviii_end_A #11#2\expandafter #3\relax #4#5{#2.1#5.}%
% \end{macrocode}
% \lverb|This is used typically as$bgroup$obeyspaces$obeylines
% \romannumeral0\expandafter\XINT_sepandrev <8Ndigits>$%
% \XINT_rsepbyviii_end_A 2345678$%
% \XINT_rsepbyviii_end_B 2345678\relax UV\R.\R.\R.\R.\R.\R.\R.\R.\W$egroup
%
% $noindent
% and will produce 1<8digits>!1<8digits>!1<8digits>!... where the blocks have
% been globally reversed. The UV here are only place holders to share same
% syntax as \XINT_sepandrev_andcount, they are gobbled (#2 in
% \XINT_sepandrev_done).|
% \begin{macrocode}
\def\XINT_sepandrev
{%
\expandafter\XINT_sepandrev_a\the\numexpr 1\XINT_rsepbyviii
}%
\def\XINT_sepandrev_a {\XINT_sepandrev_b {}}%
\def\XINT_sepandrev_b #1#2.#3.#4.#5.#6.#7.#8.#9.%
{%
\xint_gob_til_R #9\XINT_sepandrev_end\R
\XINT_sepandrev_b {#9!#8!#7!#6!#5!#4!#3!#2!#1}%
}%
\def\XINT_sepandrev_end\R\XINT_sepandrev_b #1#2\W {\XINT_sepandrev_done #1}%
\def\XINT_sepandrev_done #11#2!{ }%
% \end{macrocode}
% \lverb|This is used typically as$bgroup$obeyspaces$obeylines
% \romannumeral0\expandafter\XINT_sepandrev_andcount
% \the\numexpr1\XINT_rsepbyviii <8Ndigits>$%
% \XINT_rsepbyviii_end_A 2345678$%
% \XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
% \R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
% \R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W$egroup
%
% $noindent
% and will produce <length>.1<8digits>!1<8digits>!1<8digits>!... where the
% blocks have been globally reversed and <length> is the number of blocks.|
% \begin{macrocode}
\def\XINT_sepandrev_andcount
{%
\expandafter\XINT_sepandrev_andcount_a\the\numexpr 1\XINT_rsepbyviii
}%
\def\XINT_sepandrev_andcount_a {\XINT_sepandrev_andcount_b 0.{}}%
\def\XINT_sepandrev_andcount_b #1.#2#3.#4.#5.#6.#7.#8.#9.%
{%
\xint_gob_til_R #9\XINT_sepandrev_andcount_end\R
\expandafter\XINT_sepandrev_andcount_b \the\numexpr #1+\xint_c_xiv.%
{#9!#8!#7!#6!#5!#4!#3!#2}%
}%
\def\XINT_sepandrev_andcount_end\R
\expandafter\XINT_sepandrev_andcount_b\the\numexpr #1+\xint_c_xiv.#2#3#4\W
{\expandafter\XINT_sepandrev_andcount_done\the\numexpr \xint_c_ii*#3+#1.#2}%
\edef\XINT_sepandrev_andcount_done #1.#21#3!%
{\noexpand\expandafter\space\noexpand\the\numexpr #1-#3.}%
% \end{macrocode}
% \lverb|Used as \romannumeral0\XINT_unrevbyviii 1<8d>!....1<8d>! terminated
% by$newline 1\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W.
%
% The \romannumeral in unrevbyviii_a is for special effects (expand some token
% which was put as 1<token>! at the end of the original blocks). Used by
% subtraction during \XINT_sub_out, in particular.|
% \begin{macrocode}
\def\XINT_unrevbyviii #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_unrevbyviii_a\R
\XINT_unrevbyviii {#9#8#7#6#5#4#3#2#1}%
}%
\edef\XINT_unrevbyviii_a\R\XINT_unrevbyviii #1#2\W
{\noexpand\expandafter\space
\noexpand\romannumeral`&&@\noexpand\xint_gob_til_Z #1}%
% \end{macrocode}
% \lverb|Can work with shorter ending pattern: 1\Z!1\R!1\R!1\R!1\R!1\R!1\R!\W
% but the longer one of unrevbyviii is ok here too. Used currently (1.2) only
% by addition, now (1.2c) with long ending pattern. Does the final clean up of
% leading zeroes contrarily to general \XINT_unrevbyviii.|
% \begin{macrocode}
\def\XINT_smallunrevbyviii 1#1!1#2!1#3!1#4!1#5!1#6!1#7!1#8!#9\W%
{%
\expandafter\XINT_cuz_small\xint_gob_til_Z #8#7#6#5#4#3#2#1%
}%
% \end{macrocode}
% \subsection{Blocks of eight, for needs of 1.2 \csh{xintiiDivision}.}
% \lverb|This is used as$bgroup$obeyspaces$obeylines
% \the\numexpr\XINT_sepbyviii_andcount <8Ndigits>$%
% \XINT_sepbyviii_end 2345678\relax
% \xint_c_vii!\xint_c_vi!\xint_c_v!\xint_c_iv!%
% \xint_c_iii!\xint_c_ii!\xint_c_i!\xint_c_\W $egroup
%
% $noindent
% It will produce 1<8d>!1<8d>!....1<8d>!1.<count of blocks>. Used by
% \XINT_div_prepare_g for \XINT_div_prepare_h.|
% \begin{macrocode}
\def\XINT_sepbyviii_andcount
{%
\expandafter\XINT_sepbyviii_andcount_a\the\numexpr\XINT_sepbyviii
}%
\def\XINT_sepbyviii #1#2#3#4#5#6#7#8%
{%
1#1#2#3#4#5#6#7#8\expandafter!\the\numexpr\XINT_sepbyviii
}%
\def\XINT_sepbyviii_end #1\relax {\relax\XINT_sepbyviii_andcount_end!}%
\def\XINT_sepbyviii_andcount_a {\XINT_sepbyviii_andcount_b \xint_c_.}%
\def\XINT_sepbyviii_andcount_b #1.#2!#3!#4!#5!#6!#7!#8!#9!%
{%
#2\expandafter!\the\numexpr#3\expandafter!\the\numexpr#4\expandafter
!\the\numexpr#5\expandafter!\the\numexpr#6\expandafter!\the\numexpr
#7\expandafter!\the\numexpr#8\expandafter!\the\numexpr#9\expandafter!\the\numexpr
\expandafter\XINT_sepbyviii_andcount_b\the\numexpr #1+\xint_c_viii.%
}%
\def\XINT_sepbyviii_andcount_end #1\XINT_sepbyviii_andcount_b\the\numexpr
#2+\xint_c_viii.#3#4\W {\expandafter.\the\numexpr #2+#3.}%
% \end{macrocode}
% \subsection{Blocks of eight, for needs of 1.2 \csh{xintiiDivision}.}
% \lverb|This is used as$newline
% \romannumeral0\XINT_rev_nounsep {}<blocks 1<8d>!>\R!\R!\R!\R!\R!\R!\R!\R!\W
%
% It reverses the blocks, keeping the 1's and ! separators. Used multiple
% times in division algorithm. The inserted {} here is *not* optional.
% Attention does not make disappear a 1!.|
% \begin{macrocode}
\def\XINT_rev_nounsep #1#2!#3!#4!#5!#6!#7!#8!#9!%
{%
\xint_gob_til_R #9\XINT_rev_nounsep_end\R
\XINT_rev_nounsep {#9!#8!#7!#6!#5!#4!#3!#2!#1}%
}%
\def\XINT_rev_nounsep_end\R\XINT_rev_nounsep #1#2\W {\XINT_rev_nounsep_done #1}%
\def\XINT_rev_nounsep_done #11{ 1}%
% \end{macrocode}
% \lverb|This is used as$newline
% \the\numexpr\XINT_sepbyviii_Z <8Ndigits>\XINT_sepbyviii_Z_end 2345678\relax
%
% It produces 1<8d>!...1<8d>!1\Z!|
% \begin{macrocode}
\def\XINT_sepbyviii_Z #1#2#3#4#5#6#7#8%
{%
1#1#2#3#4#5#6#7#8\expandafter!\the\numexpr\XINT_sepbyviii_Z
}%
\def\XINT_sepbyviii_Z_end #1\relax {\relax\Z!}%
% \end{macrocode}
% \lverb|This is used as$newline
% \romannumeral0\XINT_unsep_cuzsmall {}<blocks of 1<8d>!>1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
%
% En fait le {} est optionnel, s'il est absent le premier #1 sera vide, tout
% simplement. It removes the 1's and !'s, and removes the leading zeroes *of
% the first block*. This could have been done with \numexpr and a \cleanup but
% would have restricted due to maximal expansion depth. Probably there where
% already O(N^2) macros, thus I decided that this one would be too.|
% \begin{macrocode}
\def\XINT_unsep_cuzsmall #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_unsep_cuzsmall_end\R
\XINT_unsep_cuzsmall {#1#2#3#4#5#6#7#8#9}%
}%
\def\XINT_unsep_cuzsmall_end\R
\XINT_unsep_cuzsmall #1{\XINT_unsep_cuzsmall_done #1}%
\def\XINT_unsep_cuzsmall_done #1\R #2\W{\XINT_cuz_small #1}%
\def\XINT_unsep_delim {1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W}%
% \end{macrocode}
% \lverb|This is used by division to remove separators from the produced
% quotient. The quotient is produced in the correct order. The routine will
% also remove leading zeroes. An extra intial block of 8 zeroes is possible
% and thus if present must be removed. Then the next eight digits must be
% cleaned of leading zeroes.|
% \begin{macrocode}
\def\XINT_div_unsepQ #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_div_unsepQ_end\R
\XINT_div_unsepQ {#1#2#3#4#5#6#7#8#9}%
}%
\def\XINT_div_unsepQ_end\R\XINT_div_unsepQ #1{\XINT_div_unsepQ_x #1}%
\def\XINT_div_unsepQ_x #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_div_unsepQ_e \R
\xint_gob_til_eightzeroes #1#2#3#4#5#6#7#8\XINT_div_unsepQ_y 00000000%
\expandafter\XINT_div_unsepQ_done \the\numexpr #1#2#3#4#5#6#7#8.#9%
}%
\def\XINT_div_unsepQ_e\R\xint_gob_til_eightzeroes #1\XINT_div_unsepQ_y #2\W
{\the\numexpr #1\relax \Z}%
\def\XINT_div_unsepQ_y #1.#2\R #3\W{\XINT_cuz_small #2\Z}%
\def\XINT_div_unsepQ_done #1.#2\R #3\W { #1#2\Z}%
% \end{macrocode}
% \lverb|This is used by division to remove separators from the produced
% remainder. The remainder is here in correct order. It must be cleaned of
% leading zeroes, possibly all the way. Terminator was
% 1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W|
% \begin{macrocode}
\def\XINT_div_unsepR #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_div_unsepR_end\R
\XINT_div_unsepR {#1#2#3#4#5#6#7#8#9}%
}%
\def\XINT_div_unsepR_end\R\XINT_div_unsepR #1{\XINT_div_unsepR_done #1}%
\def\XINT_div_unsepR_done #1\R #2\W {\XINT_cuz #1\R}%
% \end{macrocode}
% \subsection{\csh{xintReverseDigits}}
% \lverb|1.2. Needed now by \xintLDg.|
% \begin{macrocode}
\def\XINT_microrevsep #1#2#3#4#5#6#7#8%
{%
1#8#7#6#5#4#3#2#1\expandafter!\the\numexpr\XINT_microrevsep
}%
\def\XINT_microrevsep_end #1\W #2\expandafter #3\Z{#2!}%
\def\xintReverseDigits {\romannumeral0\xintreversedigits }%
\def\xintreversedigits #1{\expandafter\XINT_reversedigits\romannumeral`&&@#1\Z}%
\def\XINT_reversedigits #1%
{%
\xint_UDsignfork
#1{\expandafter-\romannumeral0\XINT_reversedigits_a}%
-{\XINT_reversedigits_a #1}%
\krof
}%
\def\XINT_reversedigits_a #1\Z
{%
\expandafter\XINT_revdigits_a\the\numexpr\expandafter\XINT_microrevsep
\romannumeral`&&@#1{\XINT_microrevsep_end\W}\XINT_microrevsep_end
\XINT_microrevsep_end\XINT_microrevsep_end
\XINT_microrevsep_end\XINT_microrevsep_end
\XINT_microrevsep_end\XINT_microrevsep_end\Z
1\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_revdigits_a {\XINT_revdigits_b {}}%
\def\XINT_revdigits_b #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_revdigits_end\R
\XINT_revdigits_b {#9#8#7#6#5#4#3#2#1}%
}%
\edef\XINT_revdigits_end\R\XINT_revdigits_b #1#2\W
{\noexpand\expandafter\space\noexpand\xint_gob_til_Z #1}%
% \end{macrocode}
% \subsection{\csh{xintSgn}, \csh{xintiiSgn}, \csh{XINT_Sgn}, \csh{XINT_cntSgn}}
% \lverb|&
% xintfrac.sty will overwrite \xintsgn with use of \xintraw rather than
% \xintnum, naturally.
%|
% \begin{macrocode}
\def\xintiiSgn {\romannumeral0\xintiisgn }%
\def\xintiisgn #1%
{%
\expandafter\XINT_sgn \romannumeral`&&@#1\Z%
}%
\def\xintSgn {\romannumeral0\xintsgn }%
\def\xintsgn #1%
{%
\expandafter\XINT_sgn \romannumeral0\xintnum{#1}\Z%
}%
\def\XINT_sgn #1#2\Z
{%
\xint_UDzerominusfork
#1-{ 0}%
0#1{-1}%
0-{ 1}%
\krof
}%
\def\XINT_Sgn #1#2\Z
{%
\xint_UDzerominusfork
#1-{0}%
0#1{-1}%
0-{1}%
\krof
}%
\def\XINT_cntSgn #1#2\Z
{%
\xint_UDzerominusfork
#1-\xint_c_
0#1\xint_c_mone
0-\xint_c_i
\krof
}%
% \end{macrocode}
% \subsection{\csh{xintiOpp}, \csh{xintiiOpp}}
% \begin{macrocode}
\def\xintiiOpp {\romannumeral0\xintiiopp }%
\def\xintiiopp #1%
{%
\expandafter\XINT_opp \romannumeral`&&@#1%
}%
\def\xintiOpp {\romannumeral0\xintiopp }%
\def\xintiopp #1%
{%
\expandafter\XINT_opp \romannumeral0\xintnum{#1}%
}%
\def\XINT_Opp #1{\romannumeral0\XINT_opp #1}%
\def\XINT_opp #1%
{%
\xint_UDzerominusfork
#1-{ 0}% zero
0#1{ }% negative
0-{ -#1}% positive
\krof
}%
% \end{macrocode}
% \subsection{\csh{xintiAbs}, \csh{xintiiAbs}}
% \begin{macrocode}
\def\xintiiAbs {\romannumeral0\xintiiabs }%
\def\xintiiabs #1%
{%
\expandafter\XINT_abs \romannumeral`&&@#1%
}%
\def\xintiAbs {\romannumeral0\xintiabs }%
\def\xintiabs #1%
{%
\expandafter\XINT_abs \romannumeral0\xintnum{#1}%
}%
\def\XINT_Abs #1{\romannumeral0\XINT_abs #1}%
\def\XINT_abs #1%
{%
\xint_UDsignfork
#1{ }%
-{ #1}%
\krof
}%
% \end{macrocode}
% \subsection{\csh{xintFDg}, \csh{xintiiFDg}}
% \begin{macrocode}
\def\xintiiFDg {\romannumeral0\xintiifdg }%
\def\xintiifdg #1%
{%
\expandafter\XINT_fdg \romannumeral`&&@#1\W\Z
}%
\def\xintFDg {\romannumeral0\xintfdg }%
\def\xintfdg #1%
{%
\expandafter\XINT_fdg \romannumeral0\xintnum{#1}\W\Z
}%
\def\XINT_FDg #1{\romannumeral0\XINT_fdg #1\W\Z }%
\def\XINT_fdg #1#2#3\Z
{%
\xint_UDzerominusfork
#1-{ 0}% zero
0#1{ #2}% negative
0-{ #1}% positive
\krof
}%
% \end{macrocode}
% \subsection{\csh{xintLDg}, \csh{xintiiLDg}}
% \begin{macrocode}
\def\xintLDg {\romannumeral0\xintldg }%
\def\xintldg #1{\xintiildg {\xintNum{#1}}}%
\def\xintiiLDg {\romannumeral0\xintiildg }%
\def\xintiildg #1%
{%
\expandafter\XINT_ldg_done\romannumeral0%
\expandafter\XINT_revdigits_a\the\numexpr\expandafter\XINT_microrevsep
\romannumeral0\expandafter\XINT_abs
\romannumeral`&&@#1{\XINT_microrevsep_end\W}\XINT_microrevsep_end
\XINT_microrevsep_end\XINT_microrevsep_end
\XINT_microrevsep_end\XINT_microrevsep_end
\XINT_microrevsep_end\XINT_microrevsep_end\Z
1\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
\Z
}%
\def\XINT_ldg_done #1#2\Z { #1}%
% \end{macrocode}
% \subsection{\csh{xintDouble}}
% \begin{macrocode}
\def\xintDouble {\romannumeral0\xintdouble }%
\def\xintdouble #1%
{%
\expandafter\XINT_dbl\romannumeral`&&@#1\Z
}%
\def\XINT_dbl #1%
{%
\xint_UDzerominusfork
#1-\XINT_dbl_zero
0#1\XINT_dbl_neg
0-{\XINT_dbl_pos #1}%
\krof
}%
\def\XINT_dbl_zero #1\Z { 0}%
\def\XINT_dbl_neg
{\expandafter-\romannumeral0\XINT_dbl_pos }%
\def\XINT_dbl_pos #1\Z
{%
\expandafter\XINT_dbl_pos_aa
\romannumeral0\expandafter\XINT_sepandrev
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax XX%
\R.\R.\R.\R.\R.\R.\R.\R.\W 1\Z!%
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_dbl_pos_aa
{%
\expandafter\XINT_mul_out\the\numexpr\XINT_verysmallmul 0.2!%
}%
% \end{macrocode}
% \subsection{\csh{xintHalf}}
% \begin{macrocode}
\def\xintHalf {\romannumeral0\xinthalf }%
\def\xinthalf #1%
{%
\expandafter\XINT_half\romannumeral`&&@#1\Z
}%
\def\XINT_half #1%
{%
\xint_UDzerominusfork
#1-\XINT_half_zero
0#1\XINT_half_neg
0-{\XINT_half_pos #1}%
\krof
}%
\def\XINT_half_zero #1\Z { 0}%
\def\XINT_half_neg {\expandafter\XINT_opp\romannumeral0\XINT_half_pos }%
\def\XINT_half_pos #1\Z
{%
\expandafter\XINT_half_pos_a
\romannumeral0\expandafter\XINT_sepandrev
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax XX%
\R.\R.\R.\R.\R.\R.\R.\R.\W
1\Z!%
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_half_pos_a
{\expandafter\XINT_half_pos_b\the\numexpr\XINT_verysmallmul 0.5!}%
\def\XINT_half_pos_b 1#1#2#3#4#5#6#7#8!1#9%
{%
\xint_gob_til_Z #9\XINT_half_small \Z
\XINT_mul_out 1#1#2#3#4#5#6#7!1#9%
}%
\edef\XINT_half_small \Z\XINT_mul_out 1#1!#2\W
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1\relax
}%
% \end{macrocode}
% \subsection{\csh{xintDec}}
% \begin{macrocode}
\def\xintDec {\romannumeral0\xintdec }%
\def\xintdec #1%
{%
\expandafter\XINT_dec\romannumeral`&&@#1\Z
}%
\def\XINT_dec #1%
{%
\xint_UDzerominusfork
#1-\XINT_dec_zero
0#1\XINT_dec_neg
0-{\XINT_dec_pos #1}%
\krof
}%
\def\XINT_dec_zero #1\Z {-1}%
\def\XINT_dec_neg
{\expandafter-\romannumeral0\XINT_inc_pos }%
\def\XINT_dec_pos #1\Z
{%
\expandafter\XINT_dec_pos_aa
\romannumeral0\expandafter\XINT_sepandrev
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax XX%
\R.\R.\R.\R.\R.\R.\R.\R.\W
\Z!\Z!\Z!\Z!\W
}%
\def\XINT_dec_pos_aa {\XINT_sub_aa 100000001!\Z!\Z!\Z!\Z!\W }%
% \end{macrocode}
% \subsection{\csh{xintInc}}
% \begin{macrocode}
\def\xintInc {\romannumeral0\xintinc }%
\def\xintinc #1%
{%
\expandafter\XINT_inc\romannumeral`&&@#1\Z
}%
\def\XINT_inc #1%
{%
\xint_UDzerominusfork
#1-\XINT_inc_zero
0#1\XINT_inc_neg
0-{\XINT_inc_pos #1}%
\krof
}%
\def\XINT_inc_zero #1\Z { 1}%
\def\XINT_inc_neg {\expandafter\XINT_opp\romannumeral0\XINT_dec_pos }%
\def\XINT_inc_pos #1\Z
{%
\expandafter\XINT_inc_pos_aa
\romannumeral0\expandafter\XINT_sepandrev
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax XX%
\R.\R.\R.\R.\R.\R.\R.\R.\W
1\Z!1\Z!1\Z!1\Z!\W
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_inc_pos_aa {\XINT_add_aa 100000001!1\Z!1\Z!1\Z!1\Z!\W }%
% \end{macrocode}
% \subsection{Core arithmetic}
% \lverb|The four operations have been rewritten entirely for release 1.2.
% The new routines works with separated blocks of eight digits. They all measure
% first the lengths of the arguments, even addition and subtraction (this was
% not the case with xintcore.sty 1.1 or earlier.)
%
% The technique of chaining \the\numexpr induces a limitation on the
% maximal size depending on the size of the input save stack and the maximum
% expansion depth. For the current (TL2015) settings (5000, resp. 10000), the
% induced limit for addition of numbers is at 19968 and for multiplication
% it is observed to be 19959 (valid as of 2015/10/07).
%
% Side remark: I tested that \the\numexpr was more efficient than \number. But
% it reduced the allowable numbers for addition from 19976 digits to 19968
% digits.|
%
% \subsection{\csbh{xintiAdd}, \csbh{xintiiAdd}}
% \begin{macrocode}
\def\xintiAdd {\romannumeral0\xintiadd }%
\def\xintiadd #1{\expandafter\XINT_iadd\romannumeral0\xintnum{#1}\Z }%
\def\xintiiAdd {\romannumeral0\xintiiadd }%
\def\xintiiadd #1{\expandafter\XINT_iiadd\romannumeral`&&@#1\Z }%
\def\XINT_iiadd #1#2\Z #3%
{%
\expandafter\XINT_add_nfork\expandafter #1\romannumeral`&&@#3\Z #2\Z
}%
\def\XINT_iadd #1#2\Z #3%
{%
\expandafter\XINT_add_nfork\expandafter #1\romannumeral0\xintnum{#3}\Z #2\Z
}%
\def\XINT_add_fork #1#2\Z #3\Z {\XINT_add_nfork #1#3\Z #2\Z}%
\def\XINT_add_nfork #1#2%
{%
\xint_UDzerofork
#1\XINT_add_firstiszero
#2\XINT_add_secondiszero
0{}%
\krof
\xint_UDsignsfork
#1#2\XINT_add_minusminus
#1-\XINT_add_minusplus
#2-\XINT_add_plusminus
--\XINT_add_plusplus
\krof #1#2%
}%
\def\XINT_add_firstiszero #1\krof 0#2#3\Z #4\Z { #2#3}%
\def\XINT_add_secondiszero #1\krof #20#3\Z #4\Z { #2#4}%
\def\XINT_add_minusminus #1#2%
{\expandafter-\romannumeral0\XINT_add_pp_a {}{}}%
\def\XINT_add_minusplus #1#2{\XINT_sub_mm_a {}#2}%
\def\XINT_add_plusminus #1#2%
{\expandafter\XINT_opp\romannumeral0\XINT_sub_mm_a #1{}}%
\def\XINT_add_pp_a #1#2#3\Z
{%
\expandafter\XINT_add_pp_b
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W
#2#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\X #1%
}%
\let\XINT_add_plusplus \XINT_add_pp_a
\def\XINT_add_pp_b #1.#2\X #3\Z
{%
\expandafter\XINT_add_checklengths
\the\numexpr #1\expandafter.%
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W
#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
1\Z!1\Z!1\Z!1\Z!\W #21\Z!1\Z!1\Z!1\Z!\W
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
% \end{macrocode}
% \lverb|I keep #1.#2. to check if at most 6 + 6 base 10^8 digits which can be
% treated faster for final reverse. But is this overhead at all useful ? |
% \begin{macrocode}
\def\XINT_add_checklengths #1.#2.%
{%
\ifnum #2>#1
\expandafter\XINT_add_exchange
\else
\expandafter\XINT_add_A
\fi
#1.#2.%
}%
\def\XINT_add_exchange #1.#2.#3\W #4\W
{%
\XINT_add_A #2.#1.#4\W #3\W
}%
\def\XINT_add_A #1.#2.%
{%
\ifnum #1>\xint_c_vi
\expandafter\XINT_add_aa
\else \expandafter\XINT_add_aa_small
\fi
}%
\def\XINT_add_aa {\expandafter\XINT_add_out\the\numexpr\XINT_add_a \xint_c_ii}%
\def\XINT_add_out{\expandafter\XINT_cuz_small\romannumeral0\XINT_unrevbyviii {}}%
\def\XINT_add_aa_small
{\expandafter\XINT_smallunrevbyviii\the\numexpr\XINT_add_a \xint_c_ii}%
% \end{macrocode}
% \lverb|2 as first token of #1 stands for "no carry", 3 will mean a carry (we
% are adding 1<8digits> to 1<8digits>.) Version 1.2c has terminators of the
% shape 1\Z!, replacing the \Z! used in 1.2.
%
% Call: \the\numexpr\XINT_add_a 2#11\Z!1\Z!1\Z!1\Z!\W #21\Z!1\Z!1\Z!1\Z!\W
% where #1 and #2 are blocks of 1<8d>!, and #1 is at most as long as #2. This
% last requirement is a bit annoying (if one wants to do recursive algorithms
% but not have to check lengths), and I will probably remove it at some point.
%
% Output: blocks of 1<8d>! representing the addition, (least significant
% first), and a final 1\Z!. In recursive algotithm this 1\Z! terminator can
% thus conveniently be reused as part of input terminator (up to the length
% problem).|
% \begin{macrocode}
\def\XINT_add_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!%
{%
\XINT_add_b #1!#6!#2!#7!#3!#8!#4!#9!#5\W
}%
\def\XINT_add_b #11#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_add_bi \Z
\expandafter\XINT_add_c\the\numexpr#1+1#2#3+#4-\xint_c_ii.%
}%
\def\XINT_add_bi\Z\expandafter\XINT_add_c
\the\numexpr#1+#2+#3-\xint_c_ii.#4!#5!#6!#7!#8!#9!\W
{%
\XINT_add_k #1#3!#5!#7!#9!%
}%
\def\XINT_add_c #1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_add_d #1%
}%
\def\XINT_add_d #11#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_add_di \Z
\expandafter\XINT_add_e\the\numexpr#1+1#2#3+#4-\xint_c_ii.%
}%
\def\XINT_add_di\Z\expandafter\XINT_add_e
\the\numexpr#1+#2+#3-\xint_c_ii.#4!#5!#6!#7!#8\W
{%
\XINT_add_k #1#3!#5!#7!%
}%
\def\XINT_add_e #1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_add_f #1%
}%
\def\XINT_add_f #11#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_add_fi \Z
\expandafter\XINT_add_g\the\numexpr#1+1#2#3+#4-\xint_c_ii.%
}%
\def\XINT_add_fi\Z\expandafter\XINT_add_g
\the\numexpr#1+#2+#3-\xint_c_ii.#4!#5!#6\W
{%
\XINT_add_k #1#3!#5!%
}%
\def\XINT_add_g #1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_add_h #1%
}%
\def\XINT_add_h #11#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_add_hi \Z
\expandafter\XINT_add_i\the\numexpr#1+1#2#3+#4-\xint_c_ii.%
}%
\def\XINT_add_hi\Z
\expandafter\XINT_add_i\the\numexpr#1+#2+#3-\xint_c_ii.#4\W
{%
\XINT_add_k #1#3!%
}%
\def\XINT_add_i #1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_add_a #1%
}%
\def\XINT_add_k #1{\if #12\expandafter\XINT_add_ke\else\expandafter\XINT_add_l \fi}%
\def\XINT_add_ke #11\Z #2\W {\XINT_add_kf #11\Z!}%
\def\XINT_add_kf 1{1\relax }%
\def\XINT_add_l 1#1#2{\xint_gob_til_Z #1\XINT_add_lf \Z \XINT_add_m 1#1#2}%
\def\XINT_add_lf #1\W {1\relax 00000001!1\Z!}%
\def\XINT_add_m #1!{\expandafter\XINT_add_n\the\numexpr\xint_c_i+#1.}%
\def\XINT_add_n #1#2.{1#2\expandafter!\the\numexpr\XINT_add_o #1}%
% \end{macrocode}
% \lverb|Here 2 stands for "carry", and 1 for "no carry" (we have been adding
% 1 to 1<8digits>.)|
% \begin{macrocode}
\def\XINT_add_o #1{\if #12\expandafter\XINT_add_l\else\expandafter\XINT_add_ke \fi}%
% \end{macrocode}
% \subsection{\csh{xintiSub}, \csh{xintiiSub}}
% \lverb|Entirely rewritten for 1.2.|
% \begin{macrocode}
\def\xintiiSub {\romannumeral0\xintiisub }%
\def\xintiisub #1{\expandafter\XINT_iisub\romannumeral`&&@#1\Z }%
\def\XINT_iisub #1#2\Z #3%
{%
\expandafter\XINT_sub_nfork\expandafter #1\romannumeral`&&@#3\Z #2\Z
}%
\def\xintiSub {\romannumeral0\xintisub }%
\def\xintisub #1{\expandafter\XINT_isub\romannumeral0\xintnum{#1}\Z }%
\def\XINT_isub #1#2\Z #3%
{%
\expandafter\XINT_sub_nfork\expandafter #1\romannumeral0\xintnum{#3}\Z #2\Z
}%
\def\XINT_sub_nfork #1#2%
{%
\xint_UDzerofork
#1\XINT_sub_firstiszero
#2\XINT_sub_secondiszero
0{}%
\krof
\xint_UDsignsfork
#1#2\XINT_sub_minusminus
#1-\XINT_sub_minusplus
#2-\XINT_sub_plusminus
--\XINT_sub_plusplus
\krof #1#2%
}%
\def\XINT_sub_firstiszero #1\krof 0#2#3\Z #4\Z {\XINT_opp #2#3}%
\def\XINT_sub_secondiszero #1\krof #20#3\Z #4\Z { #2#4}%
\def\XINT_sub_plusminus #1#2{\XINT_add_pp_a #1{}}%
\def\XINT_sub_plusplus #1#2%
{\expandafter\XINT_opp\romannumeral0\XINT_sub_mm_a #1#2}%
\def\XINT_sub_minusplus #1#2%
{\expandafter-\romannumeral0\XINT_add_pp_a {}#2}%
\def\XINT_sub_minusminus #1#2{\XINT_sub_mm_a {}{}}%
\def\XINT_sub_mm_a #1#2#3\Z
{%
\expandafter\XINT_sub_mm_b
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W
#2#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\X #1%
}%
\def\XINT_sub_mm_b #1.#2\X #3\Z
{%
\expandafter\XINT_sub_checklengths
\the\numexpr #1\expandafter.%
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W
#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax \xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\Z!\Z!\Z!\Z!\W #2\Z!\Z!\Z!\Z!\W
}%
\def\XINT_sub_checklengths #1.#2.%
{%
\ifnum #2>#1
\expandafter\XINT_sub_exchange
\else
\expandafter\XINT_sub_aa
\fi
}%
\def\XINT_sub_exchange #1\W #2\W
{%
\expandafter\XINT_opp\romannumeral0\XINT_sub_aa #2\W #1\W
}%
\def\XINT_sub_aa {\expandafter\XINT_sub_out\the\numexpr\XINT_sub_a \xint_c_i }%
% \end{macrocode}
% \lverb|The {} after \XINT_unrevbyviii could be removed, but attention then
% at \XINT_sub_startrescue which must be modified (no need for #1).|
% \begin{macrocode}
\def\XINT_sub_out #1\Z #2#3\W
{%
\if-#2\expandafter\XINT_sub_startrescue\fi
\expandafter\XINT_cuz_small
\romannumeral0\XINT_unrevbyviii {}#11\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
% \end{macrocode}
% \lverb|1 as first token of #1 stands for "no carry", 0 will mean a carry.
%
% Call: \the\numexpr
% \XINT_sub_a 1#1\Z!\Z!\Z!\Z!\W #2\Z!\Z!\Z!\Z!\W where #1 and #2
% are blocks of 1<8d>!, and #1 *must* be at most as long as #2.
%
% The routine wants to compute #2-#1.
%
% Notice that currently the terminators on input differ from those for
% addition. Also, currently (1.2f) the routine can not be called without final
% reversal and clean up of the result.
%
% \numexpr governed expansion stops with various possibilities:
%
% 1. #1 was shorter (in number of 8 digits blocks) than #2.
%
% *1a There may be no carry in which case we end up with$\
% 1<8d>!...1<8d>!\Z!\Z!\Z!\Z!\W
%
% If there is a carry things are more complicated.
%
% *1b If the first hit block of #2 is > 1 no problem we are like in the
% no-carry case.
%
% *1c If it is exactly 1 then we will have leading zeros; but there may be
% also before that arbitrarily many produced zeros, all these leading zeros
% will have to be cleaned up. This is done via ending the expansion with the
% shape
%
% 1<8d>!...1<8d>!1\XINT_cuz_byviii!\Z 0\W\R
%
% *1d If the block value is zero, subtraction produces 99999999 and goes on.
% This is the only situation where the carry can propagate. This case can
% never produce extra blocks of leading zeros but may well end up with an ending
% zero block. In this subcase, the \numexpr is then made to stop with a 1!.
% This 1! will disappear during final reverse.
%
% 2a. #1 was of same length as #2, but <= #2. Then we end up expansion with$\
% 1<8d>!...1<8d>!1\XINT_cuz_byviii!\Z 0\W\R$\
% and the blocks will have to cleaned up of leading zeroes after reversal.
%
% 2b. #1 was of same length as #2, but > #2. Then we end up with blocks
% 1<8d>!...1<8d>! followed by -1\Z-\W
%
% Thus \XINT_sub_out examines the token after the first \Z, which may be ! or
% 0 or -. If ! or 0, \XINT_unrevbyviii will be executed (gobbling a possible
% final 1!), and followed in case 2a or 1c by \XINT_cuz_byviii (note the extra \R
% which terminates it), and then in both 1* and 2a by \XINT_cuz_small.
%
% If we were in 2b we proceed to \XINT_sub_startrescue which I will comment
% another day (the extra -1 at the end from -1\Z-\W will become a -1! and the
% - will serve in \XINT_sub_rescue_d as loop terminator).
%
% Currently (1.2f) we can not easily use these low level routines in a binary
% split approach due to the fact that first input must be at most as long as
% second but also because the final reversal is not in a common second stage,
% due to the separate treatment for case 2b.
%
% For the record: subtraction was correct (I think) in xint releases up to
% 1.2, but 1.2 had a broken treatment of the 1d case. For example \xintiiSub
% {10000000112345678}{12345679} produced 99999999. This got fixed in 1.2c, but
% that fix broke the 1c case :((, for example \xintiiSub
% {10000000000000000}{9999999999999997} was now returning 000000003. Alas.
%
% This was only realized later on 2016/02/29 (in fact it impacted
% \xintiiSqrt). Hopefully 1.2f got it right at last. |
% \begin{macrocode}
\def\XINT_sub_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!%
{%
\XINT_sub_b #1!#6!#2!#7!#3!#8!#4!#9!#5\W
}%
\def\XINT_sub_b #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_sub_bi \Z
\expandafter\XINT_sub_c\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_sub_c 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_sub_d #1%
}%
\def\XINT_sub_d #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_sub_di \Z
\expandafter\XINT_sub_e\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_sub_e 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_sub_f #1%
}%
\def\XINT_sub_f #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_sub_fi \Z
\expandafter\XINT_sub_g\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_sub_g 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_sub_h #1%
}%
\def\XINT_sub_h #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_sub_hi \Z
\expandafter\XINT_sub_i\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_sub_i 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_sub_a #1%
}%
\def\XINT_sub_bi\Z
\expandafter\XINT_sub_c\the\numexpr#1+1#2-#3.#4!#5!#6!#7!#8!#9!\W
{%
\XINT_sub_k #1#2!#5!#7!#9!%
}%
\def\XINT_sub_di\Z
\expandafter\XINT_sub_e\the\numexpr#1+1#2-#3.#4!#5!#6!#7!#8\W
{%
\XINT_sub_k #1#2!#5!#7!%
}%
\def\XINT_sub_fi\Z
\expandafter\XINT_sub_g\the\numexpr#1+1#2-#3.#4!#5!#6\W
{%
\XINT_sub_k #1#2!#5!%
}%
\def\XINT_sub_hi\Z
\expandafter\XINT_sub_i\the\numexpr#1+1#2-#3.#4\W
{%
\XINT_sub_k #1#2!%
}%
% \end{macrocode}
% \lverb|B terminated. Have we reached the end of A (necessarily at least as
% long as B) ? (we are computing A-B, digits of B come first).
%
% If not, then we are certain that even if there is carry it will not
% propagate beyond the end of A. But it may propagate far transforming chains
% of 00000000 into 99999999, and if it does go to the final block which is
% just 1<00000001>!, we will have those eight zeros to clean up. (but we have
% to be careful that if we encounter 1<00000001>! and this is not the final
% block, we should not make something silly either).
%
% There is the possibility that A has exactly one more <eight-digits> block
% than B and that this block is exactly 1. In that case there can be
% arbitrarily many leading zeros to clean up from A-B. This was done correctly
% up to 1.2b but got broken in 1.2c. Belatedly fixed in 1.2f.
%
% If we have simultaneously reached the end of A, then if B was smaller there
% might be arbitrarily many zeroes to clean up, if it was larger, we will have
% to rescue the whole thing.|
% \begin{macrocode}
\def\XINT_sub_k #1#2%
{%
\xint_gob_til_Z #2\XINT_sub_p\Z \XINT_sub_l #1#2%
}%
\def\XINT_sub_l #1{\xint_UDzerofork #1\XINT_sub_l_carry 0\XINT_sub_l_nocarry\krof}%
\def\XINT_sub_l_nocarry 1{1\relax }%
\def\XINT_sub_l_carry 1#1!{\ifcase #1
\expandafter \XINT_sub_l_zeroa\or\expandafter\XINT_sub_l_one\else
\expandafter \XINT_sub_l_done\fi 1#1!}%
\def\XINT_sub_l_done {-\xint_c_i+}%
\def\XINT_sub_l_one 1#1!#2%
{%
\xint_gob_til_Z #2\XINT_sub_l_oneone\Z 1\relax 00000000!#2%
}%
\def\XINT_sub_l_oneone #1\W {1\relax \XINT_cuz_byviii!\Z 0\W\R }%
\def\XINT_sub_l_zeroa 1#1!{199999999\expandafter!\the\numexpr \XINT_sub_l_zerob }%
\def\XINT_sub_l_zerob 1#1!{\ifcase #1
\expandafter \XINT_sub_l_zeroa\or\expandafter\XINT_sub_l_zone\else
\expandafter \XINT_sub_l_done\fi 1#1!}%
\def\XINT_sub_l_zone 1#1!#2%
{%
\xint_gob_til_Z #2\XINT_sub_l_zoneone\Z 1\relax 00000000!#2%
}%
\def\XINT_sub_l_zoneone\Z 1\relax 00000000{1}%
% \end{macrocode}
% \lverb|Here we are in the situation were the two inputs had the same length
% in base 10^8. If #1=0 we bitterly discover that first input was greater than
% second input despite having same length (in base 10^8). The \numexpr will
% expand beyond the -1 or 1. If #1=1 we had no carry but perhaps the result
% will have plenty of zeroes to clean-up. The result might even be simply zero.|
% \begin{macrocode}
\def\XINT_sub_p\Z\XINT_sub_l #1#2\W
{%
\xint_UDzerofork
#1{-1\relax\Z -\W}%
0{1\relax \XINT_cuz_byviii!\Z 0\W\R }%
\krof
}%
% \end{macrocode}
% \lverb|We arrive here if #2-#1 concluded #1>#2 (both of the same length in
% base 10^8). To be commented. Here also before the \XINT_sub_rescue_finish
% there will be an ending 1! which will disappear only due to
% \XINT_unrevbyviii. The final \R is for \XINT_cuz.|
% \begin{macrocode}
\def\XINT_sub_startrescue\expandafter\XINT_cuz_small
\romannumeral0\XINT_unrevbyviii #1#2\Z!#3\W
{%
\expandafter\XINT_sub_rescue_finish
\the\numexpr\XINT_sub_rescue_a #2!%
1\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W \R
}%
\def\XINT_sub_rescue_finish
{\expandafter-\romannumeral0\expandafter\XINT_cuz\romannumeral0\XINT_unrevbyviii {}}%
\def\XINT_sub_rescue_a #1!%
{%
\expandafter\XINT_sub_rescue_c\the\numexpr \xint_c_xii_e_viii-#1.%
}%
\def\XINT_sub_rescue_c 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_sub_rescue_d #1%
}%
\def\XINT_sub_rescue_d #1#2#3!%
{%
\xint_gob_til_minus #2\XINT_sub_rescue_z -%
\expandafter\XINT_sub_rescue_c\the\numexpr \xint_c_xii_e_viii_mone-#2#3+#1.%
}%
\def\XINT_sub_rescue_z #1.{1!}%
% \end{macrocode}
% \subsection{\csh{xintiMul}, \csh{xintiiMul}}
% \lverb|Completely rewritten for 1.2.|
% \begin{macrocode}
\def\xintiMul {\romannumeral0\xintimul }%
\def\xintimul #1%
{%
\expandafter\XINT_imul\romannumeral0\xintnum{#1}\Z
}%
\def\XINT_imul #1#2\Z #3%
{%
\expandafter\XINT_mul_nfork\expandafter #1\romannumeral0\xintnum{#3}\Z #2\Z
}%
\def\xintiiMul {\romannumeral0\xintiimul }%
\def\xintiimul #1%
{%
\expandafter\XINT_iimul\romannumeral`&&@#1\Z
}%
\def\XINT_iimul #1#2\Z #3%
{%
\expandafter\XINT_mul_nfork\expandafter #1\romannumeral`&&@#3\Z #2\Z
}%
% \end{macrocode}
% \lverb|I have changed the fork, and it complicates matters elsewhere.|
% \begin{macrocode}
\def\XINT_mul_fork #1#2\Z #3\Z{\XINT_mul_nfork #1#3\Z #2\Z}%
\def\XINT_mul_nfork #1#2%
{%
\xint_UDzerofork
#1\XINT_mul_zero
#2\XINT_mul_zero
0{}%
\krof
\xint_UDsignsfork
#1#2\XINT_mul_minusminus
#1-\XINT_mul_minusplus
#2-\XINT_mul_plusminus
--\XINT_mul_plusplus
\krof #1#2%
}%
\def\XINT_mul_zero #1\krof #2#3\Z #4\Z { 0}%
\def\XINT_mul_minusminus #1#2{\XINT_mul_plusplus {}{}}%
\def\XINT_mul_minusplus #1#2%
{\expandafter-\romannumeral0\XINT_mul_plusplus {}#2}%
\def\XINT_mul_plusminus #1#2%
{\expandafter-\romannumeral0\XINT_mul_plusplus #1{}}%
\def\XINT_mul_plusplus #1#2#3\Z
{%
\expandafter\XINT_mul_pre_b
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W
#2#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\W #1%
}%
\def\XINT_mul_pre_b #1.#2\W #3\Z
{%
\expandafter\XINT_mul_checklengths
\the\numexpr #1\expandafter.%
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W
#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
1\Z!\W #21\Z!%
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
% \end{macrocode}
% \lverb|Cooking recipe, 2015/10/05.|
% \begin{macrocode}
\def\XINT_mul_checklengths #1.#2.%
{%
\ifnum #2=\xint_c_i\expandafter\XINT_mul_smallbyfirst\fi
\ifnum #1=\xint_c_i\expandafter\XINT_mul_smallbysecond\fi
\ifnum #2<#1
\ifnum \numexpr (#2-\xint_c_i)*(#1-#2)<383
\XINT_mul_exchange
\fi
\else
\ifnum \numexpr (#1-\xint_c_i)*(#2-#1)>383
\XINT_mul_exchange
\fi
\fi
\XINT_mul_start
}%
\def\XINT_mul_smallbyfirst #1\XINT_mul_start 1#2!1\Z!\W
{%
\ifnum#2=\xint_c_i\expandafter\XINT_mul_oneisone\fi
\ifnum#2<\xint_c_xxii\expandafter\XINT_mul_verysmall\fi
\expandafter\XINT_mul_out\the\numexpr\XINT_smallmul 1#2!%
}%
\def\XINT_mul_smallbysecond #1\XINT_mul_start #2\W 1#3!1\Z!%
{%
\ifnum#3=\xint_c_i\expandafter\XINT_mul_oneisone\fi
\ifnum#3<\xint_c_xxii\expandafter\XINT_mul_verysmall\fi
\expandafter\XINT_mul_out\the\numexpr\XINT_smallmul 1#3!#2%
}%
\def\XINT_mul_oneisone #1!{\XINT_mul_out }%
\def\XINT_mul_verysmall\expandafter\XINT_mul_out
\the\numexpr\XINT_smallmul 1#1!%
{\expandafter\XINT_mul_out\the\numexpr\XINT_verysmallmul 0.#1!}%
\def\XINT_mul_exchange #1\XINT_mul_start #2\W #31\Z!%
{\fi\fi\XINT_mul_start #31\Z!\W #2}%
% \end{macrocode}
% \lverb|1.2c: earlier version of addition had sometimes a final 1!, but not
% in all cases. Version 1.2c of \XINT_add_a always has an ending 1\Z!, which
% is thus expected by \XINT_mul_loop.|
% \begin{macrocode}
\def\XINT_mul_start
{\expandafter\XINT_mul_out\the\numexpr\XINT_mul_loop 100000000!1\Z!\W}%
\def\XINT_mul_out
{\expandafter\XINT_cuz_small\romannumeral0\XINT_unrevbyviii {}}%
% \end{macrocode}
% \lverb|The 1.2 \XINT_mul_loop could *not* be called directly with a small
% multiplicand, due to problems caused in case the addition done in
% \XINT_mul_a produced only 1 block the second one being either empty or a 1!
% which had to be handled by \XINT_mul_loop and \XINT_mul_e. But
% \XINT_mul_loop was only called via \xintiiMul for arguments with at least 2
% digits in base 10^8, thus no problem. But this made it annoying for
% \xintiiPow and \xintiiSqr which had to check if the intended multiplier had
% only 1 digit in base 10^8. It also made it annoying to create recursive
% algorithms which did multiplications maintaining the result reverses, for
% iterative use of output as input.
%
% Finally on 2015/11/14 during 1.2c preparation I modified the addition to
% *always* have the ending 1\Z!.\numexpr expands even through spaces to find
% operators and even something like 1<space>\Z will try to expand the \Z. Thus
% we have to not forget that #2 in \XINT_mul_e might be \Z! (a #2=1\Z! in
% \XINT_mul_a hence \XINT_add_a is no problem). Again this can only happen if
% we use \XINT_mul_loop directly with a small first argument (in place of
% smallmul). Anyway, now the routine \XINT_mul_loop can handle a small #2,
% with no black magic with delimiters and checking if #1 empty, although it
% never happens when called via \xintiiMul.
%
% The delimiting patterns for addition was changed to use 1\Z! to fit what is
% used on output (by necessity).
%
% Call: \the\numexpr \XINT_mul_loop 100000000!1\Z!\W #11\Z!\W #21\Z!$newline
% where #1 and #2 are (globally reversed) blocks 1<8d>!. Its is generally more
% efficient to have #1 as the shorter one, but a better recipe is implemented
% in \XINT_mul_checklengths which as executed earlier. One may call
% \XINT_mul_loop directly (but multiplication by zero will produce many
% 100000000! blocks on output).
%
% Ends after having produced: 1<8d>!....1<8d>!1\Z!. The most significant
% digit block is the last one. It can not be 100000000! except if naturally
% the loop was called with a zero operand.
%
% Thus \XINT_mul_loop can be conveniently called directly in recursive
% routines, as the output terminator can serve as input terminator, we can
% arrange to not have to grab the whole thing again.|
% \begin{macrocode}
\def\XINT_mul_loop #1\W #2\W 1#3!%
{%
\xint_gob_til_Z #3\XINT_mul_e \Z
\expandafter\XINT_mul_a\the\numexpr \XINT_smallmul 1#3!#2\W
#1\W #2\W
}%
% \end{macrocode}
% \lverb|Each of #1 and #2 brings its 1\Z! for \XINT_add_a.|
% \begin{macrocode}
\def\XINT_mul_a #1\W #2\W
{%
\expandafter\XINT_mul_b\the\numexpr
\XINT_add_a \xint_c_ii #21\Z!1\Z!1\Z!\W #11\Z!1\Z!1\Z!\W\W
}%
\def\XINT_mul_b 1#1!{1#1\expandafter!\the\numexpr\XINT_mul_loop }%
\def\XINT_mul_e\Z #1\W 1#2\W #3\W {1\relax #2}%
% \end{macrocode}
% \lverb|1.2 small and mini multiplication in base 10^8 with carry. Used by
% the main multiplication routines. But division, float factorial, etc.. have
% their own variants as they need output with specific constraints.
%
% The minimulwc has 1<8digits carry>.<4 high digits>.<4 low digits!<8digits>.
%
% It produces a block 1<8d>! and then jump back into \XINT_smallmul_a with the
% new 8digits carry as argument. The \XINT_smallmul_a fetches a new 1<8d>!
% block to multiply, and calls back \XINT_minimul_wc having stored the
% multiplicand for re-use later. When the loop terminates, the final carry is
% checked for being nul, and in all cases the output is terminated by a 1\Z!
%
% Multiplication by zero will produce blocks of zeros.|
% \begin{macrocode}
\def\XINT_minimulwc_a 1#1.#2.#3!#4#5#6#7#8.%
{%
\expandafter\XINT_minimulwc_b
\the\numexpr \xint_c_x^ix+#1+#3*#8.#3*#4#5#6#7+#2*#8.#2*#4#5#6#7.%
}%
\def\XINT_minimulwc_b 1#1#2#3#4#5#6.#7.%
{%
\expandafter\XINT_minimulwc_c
\the\numexpr \xint_c_x^ix+#1#2#3#4#5+#7.#6.%
}%
\def\XINT_minimulwc_c 1#1#2#3#4#5#6.#7.#8.%
{%
1#6#7\expandafter!%
\the\numexpr\expandafter\XINT_smallmul_a
\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#8.%
}%
\def\XINT_smallmul 1#1#2#3#4#5!{\XINT_smallmul_a 100000000.#1#2#3#4.#5!}%
\def\XINT_smallmul_a #1.#2.#3!1#4!%
{%
\xint_gob_til_Z #4\XINT_smallmul_e\Z
\XINT_minimulwc_a #1.#2.#3!#4.#2.#3!%
}%
\def\XINT_smallmul_e\Z\XINT_minimulwc_a 1#1.#2\Z #3!%
{\xint_gob_til_eightzeroes #1\XINT_smallmul_f 000000001\relax #1!1\Z!}%
\def\XINT_smallmul_f 000000001\relax 00000000!1{1\relax}%
% \end{macrocode}
% \lverb|This is multiplication by 1 up to 21. Last time I checked it is never
% called with a wasteful multiplicand of 1. Here also always the output
% terminated by a 1\Z! and the last block of digits is not zero. I imagine
% multiplication by zero produces blocks of zeroes. Will check another day.|
% \begin{macrocode}
\def\XINT_verysmallmul #1.#2!1#3!%
{%
\xint_gob_til_Z #3\XINT_verysmallmul_e\Z
\expandafter\XINT_verysmallmul_a
\the\numexpr #2*#3+#1.#2!%
}%
\def\XINT_verysmallmul_e\Z\expandafter\XINT_verysmallmul_a\the\numexpr
#1+#2#3.#4!%
{\xint_gob_til_zero #2\XINT_verysmallmul_f 0\xint_c_x^viii+#2#3!1\Z!}%
\def\XINT_verysmallmul_f #1!1{1\relax}%
\def\XINT_verysmallmul_a #1#2.%
{%
\unless\ifnum #1#2<\xint_c_x^ix
\expandafter\XINT_verysmallmul_bi\else
\expandafter\XINT_verysmallmul_bj\fi
\the\numexpr \xint_c_x^ix+#1#2.%
}%
\def\XINT_verysmallmul_bj{\expandafter\XINT_verysmallmul_cj }%
\def\XINT_verysmallmul_cj 1#1#2.%
{1#2\expandafter!\the\numexpr\XINT_verysmallmul #1.}%
\def\XINT_verysmallmul_bi\the\numexpr\xint_c_x^ix+#1#2#3.%
{1#3\expandafter!\the\numexpr\XINT_verysmallmul #1#2.}%
% \end{macrocode}
% \lverb|Used by division and by squaring, not by multiplication itself.
%
% This routine does not loop, it only does one mini multiplication with input
% format <4 high digits>.<4 low digits>!<8 digits>!, and on output
% 1<8d>!1<8d>!, with least significant block first.|
% \begin{macrocode}
\def\XINT_minimul_a #1.#2!#3#4#5#6#7!%
{%
\expandafter\XINT_minimul_b
\the\numexpr \xint_c_x^viii+#2*#7.#2*#3#4#5#6+#1*#7.#1*#3#4#5#6.%
}%
\def\XINT_minimul_b 1#1#2#3#4#5.#6.%
{%
\expandafter\XINT_minimul_c
\the\numexpr \xint_c_x^ix+#1#2#3#4+#6.#5.%
}%
\def\XINT_minimul_c 1#1#2#3#4#5#6.#7.#8.%
{%
1#6#7\expandafter!\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#8!%
}%
% \end{macrocode}
% \subsection{\csh{xintiSqr}, \csh{xintiiSqr}}
% \lverb|Rewritten for 1.2.|
% \begin{macrocode}
\def\xintiiSqr {\romannumeral0\xintiisqr }%
\def\xintiisqr #1%
{%
\expandafter\XINT_sqr\romannumeral0\xintiiabs{#1}\Z
}%
\def\xintiSqr {\romannumeral0\xintisqr }%
\def\xintisqr #1%
{%
\expandafter\XINT_sqr\romannumeral0\xintiabs{#1}\Z
}%
\def\XINT_sqr #1\Z
{%
\expandafter\XINT_sqr_a
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\Z
}%
% \end{macrocode}
% \lverb|1.2c \XINT_mul_loop can now be called directly even with small
% arguments, thus the following check is not anymore a necessity.|
% \begin{macrocode}
\def\XINT_sqr_a #1.%
{%
\ifnum #1=\xint_c_i \expandafter\XINT_sqr_small
\else\expandafter\XINT_sqr_start\fi
}%
\def\XINT_sqr_small 1#1#2#3#4#5!\Z
{%
\ifnum #1#2#3#4#5<46341 \expandafter\XINT_sqr_verysmall\fi
\expandafter\XINT_sqr_small_out
\the\numexpr\XINT_minimul_a #1#2#3#4.#5!#1#2#3#4#5!%
}%
\edef\XINT_sqr_verysmall
\expandafter\XINT_sqr_small_out\the\numexpr\XINT_minimul_a #1!#2!%
{\noexpand\expandafter\space\noexpand\the\numexpr #2*#2\relax}%
\def\XINT_sqr_small_out 1#1!1#2!%
{%
\XINT_cuz #2#1\R
}%
% \end{macrocode}
% \lverb|An ending 1\Z! is produced on output for \XINT_mul_loop and gets
% incorporated to the delimiter needed by the \XINT_unrevbyviii done by
% \XINT_mul_out.|
% \begin{macrocode}
\def\XINT_sqr_start #1\Z
{%
\expandafter\XINT_mul_out
\the\numexpr\XINT_mul_loop 100000000!1\Z!\W #11\Z!\W #11\Z!%
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
% \end{macrocode}
% \subsection{\csh{xintiPow}, \csh{xintiiPow}}
% \lverb|&
% The exponent is not limited but with current default settings of tex memory,
% with xint 1.2, the maximal exponent for 2^N is N = 2^17 = 131072.
%
% 1.2f Modifies the initial steps: 1) in order to be able to let more easily
% \xintiPow use \xintNum on the exponent once xintfrac.sty is loaded; 2) also
% because I noticed it was not very well coded. And it did only a \numexpr on
% the exponent, contradicting the documentation related to the "i" convention
% in names.|
% \begin{macrocode}
\def\xintiiPow {\romannumeral0\xintiipow }%
\def\xintiipow #1#2%
{%
\expandafter\xint_pow\the\numexpr #2\expandafter.\romannumeral`&&@#1\Z%
}%
\def\xintiPow {\romannumeral0\xintipow }%
\def\xintipow #1#2%
{%
\expandafter\xint_pow\the\numexpr #2\expandafter.\romannumeral0\xintnum{#1}\Z%
}%
\def\xint_pow #1.#2%#3\Z
{%
\xint_UDzerominusfork
#2-\XINT_pow_AisZero
0#2\XINT_pow_Aneg
0-{\XINT_pow_Apos #2}%
\krof {#1}%
}%
\def\XINT_pow_AisZero #1#2\Z
{%
\ifcase\XINT_cntSgn #1\Z
\xint_afterfi { 1}%
\or
\xint_afterfi { 0}%
\else
\xint_afterfi {\xintError:DivisionByZero\space 0}%
\fi
}%
\def\XINT_pow_Aneg #1%
{%
\ifodd #1
\expandafter\XINT_opp\romannumeral0%
\fi
\XINT_pow_Apos {}{#1}%
}%
\def\XINT_pow_Apos #1#2{\XINT_pow_Apos_a {#2}#1}%
\def\XINT_pow_Apos_a #1#2#3%
{%
\xint_gob_til_Z #3\XINT_pow_Apos_short\Z
\XINT_pow_AatleastTwo {#1}#2#3%
}%
\def\XINT_pow_Apos_short\Z\XINT_pow_AatleastTwo #1#2\Z
{%
\ifcase #2
\xintError:thiscannothappen!
\or \expandafter\XINT_pow_AisOne
\else\expandafter\XINT_pow_AatleastTwo
\fi {#1}#2\Z
}%
\def\XINT_pow_AisOne #1\Z{ 1}%
\def\XINT_pow_AatleastTwo #1%
{%
\ifcase\XINT_cntSgn #1\Z
\expandafter\XINT_pow_BisZero
\or
\expandafter\XINT_pow_I_in
\else
\expandafter\XINT_pow_BisNegative
\fi
{#1}%
}%
\edef\XINT_pow_BisNegative #1\Z
{\noexpand\xintError:FractionRoundedToZero\space 0}%
\def\XINT_pow_BisZero #1\Z{ 1}%
% \end{macrocode}
% \lverb|B = #1 > 0, A = #2 > 1. Earlier code checked if size of B did not
% exceed a given limit (for example 131000).|
% \begin{macrocode}
\def\XINT_pow_I_in #1#2\Z
{%
\expandafter\XINT_pow_I_loop
\the\numexpr #1\expandafter.%
\romannumeral0\expandafter\XINT_sepandrev
\romannumeral0\XINT_zeroes_forviii #2\R\R\R\R\R\R\R\R{10}0000001\W
#2\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax XX%
\R.\R.\R.\R.\R.\R.\R.\R.\W 1\Z!\W
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_pow_I_loop #1.%
{%
\ifnum #1 = \xint_c_i\expandafter\XINT_pow_I_exit\fi
\ifodd #1
\expandafter\XINT_pow_II_in
\else
\expandafter\XINT_pow_I_squareit
\fi #1.%
}%
\def\XINT_pow_I_exit \ifodd #1\fi #2.#3\W {\XINT_mul_out #3}%
% \end{macrocode}
% \lverb|The 1.2c \XINT_mul_loop can be called directly even with small
% arguments, hence the "butcheckifsmall" is not a necessity as it was earlier
% with 1.2. On 2^30, it does bring roughly a 40$char37 $space time gain
% though, and 30$char37 $space gain for 2^60. The overhead on big computations
% should be negligible.|
% \begin{macrocode}
\def\XINT_pow_I_squareit #1.#2\W%
{%
\expandafter\XINT_pow_I_loop
\the\numexpr #1/\xint_c_ii\expandafter.%
\the\numexpr\XINT_pow_mulbutcheckifsmall #2\W #2\W
}%
\def\XINT_pow_mulbutcheckifsmall #1!1#2%
{%
\xint_gob_til_Z #2\XINT_pow_mul_small\Z
\XINT_mul_loop 100000000!1\Z!\W #1!1#2%
}%
\def\XINT_pow_mul_small\Z \XINT_mul_loop 100000000!1\Z!\W 1#1!1\Z!\W
{%
\XINT_smallmul 1#1!%
}%
\def\XINT_pow_II_in #1.#2\W
{%
\expandafter\XINT_pow_II_loop
\the\numexpr #1/\xint_c_ii-\xint_c_i\expandafter.%
\the\numexpr\XINT_pow_mulbutcheckifsmall #2\W #2\W #2\W
}%
\def\XINT_pow_II_loop #1.%
{%
\ifnum #1 = \xint_c_i\expandafter\XINT_pow_II_exit\fi
\ifodd #1
\expandafter\XINT_pow_II_odda
\else
\expandafter\XINT_pow_II_even
\fi #1.%
}%
\def\XINT_pow_II_exit\ifodd #1\fi #2.#3\W #4\W
{%
\expandafter\XINT_mul_out
\the\numexpr\XINT_pow_mulbutcheckifsmall #4\W #3%
}%
\def\XINT_pow_II_even #1.#2\W
{%
\expandafter\XINT_pow_II_loop
\the\numexpr #1/\xint_c_ii\expandafter.%
\the\numexpr\XINT_pow_mulbutcheckifsmall #2\W #2\W
}%
\def\XINT_pow_II_odda #1.#2\W #3\W
{%
\expandafter\XINT_pow_II_oddb
\the\numexpr #1/\xint_c_ii-\xint_c_i\expandafter.%
\the\numexpr\XINT_pow_mulbutcheckifsmall #3\W #2\W #2\W
}%
\def\XINT_pow_II_oddb #1.#2\W #3\W
{%
\expandafter\XINT_pow_II_loop
\the\numexpr #1\expandafter.%
\the\numexpr\XINT_pow_mulbutcheckifsmall #3\W #3\W #2\W
}%
% \end{macrocode}
% \subsection{\csh{xintiFac}, \csh{xintiiFac}}
% \lverb|Moved here from xint.sty with release 1.2 (to be usable by \bnumexpr).
%
% The routine has been partially rewritten with release 1.2 to exploit the new
% inner structure of multiplication. I impose an intrinsic limit of the
% argument at maximal value 9999 (1.2f sets it at 10000, there was no reason
% for 9999 and not 10000). Anyhow with current default settings of the
% etex memory and the current 1.2 routine (last commit: eada1b1), the maximal
% possible computation is 5971! (which has 19956 digits). Also, I add
% \xintiiFac which does only \romannumeral-`0 and not \numexpr on its
% argument. This is for a silly slight optimization of the \xintiiexpr (and
% \bnumexpr) parsers. If the argument is >=2^31 an arithmetic overflow will
% occur in the \ifnum. This is not as good as in the \numexpr, but well.
%
% 2015/11/14 added note on the implementation: we can roughly estimate for big
% n that we do n/2 multiplications alpha*X where alpha=(k+1)(k+2)<10^8 and
% X=k! has size of order k log(k), with k along a step 2 arithmetic sequence
% up to n. Each small multiplication should have a linear cost hence O(k
% log(k)) (as we maintain the reversed representation) hence a total cost of
% O(n^2 log(n)); on computing n! for n=100, 200, ..., 2000 I obtained a good
% fit (only roughly 20$char37 $space variation) of the computation time with
% the square of the length of n! -- to the extent that the big variability of
% \pdfelapsedtime allows to draw any conclusion -- I did not repeat the
% computations as many times as I should have. I currently do not quite
% understand why in this range it seems computation times are better fitted by
% O(n^2 log^2 n) than by O(n^2 log n). True, final reverse is O(N^2) with N of
% order n log n, but for this range of n's this is marginal (and I tested also
% with this final reverse skipped).
%
% On the other hand with an approach based on binary splitting n!=AB and
% A=[n/2]! each of A and B will be of size n/2 log(n), but xint schoolbook
% multiplication in TeX is worse than quadratic due to penalty when TeX needs
% to fetch arguments and it didn't seem promising. I didn't even test. Binary
% splitting is good when a fast multiplication is available.
%
% No wait! incredibly a very naive recursive implementation with five lines of
% code via a binary splitting approach with \xintiiMul is only about 1.6x--2x
% slower in the range N=200 to 2000 ! this seems to say that the reversing
% done by \xintiiMul both on input and for output is quite efficient. The best
% case seems to be around N=1000, hence multiplication of 500 digits numbers,
% after that the impact of over-quadratic computation time seems to show: for
% N=4000, the naive binary splitting approach is about 3.4x slower than the
% naive iterated small multiplications as here (naturally with sub-quadratic
% multiplication that would be otherwise).
%
%
% 2015/11/29 for 1.2f: no more a \xintFac, only \xintiFac/\xintiiFac. I could
% not go on like this with \xintFac/\xintiFac/\xintiiFac.|
% \begin{macrocode}
\def\xintiiFac {\romannumeral0\xintiifac }%
\def\xintiifac #1{\expandafter\XINT_fac_fork\the\numexpr#1.}%
\def\xintiFac {\romannumeral0\xintifac }%
\let\xintifac\xintiifac
% \end{macrocode}
% \lverb|Vieux style. Bon je modifie pour 1.2f. Le cas négatif devrait faire
% un 1/0 et créer un Inf.|
% \begin{macrocode}
\def\XINT_fac_fork #1#2.%
{%
\xint_UDzerominusfork
#1-\XINT_fac_zero
0#1\XINT_fac_neg
0-\XINT_fac_checksize
\krof #1#2.%
}%
\def\XINT_fac_zero #1.{ 1}%
\edef\XINT_fac_neg #1.{\noexpand\xintError:FactorialOfNegative\space 1}%
\def\XINT_fac_checksize #1.%
{%
\ifnum #1>\xint_c_x^iv
\xint_dothis{\expandafter\xintError:TooBigFactorial
\expandafter\space\expandafter 1\xint_gob_til_W }\fi
\ifnum #1>465 \xint_dothis{\XINT_fac_bigloop_a #1.}\fi
\ifnum #1>101 \xint_dothis{\XINT_fac_medloop_a #1.\XINT_mul_out}\fi
\xint_orthat{\XINT_fac_smallloop_a #1.\XINT_mul_out}%
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_fac_bigloop_a #1.%
{%
\expandafter\XINT_fac_bigloop_b \the\numexpr
#1+\xint_c_i-\xint_c_ii*((#1-464)/\xint_c_ii).#1.%
}%
\def\XINT_fac_bigloop_b #1.#2.%
{%
\expandafter\XINT_fac_medloop_a
\the\numexpr #1-\xint_c_i.{\XINT_fac_bigloop_loop #1.#2.}%
}%
\def\XINT_fac_bigloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_fac_bigloop_exit\fi
\expandafter\XINT_fac_bigloop_loop
\the\numexpr #1+\xint_c_ii\expandafter.%
\the\numexpr #2\expandafter.\the\numexpr\XINT_fac_bigloop_mul #1!%
}%
\def\XINT_fac_bigloop_exit #1!{\XINT_mul_out}%
\def\XINT_fac_bigloop_mul #1!%
{%
\expandafter\XINT_smallmul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!%
}%
\def\XINT_fac_medloop_a #1.%
{%
\expandafter\XINT_fac_medloop_b
\the\numexpr #1+\xint_c_i-\xint_c_iii*((#1-100)/\xint_c_iii).#1.%
}%
\def\XINT_fac_medloop_b #1.#2.%
{%
\expandafter\XINT_fac_smallloop_a
\the\numexpr #1-\xint_c_i.{\XINT_fac_medloop_loop #1.#2.}%
}%
\def\XINT_fac_medloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_fac_loop_exit\fi
\expandafter\XINT_fac_medloop_loop
\the\numexpr #1+\xint_c_iii\expandafter.%
\the\numexpr #2\expandafter.\the\numexpr\XINT_fac_medloop_mul #1!%
}%
\def\XINT_fac_medloop_mul #1!%
{%
\expandafter\XINT_smallmul
\the\numexpr
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_fac_smallloop_a #1.%
{%
\csname
XINT_fac_smallloop_\the\numexpr #1-\xint_c_iv*(#1/\xint_c_iv)\relax
\endcsname #1.%
}%
\expandafter\def\csname XINT_fac_smallloop_1\endcsname #1.%
{%
\XINT_fac_smallloop_loop 2.#1.100000001!1\Z!%
}%
\expandafter\def\csname XINT_fac_smallloop_-2\endcsname #1.%
{%
\XINT_fac_smallloop_loop 3.#1.100000002!1\Z!%
}%
\expandafter\def\csname XINT_fac_smallloop_-1\endcsname #1.%
{%
\XINT_fac_smallloop_loop 4.#1.100000006!1\Z!%
}%
\expandafter\def\csname XINT_fac_smallloop_0\endcsname #1.%
{%
\XINT_fac_smallloop_loop 5.#1.1000000024!1\Z!%
}%
\def\XINT_fac_smallloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_fac_loop_exit\fi
\expandafter\XINT_fac_smallloop_loop
\the\numexpr #1+\xint_c_iv\expandafter.%
\the\numexpr #2\expandafter.\the\numexpr\XINT_fac_smallloop_mul #1!%
}%
\def\XINT_fac_smallloop_mul #1!%
{%
\expandafter\XINT_smallmul
\the\numexpr
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_fac_loop_exit #1!#2\Z!#3{#3#2\Z!}%
% \end{macrocode}
% \subsection{\csh{xintiDivision}, \csh{xintiQuo}, \csh{xintiRem},
% \csh{xintiiDivision}, \csh{xintiiQuo}, \csh{xintiiRem}}
% \lverb|Completely rewritten for 1.2.
%
% WARNING: some comments below try to describe the flow of tokens but they
% date back to xint 1.09j and I updated them on the fly while doing the 1.2
% version. As the routine now works in base 10^8, not 10^4 and "drops" the
% quotient digits,rather than store them upfront as the earlier code, I may
% well have not correctly converted all such comments. At the last minute some
% previously #1 became stuff like #1#2#3#4, then of course the old comments
% describing what the macro parameters stand for are necessarily wrong.
%
% Side remark: the way tokens are grouped was not essentially modified in
% 1.2, although the situation has changed. It was fine-tuned in xint
% 1.0/1.1 but the context has changed, and perhaps I should revisit this.
% As a corollary to the fact that quotient digits are now left behind thanks
% to the chains of \numexpr, some macros which in 1.0/1.1 fetched up to 9
% parameters now need handle less such parameters. Thus, some rationale for
% the way the code was structured has disappeared.
%
% 1.2 2015/10/15 had a bad bug which got corrected in 1.2b of 2015/10/29: a
% divisor starting with 99999999xyz... would cause a failure, simply because
% it was attempted to use the \XINT_div_mini routine with a divisor of
% 1+99999999=100000000 having 9 digits. Fortunately the origin of the bug was
% easy to find out. Too bad that my obviously very deficient test files
% did not detect it.|
% \begin{macrocode}
\def\xintiiQuo {\romannumeral0\xintiiquo }%
\def\xintiiRem {\romannumeral0\xintiirem }%
\def\xintiiquo {\expandafter\xint_firstoftwo_thenstop\romannumeral0\xintiidivision }%
\def\xintiirem {\expandafter\xint_secondoftwo_thenstop\romannumeral0\xintiidivision }%
\def\xintiQuo {\romannumeral0\xintiquo }%
\def\xintiRem {\romannumeral0\xintirem }%
\def\xintiquo {\expandafter\xint_firstoftwo_thenstop\romannumeral0\xintidivision }%
\def\xintirem {\expandafter\xint_secondoftwo_thenstop\romannumeral0\xintidivision }%
\let\xintQuo\xintiQuo\let\xintquo\xintiquo % deprecated
\let\xintRem\xintiRem\let\xintrem\xintirem % deprecated
% \end{macrocode}
% \lverb-#1 = A, #2 = B. On calcule le quotient et le reste dans la division
% euclidienne de A par B: A=BQ+R, 0<= R < |B|.-
% \begin{macrocode}
\def\xintiDivision {\romannumeral0\xintidivision }%
\def\xintidivision #1{\expandafter\XINT_idivision\romannumeral0\xintnum{#1}\Z }%
\def\XINT_idivision #1#2\Z #3{\expandafter\XINT_iidivision_a\expandafter #1%
\romannumeral0\xintnum{#3}\Z #2\Z }%
\def\xintiiDivision {\romannumeral0\xintiidivision }%
\def\xintiidivision #1{\expandafter\XINT_iidivision \romannumeral`&&@#1\Z }%
\def\XINT_iidivision #1#2\Z #3{\expandafter\XINT_iidivision_a\expandafter #1%
\romannumeral`&&@#3\Z #2\Z }%
% \end{macrocode}
% \lverb|On regarde les signes de A et de B.|
% \begin{macrocode}
\def\XINT_iidivision_a #1#2% #1 de A, #2 de B.
{%
\if0#2\xint_dothis\XINT_iidivision_divbyzero\fi
\if0#1\xint_dothis\XINT_iidivision_aiszero\fi
\if-#2\xint_dothis{\expandafter\XINT_iidivision_bneg
\romannumeral0\XINT_iidivision_bpos #1}\fi
\xint_orthat{\XINT_iidivision_bpos #1#2}%
}%
\def\XINT_iidivision_divbyzero #1\Z #2\Z {\xintError:DivisionByZero{0}{0}}%
\def\XINT_iidivision_aiszero #1\Z #2\Z {{0}{0}}%
\def\XINT_iidivision_bneg #1% q->-q, r unchanged
{\expandafter{\romannumeral0\XINT_opp #1}}%
\def\XINT_iidivision_bpos #1%
{%
\xint_UDsignfork
#1\XINT_iidivision_aneg
-{\XINT_iidivision_apos #1}%
\krof
}%
% \end{macrocode}
% \lverb|Donc attention malgré son nom \XINT_div_prepare va jusqu'au bout.
% C'est donc en fait l'entrée principale (pour B>0, A>0) mais elle va
% regarder si B est < 10^8 et s'il vaut alors 1 ou 2, et si A < 10^8. Dans
% tous les cas le résultat est produit sous la forme {Q}{R}, avec Q et R sous
% leur forme final. On doit ensuite ajuster si le B ou le A initial était
% négatif. Je n'ai pas fait beaucoup d'efforts pour être un minimum efficace
% si A ou B n'est pas positif.|
% \begin{macrocode}
\def\XINT_iidivision_apos #1#2\Z #3\Z{\XINT_div_prepare {#2}{#1#3}}%
\def\XINT_iidivision_aneg #1\Z #2\Z
{\expandafter
\XINT_iidivision_aneg_b\romannumeral0\XINT_div_prepare {#1}{#2}{#1}}%
\def\XINT_iidivision_aneg_b #1#2{\if0\XINT_Sgn #2\Z
\expandafter\XINT_iidivision_aneg_rzero
\else
\expandafter\XINT_iidivision_aneg_rpos
\fi {#1}{#2}}%
\def\XINT_iidivision_aneg_rzero #1#2#3{{-#1}{0}}% necessarily q was >0
\def\XINT_iidivision_aneg_rpos #1%
{%
\expandafter\XINT_iidivision_aneg_end\expandafter
{\expandafter-\romannumeral0\xintinc {#1}}% q-> -(1+q)
}%
\def\XINT_iidivision_aneg_end #1#2#3%
{%
\expandafter\xint_exchangetwo_keepbraces
\expandafter{\romannumeral0\XINT_sub_mm_a {}{}#3\Z #2\Z}{#1}% r-> b-r
}%
% \end{macrocode}
% \lverb|Le diviseur B va être étendu par des zéros pour que sa longueur soit
% multiple de huit. Les zéros seront mis du côté non significatif.|
% \begin{macrocode}
\def\XINT_div_prepare #1%
{%
\XINT_div_prepare_a #1\R\R\R\R\R\R\R\R {10}0000001\W !{#1}%
}%
\def\XINT_div_prepare_a #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_div_prepare_small\R
\XINT_div_prepare_b #9%
}%
% \end{macrocode}
% \lverb|B a au plus huit chiffres. On se débarrasse des trucs superflus. Si
% B>0 n'est ni 1 ni 2, le point d'entrée est \XINT_div_small_a {B}{A} (avec un
% A positif).|
% \begin{macrocode}
\def\XINT_div_prepare_small\R #1!#2%
{%
\ifcase #2
\or\expandafter\XINT_div_BisOne
\or\expandafter\XINT_div_BisTwo
\else\expandafter\XINT_div_small_a
\fi {#2}%
}%
\def\XINT_div_BisOne #1#2{{#2}{0}}%
\def\XINT_div_BisTwo #1#2%
{%
\expandafter\expandafter\expandafter\XINT_div_BisTwo_a
\ifodd\xintLDg{#2} \expandafter1\else \expandafter0\fi {#2}%
}%
\def\XINT_div_BisTwo_a #1#2%
{%
\expandafter{\romannumeral0\xinthalf {#2}}{#1}%
}%
% \end{macrocode}
% \lverb|B a au plus huit chiffres et est au moins 3. On va l'utiliser
% directement, sans d'abord le multiplier par une puissance de 10 pour qu'il
% ait 8 chiffres.|
% \begin{macrocode}
\def\XINT_div_small_a #1#2%
{%
\expandafter\XINT_div_small_b
\the\numexpr #1/\xint_c_ii\expandafter
.\the\numexpr \xint_c_x^viii+#1\expandafter!%
\romannumeral0%
\XINT_div_small_ba #2\R\R\R\R\R\R\R\R{10}0000001\W
#2\XINT_sepbyviii_Z_end 2345678\relax
}%
% \end{macrocode}
% \lverb|Le #2 poursuivra l'expansion par \XINT_div_dosmallsmall ou par
% \XINT_smalldivx_a suivi de \XINT_sdiv_out.|
% \begin{macrocode}
\def\XINT_div_small_b #1!#2{#2#1!}%
% \end{macrocode}
% \lverb|On ajoute des zéros avant A, puis on le prépare sous la forme de
% blocs 1<8d>! Au passage on repère le cas d'un A<10^8.|
% \begin{macrocode}
\def\XINT_div_small_ba #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_div_smallsmall\R
\expandafter\XINT_div_dosmalldiv
\the\numexpr\expandafter\XINT_sepbyviii_Z
\romannumeral0\XINT_zeroes_forviii
#1#2#3#4#5#6#7#8#9%
}%
% \end{macrocode}
% \lverb|Si A<10^8, on va poursuivre par \XINT_div_dosmallsmall
% round(B/2).10^8+B!{A}. On fait la division directe par \numexpr. Le résultat
% est produit sous la forme {Q}{R}.|
% \begin{macrocode}
\def\XINT_div_smallsmall\R
\expandafter\XINT_div_dosmalldiv
\the\numexpr\expandafter\XINT_sepbyviii_Z
\romannumeral0\XINT_zeroes_forviii #1\R #2\relax
{{\XINT_div_dosmallsmall}{#1}}%
\def\XINT_div_dosmallsmall #1.1#2!#3%
{%
\expandafter\XINT_div_smallsmallend
\the\numexpr (#3+#1)/#2-\xint_c_i.#2.#3.%
}%
\def\XINT_div_smallsmallend #1.#2.#3.{\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #3-#1*#2}}%
% \end{macrocode}
% \lverb|Si A>=10^8, il est maintenant sous la forme 1<8d>!...1<8d>!1\Z! avec
% plus significatifs en premier. Donc on poursuit par$newline
% \expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a
% x.1B!1<8d>!...1<8d>!1\Z! avec x =round(B/2), 1B=10^8+B.|
% \begin{macrocode}
\def\XINT_div_dosmalldiv
{{\expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a}}%
% \end{macrocode}
% \lverb|Ici B est au moins 10^8, on détermine combien de zéros lui adjoindre
% pour qu'il soit de longueur 8N.|
% \begin{macrocode}
\def\XINT_div_prepare_b
{\expandafter\XINT_div_prepare_c\romannumeral0\XINT_zeroes_forviii }%
\def\XINT_div_prepare_c #1!%
{%
\XINT_div_prepare_d #1.00000000!{#1}%
}%
\def\XINT_div_prepare_d #1#2#3#4#5#6#7#8#9%
{%
\expandafter\XINT_div_prepare_e\xint_gob_til_dot #1#2#3#4#5#6#7#8#9!%
}%
\def\XINT_div_prepare_e #1!#2!#3#4%
{%
\XINT_div_prepare_f #4#3\X {#1}{#3}%
}%
% \end{macrocode}
% \lverb|attention qu'on calcule ici x'=x+1 (x = huit premiers chiffres du
% diviseur) et que si x=99999999, x' aura donc 9 chiffres, pas compatible avec
% div_mini (avant 1.2, x avait 4 chiffres, et on faisait la division avec x'
% dans un \numexpr). Bon, facile à dire après avoir laissé passer ce bug dans
% 1.2. C'est le problème lorsqu'au lieu de tout refaire à partir de zéro on
% recycle d'anciennes routines qui avaient un contexte différent.|
% \begin{macrocode}
\def\XINT_div_prepare_f #1#2#3#4#5#6#7#8#9\X
{%
\expandafter\XINT_div_prepare_g
\the\numexpr #1#2#3#4#5#6#7#8+\xint_c_i\expandafter
.\the\numexpr (#1#2#3#4#5#6#7#8+\xint_c_i)/\xint_c_ii\expandafter
.\the\numexpr #1#2#3#4#5#6#7#8\expandafter
.\romannumeral0\XINT_sepandrev_andcount
#1#2#3#4#5#6#7#8#9\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678%
\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\X
}%
\def\XINT_div_prepare_g #1.#2.#3.#4.#5\X #6#7#8%
{%
\expandafter\XINT_div_prepare_h
\the\numexpr\expandafter\XINT_sepbyviii_andcount
\romannumeral0\XINT_zeroes_forviii #8#7\R\R\R\R\R\R\R\R{10}0000001\W
#8#7\XINT_sepbyviii_end 2345678\relax
\xint_c_vii!\xint_c_vi!\xint_c_v!\xint_c_iv!%
\xint_c_iii!\xint_c_ii!\xint_c_i!\xint_c_\W
{#1}{#2}{#3}{#4}{#5}{#6}%
}%
\def\XINT_div_prepare_h #11.#2.#3#4#5#6%#7#8%
{%
\XINT_div_start_a {#2}{#6}{#1}{#3}{#4}{#5}%{#7}{#8}%
}%
% \end{macrocode}
% \lverb|L, K, A, x',y,x, B, «c». Attention que K est diminué de 1 plus loin.
% Comme xint 1.2 a déjà repéré K=1, on a ici au minimum K=2. Attention B est à
% l'envers, A est à l'endroit et les deux avec séparateurs. Attention que ce
% n'est pas ici qu'on boucle mais en \XINT_div_I_a.|
% \begin{macrocode}
\def\XINT_div_start_a #1#2%
{%
\ifnum #1 < #2
\expandafter\XINT_div_zeroQ
\else
\expandafter\XINT_div_start_b
\fi
{#1}{#2}%
}%
\def\XINT_div_zeroQ #1#2#3#4#5#6#7%
{%
\expandafter\XINT_div_zeroQ_end
\romannumeral0\XINT_unsep_cuzsmall
#31\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W .%
}%
\def\XINT_div_zeroQ_end #1.#2%
{\expandafter{\expandafter0\expandafter}\XINT_div_cleanR #1#2.}%
% \end{macrocode}
% \lverb|L, K, A, x',y,x, B, «c»->K.A.x{LK{x'y}x}B«c»|
% \begin{macrocode}
\def\XINT_div_start_b #1#2#3#4#5#6%
{%
\expandafter\XINT_div_finish\the\numexpr
\XINT_div_start_c {#2}.#3.{#6}{{#1}{#2}{{#4}{#5}}{#6}}%
}%
\def\XINT_div_finish
{%
\expandafter\XINT_div_finish_a \romannumeral`&&@\XINT_div_unsepQ
}%
\def\XINT_div_finish_a #1\Z #2.{\XINT_div_finish_b #2.{#1}}%
% \end{macrocode}
% \lverb|Ici ce sont routines de fin. Le reste déjà nettoyé. R.Q«c».|
% \begin{macrocode}
\def\XINT_div_finish_b #1%
{%
\if0#1%
\expandafter\XINT_div_finish_bRzero
\else
\expandafter\XINT_div_finish_bRpos
\fi
#1%
}%
\def\XINT_div_finish_bRzero 0.#1#2{{#1}{0}}%
\def\XINT_div_finish_bRpos #1.#2#3%
{%
\expandafter\xint_exchangetwo_keepbraces\XINT_div_cleanR #1#3.{#2}%
}%
\def\XINT_div_cleanR #100000000.{{#1}}%
% \end{macrocode}
% \lverb|Kalpha.A.x{LK{x'y}x}, B, «c», au début #2=alpha est vide. On fait une
% boucle pour prendre K unités de A (on a au moins L égal à K) et les mettre
% dans alpha.|
% \begin{macrocode}
\def\XINT_div_start_c #1%
{%
\ifnum #1>\xint_c_vi
\expandafter\XINT_div_start_ca
\else
\expandafter\XINT_div_start_cb
\fi {#1}%
}%
\def\XINT_div_start_ca #1#2.#3!#4!#5!#6!#7!#8!#9!%
{%
\expandafter\XINT_div_start_c\expandafter
{\the\numexpr #1-\xint_c_vii}#2#3!#4!#5!#6!#7!#8!#9!.%
}%
\def\XINT_div_start_cb #1%
{\csname XINT_div_start_c_\romannumeral\numexpr#1\endcsname}%
\def\XINT_div_start_c_i #1.#2!%
{\XINT_div_start_c_ #1#2!.}%
\def\XINT_div_start_c_ii #1.#2!#3!%
{\XINT_div_start_c_ #1#2!#3!.}%
\def\XINT_div_start_c_iii #1.#2!#3!#4!%
{\XINT_div_start_c_ #1#2!#3!#4!.}%
\def\XINT_div_start_c_iv #1.#2!#3!#4!#5!%
{\XINT_div_start_c_ #1#2!#3!#4!#5!.}%
\def\XINT_div_start_c_v #1.#2!#3!#4!#5!#6!%
{\XINT_div_start_c_ #1#2!#3!#4!#5!#6!.}%
\def\XINT_div_start_c_vi #1.#2!#3!#4!#5!#6!#7!%
{\XINT_div_start_c_ #1#2!#3!#4!#5!#6!#7!.}%
% \end{macrocode}
% \lverb|#1=a, #2=alpha (de longueur K, à l'endroit).#3=reste de A.#4=x,
% #5={LK{x'y}x},#6=B,«c» -> a, x, alpha, B, {00000000}, L, K, {x'y},x,
% alpha'=reste de A, B«c».|
% \begin{macrocode}
\def\XINT_div_start_c_ 1#1!#2.#3.#4#5#6%
{%
\XINT_div_I_a {#1}{#4}{1#1!#2}{#6}{00000000}#5{#3}{#6}%
}%
% \end{macrocode}
% \lverb|Ceci est le point de retour de la boucle principale. a, x, alpha, B,
% q0, L, K, {x'y}, x, alpha', B«c» |
% \begin{macrocode}
\def\XINT_div_I_a #1#2%
{%
\expandafter\XINT_div_I_b\the\numexpr #1/#2.{#1}{#2}%
}%
\def\XINT_div_I_b #1%
{%
\xint_gob_til_zero #1\XINT_div_I_czero 0\XINT_div_I_c #1%
}%
% \end{macrocode}
% \lverb|On intercepte petit quotient nul: #1=a, x, alpha, B, #5=q0, L, K,
% {x'y}, x, alpha', B«c» -> on lâche un q puis {alpha} L, K, {x'y}, x,
% alpha', B«c».|
% \begin{macrocode}
\def\XINT_div_I_czero 0\XINT_div_I_c 0.#1#2#3#4#5{1#5\XINT_div_I_g {#3}}%
\def\XINT_div_I_c #1.#2#3%
{%
\expandafter\XINT_div_I_da\the\numexpr #2-#1*#3.#1.{#2}{#3}%
}%
% \end{macrocode}
% \lverb|r.q.alpha, B, q0, L, K, {x'y}, x, alpha', B«c»|
% \begin{macrocode}
\def\XINT_div_I_da #1.%
{%
\ifnum #1>\xint_c_ix
\expandafter\XINT_div_I_dP
\else
\ifnum #1<\xint_c_
\expandafter\expandafter\expandafter\XINT_div_I_dN
\else
\expandafter\expandafter\expandafter\XINT_div_I_db
\fi
\fi
}%
% \end{macrocode}
% \lverb|attention très mauvaises notations avec _b et _db.|
% \begin{macrocode}
\def\XINT_div_I_dN #1.%
{%
\expandafter\XINT_div_I_b\the\numexpr #1-\xint_c_i.%
}%
\def\XINT_div_I_db #1.#2#3#4#5%
{%
\expandafter\XINT_div_I_dc\expandafter #1%
\romannumeral0\expandafter\XINT_div_sub\expandafter
{\romannumeral0\XINT_rev_nounsep {}#4\R!\R!\R!\R!\R!\R!\R!\R!\W}%
{\the\numexpr\XINT_div_verysmallmul #1!#51\Z!}%
\Z {#4}{#5}%
}%
% \end{macrocode}
% \lverb|La soustraction spéciale renvoie simplement - si le chiffre q est
% trop grand. On invoque dans ce cas I_dP.|
% \begin{macrocode}
\def\XINT_div_I_dc #1#2%
{%
\if-#2\expandafter\XINT_div_I_dd\else\expandafter\XINT_div_I_de\fi
#1#2%
}%
\def\XINT_div_I_dd #1-\Z
{%
\if #11\expandafter\XINT_div_I_dz\fi
\expandafter\XINT_div_I_dP\the\numexpr #1-\xint_c_i.XX%
}%
\def\XINT_div_I_dz #1XX#2#3#4%
{%
1#4\XINT_div_I_g {#2}%
}%
\def\XINT_div_I_de #1#2\Z #3#4#5{1#5+#1\XINT_div_I_g {#2}}%
% \end{macrocode}
% \lverb|q.alpha, B, q0, L, K, {x'y},x, alpha'B«c» (q=0 has been intercepted)
% -> 1nouveauq.nouvel alpha, L, K, {x'y}, x, alpha',B«c»|
% \begin{macrocode}
\def\XINT_div_I_dP #1.#2#3#4#5#6%
{%
1#6+#1\expandafter\XINT_div_I_g\expandafter
{\romannumeral0\expandafter\XINT_div_sub\expandafter
{\romannumeral0\XINT_rev_nounsep {}#4\R!\R!\R!\R!\R!\R!\R!\R!\W}%
{\the\numexpr\XINT_div_verysmallmul #1!#51\Z!}%
}%
}%
% \end{macrocode}
% \lverb|1#1=nouveau q. nouvel alpha, L, K, {x'y},x,alpha', BQ«c»|
% \begin{macrocode}
% \end{macrocode}
% \lverb|#1=q,#2=nouvel alpha,#3=L, #4=K, #5={x'y}, #6=x, #7= alpha',#8=B,
% «c» -> on laisse q puis {x'y}alpha.alpha'.{{x'y}xKL}B«c»|
% \begin{macrocode}
\def\XINT_div_I_g #1#2#3#4#5#6#7%
{%
\expandafter !\the\numexpr
\ifnum#2=#3
\expandafter\XINT_div_exittofinish
\else
\expandafter\XINT_div_I_h
\fi
{#4}#1.#6.{{#4}{#5}{#3}{#2}}{#7}%
}%
% \end{macrocode}
% \lverb|{x'y}alpha.alpha'.{{x'y}xKL}B«c» -> Attention retour à l'envoyeur ici
% par terminaison des \the\numexpr. On doit reprendre le Q déjà sorti, qui n'a
% plus de séparateurs, ni de leading 1. Ensuite R sans leading zeros.«c»|
% \begin{macrocode}
\def\XINT_div_exittofinish #1#2.#3.#4#5%
{%
1\expandafter\expandafter\expandafter!\expandafter\XINT_unsep_delim
\romannumeral0\XINT_div_unsepR #2#31\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W.%
}%
% \end{macrocode}
% \lverb|ATTENTION DESCRIPTION OBSOLÈTE. #1={x'y}alpha.#2!#3=reste de A.
% #4={{x'y},x,K,L},#5=B,«c» devient {x'y},alpha sur K+4 chiffres.B,
% {{x'y},x,K,L}, #6= nouvel alpha',B,«c»|
% \begin{macrocode}
\def\XINT_div_I_h #1.#2!#3.#4#5%
{%
\XINT_div_II_b #1#2!.{#5}{#4}{#3}{#5}%
}%
% \end{macrocode}
% \lverb|{x'y}alpha.B, {{x'y},x,K,L}, nouveau alpha',B,«c»|
% \begin{macrocode}
\def\XINT_div_II_b #11#2!#3!%
{%
\xint_gob_til_eightzeroes #2\XINT_div_II_skipc 00000000%
\XINT_div_II_c #1{1#2}{#3}%
}%
% \end{macrocode}
% \lverb|x'y{100000000}{1<8>}reste de alpha.#6=B,#7={{x'y},x,K,L}, alpha',B,
% «c» -> {x'y}x,K,L (à diminuer de 4), {alpha sur
% K}B{q1=00000000}{alpha'}B,«c»|
% \begin{macrocode}
\def\XINT_div_II_skipc 00000000\XINT_div_II_c #1#2#3#4#5.#6#7%
{%
\XINT_div_II_k #7{#4!#5}{#6}{00000000}%
}%
% \end{macrocode}
% \lverb|x'ya->1qx'yalpha.B, {{x'y},x,K,L}, nouveau alpha',B, «c». En fait,
% attention, ici #3 et #4 sont les 16 premiers chiffres du numérateur,sous la
% forme blocs 1<8chiffres>.
%
% ATTENTION!
%
% 2015/10/29 :j'avais introduit un bug ici dans 1.2 2015/10/15, car
% \XINT_div_mini veut un diviseur de huit chiffres, or si le dénominateur B
% débute par x=99999999, on aura x'=100000000, d'où évidemment un bug. Bon il
% faut intercepter x'=100000000.
%
% I need to recognize x'=100000000 in some not too penalizing way. Anyway,
% will try to optimize some other day.|
% \begin{macrocode}
\def\XINT_div_II_c #1#2#3#4%
{%
\expandafter\XINT_div_II_d\the\numexpr\XINT_div_xmini
#1.#2!#3!#4!{#1}{#2}#3!#4!%
}%
\def\XINT_div_xmini #1%
{%
\xint_gob_til_one #1\XINT_div_xmini_a 1\XINT_div_mini #1%
}%
\def\XINT_div_xmini_a 1\XINT_div_mini 1#1%
{%
\xint_gob_til_zero #1\XINT_div_xmini_b 0\XINT_div_mini 1#1%
}%
\def\XINT_div_xmini_b 0\XINT_div_mini 10#1#2#3#4#5#6#7%
{%
\xint_gob_til_zero #7\XINT_div_xmini_c 0\XINT_div_mini 10#1#2#3#4#5#6#7%
}%
% \end{macrocode}
% \lverb|x'=10^8 and we return #1=1<8digits>.|
% \begin{macrocode}
\def\XINT_div_xmini_c 0\XINT_div_mini 100000000.50000000!#1!#2!{#1!}%
% \end{macrocode}
% \lverb|1 suivi de q1 sur huit chiffres! #2=x', #3=y, #4=alpha.#5=B,
% {{x'y},x,K,L}, alpha', B, «c» --> nouvel alpha.x',y,B,q1,{{x'y},x,K,L},
% alpha', B, «c» |
% \begin{macrocode}
\def\XINT_div_II_d 1#1#2#3#4#5!#6#7#8.#9%
{%
\expandafter\XINT_div_II_e
\romannumeral0\expandafter\XINT_div_sub\expandafter
{\romannumeral0\XINT_rev_nounsep {}#8\R!\R!\R!\R!\R!\R!\R!\R!\W}%
{\the\numexpr\XINT_div_smallmul_a 100000000.#1#2#3#4.#5!#91\Z!}%
.{#6}{#7}{#9}{#1#2#3#4#5}%
}%
% \end{macrocode}
% \lverb|alpha.x',y,B,q1, {{x'y},x,K,L}, alpha', B, «c». Attention la
% soustraction spéciale doit maintenir les blocs 1<8>!|
% \begin{macrocode}
\def\XINT_div_II_e 1#1!%
{%
\xint_gob_til_eightzeroes #1\XINT_div_II_skipf 00000000%
\XINT_div_II_f 1#1!%
}%
% \end{macrocode}
% \lverb|100000000!alpha sur K chiffres.#2=x',#3=y,#4=B,#5=q1, #6={{x'y},x,K,L},
% #7=alpha',B«c» -> {x'y}x,K,L (à diminuer de 1),
% {alpha sur K}B{q1}{alpha'}B«c»|
% \begin{macrocode}
\def\XINT_div_II_skipf 00000000\XINT_div_II_f 100000000!#1.#2#3#4#5#6%
{%
\XINT_div_II_k #6{#1}{#4}{#5}%
}%
% \end{macrocode}
% \lverb|1<a1>!1<a2>!, alpha (sur K+1 blocs de 8). x', y, B, q1, {{x'y},x,K,L},
% alpha', B,«c».
%
% Here also we are dividing with x' which could be 10^8 in the exceptional
% case x=99999999. Must intercept it before sending to \XINT_div_mini.|
% \begin{macrocode}
\def\XINT_div_II_f #1!#2!#3.%
{%
\XINT_div_II_fa {#1!#2!}{#1!#2!#3}%
}%
\def\XINT_div_II_fa #1#2#3#4%
{%
\expandafter\XINT_div_II_g \the\numexpr\XINT_div_xmini #3.#4!#1{#2}%
}%
% \end{macrocode}
% \lverb|#1=q, #2=alpha (K+4), #3=B, #4=q1, {{x'y},x,K,L}, alpha', BQ«c»
% -> 1 puis nouveau q sur 8 chiffres. nouvel alpha sur K blocs,
% B, {{x'y},x,K,L}, alpha',B«c» |
% \begin{macrocode}
\def\XINT_div_II_g 1#1#2#3#4#5!#6#7#8%
{%
\expandafter \XINT_div_II_h
\the\numexpr 1#1#2#3#4#5+#8\expandafter\expandafter\expandafter
.\expandafter\expandafter\expandafter
{\expandafter\xint_gob_til_exclam
\romannumeral0\expandafter\XINT_div_sub\expandafter
{\romannumeral0\XINT_rev_nounsep {}#6\R!\R!\R!\R!\R!\R!\R!\R!\W}%
{\the\numexpr\XINT_div_smallmul_a 100000000.#1#2#3#4.#5!#71\Z!}}%
{#7}%
}%
% \end{macrocode}
% \lverb|1 puis nouveau q sur 8 chiffres, #2=nouvel alpha sur K blocs,
% #3=B, #4={{x'y},x,K,L} avec L à ajuster, alpha', BQ«c»
% -> {x'y}x,K,L à diminuer de 1, {alpha}B{q}, alpha', BQ«c»|
% \begin{macrocode}
\def\XINT_div_II_h 1#1.#2#3#4%
{%
\XINT_div_II_k #4{#2}{#3}{#1}%
}%
% \end{macrocode}
% \lverb|{x'y}x,K,L à diminuer de 1, alpha, B{q}alpha',B«c»
% ->nouveau L.K,x',y,x,alpha.B,q,alpha',B,«c»
% ->{LK{x'y}x},x,a,alpha.B,q,alpha',B,«c»|
% \begin{macrocode}
\def\XINT_div_II_k #1#2#3#4#5%
{%
\expandafter\XINT_div_II_l \the\numexpr #4-\xint_c_i.{#3}#1{#2}#5.%
}%
\def\XINT_div_II_l #1.#2#3#4#51#6!%
{%
\XINT_div_II_m {{#1}{#2}{{#3}{#4}}{#5}}{#5}{#6}1#6!%
}%
% \end{macrocode}
% \lverb|{LK{x'y}x},x,a,alpha.B{q}alpha'B -> a, x, alpha, B, q,
% L, K, {x'y}, x, alpha', B«c» |
% \begin{macrocode}
\def\XINT_div_II_m #1#2#3#4.#5#6%
{%
\XINT_div_I_a {#3}{#2}{#4}{#5}{#6}#1%
}%
% \end{macrocode}
% \lverb|This multiplication is exactly like \XINT_smallmul -- apart from not
% inserting an ending 1\Z! --, but keeps ever a vanishing ending carry.|
% \begin{macrocode}
\def\XINT_div_minimulwc_a 1#1.#2.#3!#4#5#6#7#8.%
{%
\expandafter\XINT_div_minimulwc_b
\the\numexpr \xint_c_x^ix+#1+#3*#8.#3*#4#5#6#7+#2*#8.#2*#4#5#6#7.%
}%
\def\XINT_div_minimulwc_b 1#1#2#3#4#5#6.#7.%
{%
\expandafter\XINT_div_minimulwc_c
\the\numexpr \xint_c_x^ix+#1#2#3#4#5+#7.#6.%
}%
\def\XINT_div_minimulwc_c 1#1#2#3#4#5#6.#7.#8.%
{%
1#6#7\expandafter!%
\the\numexpr\expandafter\XINT_div_smallmul_a
\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#8.%
}%
\def\XINT_div_smallmul_a #1.#2.#3!1#4!%
{%
\xint_gob_til_Z #4\XINT_div_smallmul_e\Z
\XINT_div_minimulwc_a #1.#2.#3!#4.#2.#3!%
}%
\def\XINT_div_smallmul_e\Z\XINT_div_minimulwc_a 1#1.#2\Z #3!{1\relax #1!}%
% \end{macrocode}
% \lverb|Special very small multiplication for division. We only need to cater
% for multiplicands from 1 to 9. The ending is different from standard
% verysmallmul, a zero carry is not suppressed. And no final 1\Z! is added. If
% multiplicand is just 1 let's not forget to add the zero carry 100000000! at
% the end.|
% \begin{macrocode}
\def\XINT_div_verysmallmul #1%
{\xint_gob_til_one #1\XINT_div_verysmallisone 1\XINT_div_verysmallmul_a 0.#1}%
\def\XINT_div_verysmallisone 1\XINT_div_verysmallmul_a 0.1!1#11\Z!%
{1\relax #1100000000!}%
\def\XINT_div_verysmallmul_a #1.#2!1#3!%
{%
\xint_gob_til_Z #3\XINT_div_verysmallmul_e\Z
\expandafter\XINT_div_verysmallmul_b
\the\numexpr \xint_c_x^ix+#2*#3+#1.#2!%
}%
\def\XINT_div_verysmallmul_b 1#1#2.%
{1#2\expandafter!\the\numexpr\XINT_div_verysmallmul_a #1.}%
\def\XINT_div_verysmallmul_e\Z #1\Z +#2#3!{1\relax 0000000#2!}%
% \end{macrocode}
% \lverb|Special subtraction for division purposes. If the subtracted thing
% turns out to be bigger, then just return a -. If not, then we must reverse
% the result, keeping the separators.|
% \begin{macrocode}
\def\XINT_div_sub #1#2%
{%
\expandafter\XINT_div_sub_clean
\the\numexpr\expandafter\XINT_div_sub_a\expandafter
1#2\Z!\Z!\Z!\Z!\Z!\W #1\Z!\Z!\Z!\Z!\Z!\W
}%
\def\XINT_div_sub_clean #1-#2#3\W
{%
\if1#2\expandafter\XINT_rev_nounsep\else\expandafter\XINT_div_sub_neg\fi
{}#1\R!\R!\R!\R!\R!\R!\R!\R!\W
}%
\def\XINT_div_sub_neg #1\W { -}%
\def\XINT_div_sub_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!%
{%
\XINT_div_sub_b #1!#6!#2!#7!#3!#8!#4!#9!#5\W
}%
\def\XINT_div_sub_b #1#2#3!#4!%
{%
\xint_gob_til_Z #4\XINT_div_sub_bi \Z
\expandafter\XINT_div_sub_c\the\numexpr#1-#3+1#4-\xint_c_i.%
}%
\def\XINT_div_sub_c 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_div_sub_d #1%
}%
\def\XINT_div_sub_d #1#2#3!#4!%
{%
\xint_gob_til_Z #4\XINT_div_sub_di \Z
\expandafter\XINT_div_sub_e\the\numexpr#1-#3+1#4-\xint_c_i.%
}%
\def\XINT_div_sub_e 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_div_sub_f #1%
}%
\def\XINT_div_sub_f #1#2#3!#4!%
{%
\xint_gob_til_Z #4\XINT_div_sub_fi \Z
\expandafter\XINT_div_sub_g\the\numexpr#1-#3+1#4-\xint_c_i.%
}%
\def\XINT_div_sub_g 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_div_sub_h #1%
}%
\def\XINT_div_sub_h #1#2#3!#4!%
{%
\xint_gob_til_Z #4\XINT_div_sub_hi \Z
\expandafter\XINT_div_sub_i\the\numexpr#1-#3+1#4-\xint_c_i.%
}%
\def\XINT_div_sub_i 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_div_sub_a #1%
}%
\def\XINT_div_sub_bi\Z
\expandafter\XINT_div_sub_c\the\numexpr#1-#2+#3.#4!#5!#6!#7!#8!#9!\Z !\W
{%
\XINT_div_sub_l #1#2!#5!#7!#9!%
}%
\def\XINT_div_sub_di\Z
\expandafter\XINT_div_sub_e\the\numexpr#1-#2+#3.#4!#5!#6!#7!#8\W
{%
\XINT_div_sub_l #1#2!#5!#7!%
}%
\def\XINT_div_sub_fi\Z
\expandafter\XINT_div_sub_g\the\numexpr#1-#2+#3.#4!#5!#6\W
{%
\XINT_div_sub_l #1#2!#5!%
}%
\def\XINT_div_sub_hi\Z
\expandafter\XINT_div_sub_i\the\numexpr#1-#2+#3.#4\W
{%
\XINT_div_sub_l #1#2!%
}%
\def\XINT_div_sub_l #1%
{%
\xint_UDzerofork
#1{-2\relax}%
0\XINT_div_sub_r
\krof
}%
\def\XINT_div_sub_r #1!%
{%
-\ifnum 0#1=\xint_c_ 1\else2\fi\relax
}%
% \end{macrocode}
% \lverb|Ici B<10^8 (et est >2). On
% exécute$newline
% \expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a
% x.1B!1<8d>!...1<8d>!1\Z!$newline
% avec x =round(B/2), 1B=10^8+B, et A déjà en
% blocs 1<8d>! (non renversés). Le \the\numexpr\XINT_smalldivx_a va produire
% Q\Z R\W avec un R<10^8, et un Q sous forme de blocs 1<8d>! terminé par 1!
% et nécessitant le nettoyage du premier bloc. Dans cette branche le B n'a pas
% été multiplié par une puissance de 10, il peut avoir moins de huit chiffres.
%
% |
% \begin{macrocode}
\def\XINT_sdiv_out #1\Z!#2!%
{\expandafter
{\romannumeral0\XINT_unsep_cuzsmall#11\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W}%
{#2}}%
% \end{macrocode}
% \lverb|La toute première étape fait la première division pour être sûr par
% la suite d'avoir un premier bloc pour A qui sera < B.|
% \begin{macrocode}
\def\XINT_smalldivx_a #1.1#2!1#3!%
{%
\expandafter\XINT_smalldivx_b
\the\numexpr (#3+#1)/#2-\xint_c_i!#1.#2!#3!%
}%
\def\XINT_smalldivx_b #1#2!%
{%
\if0#1\else
\xint_c_x^viii+#1#2\xint_afterfi{\expandafter!\the\numexpr}\fi
\XINT_smalldiv_c #1#2!%
}%
\def\XINT_smalldiv_c #1!#2.#3!#4!%
{%
\expandafter\XINT_smalldiv_d\the\numexpr #4-#1*#3!#2.#3!%
}%
% \end{macrocode}
% \lverb|On va boucler ici: #1 est un reste, #2 est x.B (avec B sans le 1 mais
% sur huit chiffres). #3#4 est le premier bloc qui reste de A. Si on a terminé
% avec A, alors #1 est le reste final. Le quotient lui est terminé par un 1!:
% ce 1! disparaîtra dans le nettoyage par \XINT_unsep_cuzsmall. Ce dernier,
% malgré le fait qu'on soit dans le bon ordre déjà fait une macro dans le
% style O(N^2) car sinon le nombre maximal de chiffres serait moitié moins à
% cause des nettoyages nécessaires après \numexpr. Je suis obligé de faire un
% nettoyage final car comme l'expansion est engendrée par \numexpr, elle me
% boufferait des leading zeros si je ne mettais pas un 1 devant chaque bloc en
% sortie de Q.|
% \begin{macrocode}
\def\XINT_smalldiv_d #1!#2!1#3#4!%
{%
\xint_gob_til_Z #3\XINT_smalldiv_end \Z
\XINT_smalldiv_e #1!#2!1#3#4!%
}%
\def\XINT_smalldiv_end\Z\XINT_smalldiv_e #1!#2!1\Z!{1!\Z!#1!}%
% \end{macrocode}
% \lverb|Il est crucial que le reste #1 est < #3. J'ai documenté cette routine
% dans le fichier où j'ai préparé 1.2, il faudra transférer ici. Il n'est pas
% nécessaire pour cette routine que le diviseur B ait au moins 8 chiffres.
% Mais il doit être < 10^8.|
% \begin{macrocode}
\def\XINT_smalldiv_e #1!#2.#3!%
{%
\expandafter\XINT_smalldiv_f\the\numexpr
\xint_c_xi_e_viii_mone+#1*\xint_c_x^viii/#3!#2.#3!#1!%
}%
\def\XINT_smalldiv_f 1#1#2#3#4#5#6!#7.#8!%
{%
\xint_gob_til_zero #1\XINT_smalldiv_fz 0%
\expandafter\XINT_smalldiv_g
\the\numexpr\XINT_minimul_a #2#3#4#5.#6!#8!#2#3#4#5#6!#7.#8!%
}%
\def\XINT_smalldiv_fz 0%
\expandafter\XINT_smalldiv_g\the\numexpr\XINT_minimul_a
9999.9999!#1!99999999!#2!0!1#3!%
{%
\XINT_smalldiv_i .#3!\xint_c_!#2!%
}%
\def\XINT_smalldiv_g 1#1!1#2!#3!#4!#5!#6!%
{%
\expandafter\XINT_smalldiv_h\the\numexpr 1#6-#1.#2!#5!#3!#4!%
}%
\def\XINT_smalldiv_h 1#1#2.#3!#4!%
{%
\expandafter\XINT_smalldiv_i\the\numexpr #4-#3+#1-\xint_c_i.#2!%
}%
\def\XINT_smalldiv_i #1.#2!#3!#4.#5!%
{%
\expandafter\XINT_smalldiv_j\the\numexpr (#1#2+#4)/#5-\xint_c_i!#3!#1#2!#4.#5!%
}%
\def\XINT_smalldiv_j #1!#2!%
{%
\xint_c_x^viii+#1+#2\expandafter!\the\numexpr\XINT_smalldiv_k
#1!%
}%
% \end{macrocode}
% \lverb|On boucle vers \XINT_smalldiv_d.|
% \begin{macrocode}
\def\XINT_smalldiv_k #1!#2!#3.#4!%
{%
\expandafter\XINT_smalldiv_d\the\numexpr #2-#1*#4!#3.#4!%
}%
% \end{macrocode}
% \lverb|Cette routine fait la division euclidienne d'un nombre de seize
% chiffres par #1 = C = diviseur sur huit chiffres >= 10^7, avec #2 = sa
% moitié utilisée dans \numexpr pour contrebalancer l'arrondi
% (ARRRRRRGGGGGHHHH) fait par /. Le nombre divisé XY = X*10^8+Y se présente
% sous la forme 1<8chiffres>!1<8chiffres>! avec plus significatif en premier.
%
% Seul le quotient est calculé, pas le reste. En effet la routine de division
% principale va utiliser ce quotient pour déterminer le "grand" reste, et le
% petit reste ici ne nous serait d'à peu près aucune utilité.
%
% ATTENTION UNIQUEMENT UTILISÉ POUR DES SITUATIONS OÙ IL EST GARANTI QUE X < C
% !! (et C au moins 10^7) le quotient euclidien de X*10^8+Y par C sera donc <
% 10^8. Il sera renvoyé sous la forme 1<8chiffres>.|
% \begin{macrocode}
\def\XINT_div_mini #1.#2!1#3!%
{%
\expandafter\XINT_div_mini_a\the\numexpr
\xint_c_xi_e_viii_mone+#3*\xint_c_x^viii/#1!#1.#2!#3!%
}%
% \end{macrocode}
% \lverb|Note (2015/10/08). Attention à la différence dans l'ordre des
% arguments avec ce que je vois en dans \XINT_smalldiv_f. Je ne me souviens
% plus du tout s'il y a une raison quelconque.|
% \begin{macrocode}
\def\XINT_div_mini_a 1#1#2#3#4#5#6!#7.#8!%
{%
\xint_gob_til_zero #1\XINT_div_mini_w 0%
\expandafter\XINT_div_mini_b
\the\numexpr\XINT_minimul_a #2#3#4#5.#6!#7!#2#3#4#5#6!#7.#8!%
}%
\def\XINT_div_mini_w 0%
\expandafter\XINT_div_mini_b\the\numexpr\XINT_minimul_a
9999.9999!#1!99999999!#2.#3!00000000!#4!%
{%
\xint_c_x^viii_mone+(#4+#3)/#2!%
}%
\def\XINT_div_mini_b 1#1!1#2!#3!#4!#5!#6!%
{%
\expandafter\XINT_div_mini_c
\the\numexpr 1#6-#1.#2!#5!#3!#4!%
}%
\def\XINT_div_mini_c 1#1#2.#3!#4!%
{%
\expandafter\XINT_div_mini_d
\the\numexpr #4-#3+#1-\xint_c_i.#2!%
}%
\def\XINT_div_mini_d #1.#2!#3!#4.#5!%
{%
\xint_c_x^viii_mone+#3+(#1#2+#5)/#4!%
}%
% \end{macrocode}
% \subsection{\csh{xintiDivRound}, \csh{xintiiDivRound}}
% \lverb|1.1, transferred from first release of bnumexpr. Rewritten for 1.2.|
% \begin{macrocode}
\def\xintiDivRound {\romannumeral0\xintidivround }%
\def\xintidivround #1%
{\expandafter\XINT_idivround\romannumeral0\xintnum{#1}\Z }%
\def\xintiiDivRound {\romannumeral0\xintiidivround }%
\def\xintiidivround #1{\expandafter\XINT_iidivround \romannumeral`&&@#1\Z }%
\def\XINT_idivround #1#2\Z #3%
{\expandafter\XINT_iidivround_a\expandafter #1%
\romannumeral0\xintnum{#3}\Z #2\Z }%
\def\XINT_iidivround #1#2\Z #3%
{\expandafter\XINT_iidivround_a\expandafter #1\romannumeral`&&@#3\Z #2\Z }%
\def\XINT_iidivround_a #1#2% #1 de A, #2 de B.
{%
\if0#2\xint_dothis\XINT_iidivround_divbyzero\fi
\if0#1\xint_dothis\XINT_iidivround_aiszero\fi
\if-#2\xint_dothis{\XINT_iidivround_bneg #1}\fi
\xint_orthat{\XINT_iidivround_bpos #1#2}%
}%
\def\XINT_iidivround_divbyzero #1\Z #2\Z {\xintError:DivisionByZero\space 0}%
\def\XINT_iidivround_aiszero #1\Z #2\Z { 0}%
\def\XINT_iidivround_bpos #1%
{%
\xint_UDsignfork
#1{\xintiiopp\XINT_iidivround_pos {}}%
-{\XINT_iidivround_pos #1}%
\krof
}%
\def\XINT_iidivround_bneg #1%
{%
\xint_UDsignfork
#1{\XINT_iidivround_pos {}}%
-{\xintiiopp\XINT_iidivround_pos #1}%
\krof
}%
\def\XINT_iidivround_pos #1#2\Z #3\Z
{%
\expandafter\XINT_iidivround_pos_a
\romannumeral0\XINT_div_prepare {#2}{#1#30}%
}%
% \end{macrocode}
% \lverb|The 1.2c interface to addition changed, the \Z's are now 1\Z's here.
% Will have to come back here for improvements. The 1\Z!1\Z!1\Z!1\Z!\W are for
% the addition which is done if rounding up.|
% \begin{macrocode}
\def\XINT_iidivround_pos_a #1#2%
{%
\expandafter\XINT_iidivround_pos_b
\romannumeral0\expandafter\XINT_sepandrev
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678\XINT_rsepbyviii_end_B 2345678\relax XX%
\R.\R.\R.\R.\R.\R.\R.\R.\W
1\Z!1\Z!1\Z!1\Z!\W\R
}%
\def\XINT_iidivround_pos_b 1#1#2#3#4#5#6#7#8!1#9%
{%
\xint_gob_til_Z #9\XINT_iidivround_small\Z
\ifnum #8>\xint_c_iv
\expandafter\XINT_iidivround_pos_up
\else \expandafter\XINT_iidivround_pos_finish
\fi
1#1#2#3#4#5#6#70!1#9%
}%
\def\XINT_iidivround_pos_up
{%
\expandafter\XINT_iidivround_pos_finish
\the\numexpr\XINT_add_a\xint_c_ii 100000010!1\Z!1\Z!1\Z!1\Z!\W
}%
\def\XINT_iidivround_pos_finish #10!#21\Z!#3\R
{%
\expandafter\XINT_cuz_small\romannumeral0\XINT_unrevbyviii {}%
#1!#21\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_iidivround_small\Z\ifnum #1>#2\fi 1#30!#4\W\R
{%
\ifnum #1>\xint_c_iv
\expandafter\XINT_iidivround_small_up
\else \expandafter\XINT_iidivround_small_trunc
\fi {#3}%
}%
\edef\XINT_iidivround_small_up #1%
{\noexpand\expandafter\space\noexpand\the\numexpr #1+\xint_c_i\relax }%
\edef\XINT_iidivround_small_trunc #1%
{\noexpand\expandafter\space\noexpand\the\numexpr #1\relax }%
% \end{macrocode}
% \subsection{\csh{xintiDivTrunc}, \csh{xintiiDivTrunc}}
% \begin{macrocode}
\def\xintiDivTrunc {\romannumeral0\xintidivtrunc }%
\def\xintidivtrunc #1{\expandafter\XINT_iidivtrunc\romannumeral0\xintnum{#1}\Z }%
\def\xintiiDivTrunc {\romannumeral0\xintiidivtrunc }%
\def\xintiidivtrunc #1{\expandafter\XINT_iidivtrunc \romannumeral`&&@#1\Z }%
\def\XINT_iidivtrunc #1#2\Z #3{\expandafter\XINT_iidivtrunc_a\expandafter #1%
\romannumeral`&&@#3\Z #2\Z }%
\def\XINT_iidivtrunc_a #1#2% #1 de A, #2 de B.
{%
\if0#2\xint_dothis\XINT_iidivround_divbyzero\fi
\if0#1\xint_dothis\XINT_iidivround_aiszero\fi
\if-#2\xint_dothis{\XINT_iidivtrunc_bneg #1}\fi
\xint_orthat{\XINT_iidivtrunc_bpos #1#2}%
}%
\def\XINT_iidivtrunc_bpos #1%
{%
\xint_UDsignfork
#1{\xintiiopp\XINT_iidivtrunc_pos {}}%
-{\XINT_iidivtrunc_pos #1}%
\krof
}%
\def\XINT_iidivtrunc_bneg #1%
{%
\xint_UDsignfork
#1{\XINT_iidivtrunc_pos {}}%
-{\xintiiopp\XINT_iidivtrunc_pos #1}%
\krof
}%
\def\XINT_iidivtrunc_pos #1#2\Z #3\Z%
{\expandafter\xint_firstoftwo_thenstop
\romannumeral0\XINT_div_prepare {#2}{#1#3}}%
% \end{macrocode}
% \subsection{\csh{xintiMod}, \csh{xintiiMod}}
% \begin{macrocode}
\def\xintiMod {\romannumeral0\xintimod }%
\def\xintimod #1{\expandafter\XINT_iimod\romannumeral0\xintnum{#1}\Z }%
\def\xintiiMod {\romannumeral0\xintiimod }%
\def\xintiimod #1{\expandafter\XINT_iimod \romannumeral`&&@#1\Z }%
\def\XINT_iimod #1#2\Z #3{\expandafter\XINT_iimod_a\expandafter #1%
\romannumeral`&&@#3\Z #2\Z }%
\def\XINT_iimod_a #1#2% #1 de A, #2 de B.
{%
\if0#2\xint_dothis\XINT_iidivround_divbyzero\fi
\if0#1\xint_dothis\XINT_iidivround_aiszero\fi
\if-#2\xint_dothis{\XINT_iimod_bneg #1}\fi
\xint_orthat{\XINT_iimod_bpos #1#2}%
}%
\def\XINT_iimod_bpos #1%
{%
\xint_UDsignfork
#1{\xintiiopp\XINT_iimod_pos {}}%
-{\XINT_iimod_pos #1}%
\krof
}%
\def\XINT_iimod_bneg #1%
{%
\xint_UDsignfork
#1{\xintiiopp\XINT_iimod_pos {}}%
-{\XINT_iimod_pos #1}%
\krof
}%
\def\XINT_iimod_pos #1#2\Z #3\Z%
{\expandafter\xint_secondoftwo_thenstop\romannumeral0\XINT_div_prepare
{#2}{#1#3}}%
% \end{macrocode}
% \subsection{``Load \xintfracnameimp'' macros}
% \lverb|Originally was used in \xintiiexpr. Transferred from xintfrac for 1.1.|
% \begin{macrocode}
\catcode`! 11
\def\xintAbs {\Did_you_mean_iiAbs?or_load_xintfrac!}%
\def\xintOpp {\Did_you_mean_iiOpp?or_load_xintfrac!}%
\def\xintAdd {\Did_you_mean_iiAdd?or_load_xintfrac!}%
\def\xintSub {\Did_you_mean_iiSub?or_load_xintfrac!}%
\def\xintMul {\Did_you_mean_iiMul?or_load_xintfrac!}%
\def\xintPow {\Did_you_mean_iiPow?or_load_xintfrac!}%
\def\xintSqr {\Did_you_mean_iiSqr?or_load_xintfrac!}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintcore}
%
%\gardesactifs
%\let</xintcore>\relax
%\let<*xint>\gardesinactifs
%</xintcore>^^A---------------------------------------------------
%<*xint>^^A-------------------------------------------------------
% \clearpage
% \section{Package \xintnameimp implementation}
% \label{sec:xintimp}
%
% \localtableofcontents
%
% With release |1.1| the core arithmetic routines |\xintiiAdd|,
% |\xintiiSub|, |\xintiiMul|, |\xintiiQuo|, |\xintiiPow| were separated to be
% the main component of the then new
% \xintcorenameimp.
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xint.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintcore.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xint}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintcore.sty
\ifx\w\relax % but xintkernel.sty not yet loaded.
\def\z{\endgroup\input xintcore.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintcore.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintcore}}%
\fi
\else
\aftergroup\endinput % xint already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty (loaded by xintcore.sty)
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xint}%
[2016/11/20 1.2h Expandable operations on big integers (JFB)]%
% \end{macrocode}
% \subsection{More token management}
% \begin{macrocode}
\long\def\xint_firstofthree #1#2#3{#1}%
\long\def\xint_secondofthree #1#2#3{#2}%
\long\def\xint_thirdofthree #1#2#3{#3}%
\long\def\xint_firstofthree_thenstop #1#2#3{ #1}% 1.09i
\long\def\xint_secondofthree_thenstop #1#2#3{ #2}%
\long\def\xint_thirdofthree_thenstop #1#2#3{ #3}%
\edef\xint_cleanupzeros_andstop #1#2#3#4%
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4\relax
}%
% \end{macrocode}
% \subsection{\csh{xintSgnFork}}
% \lverb|Expandable three-way fork added in 1.07. The argument #1 must expand
% to non-self-ending -1,0 or 1. 1.09i with _thenstop.|
% \begin{macrocode}
\def\xintSgnFork {\romannumeral0\xintsgnfork }%
\def\xintsgnfork #1%
{%
\ifcase #1 \expandafter\xint_secondofthree_thenstop
\or\expandafter\xint_thirdofthree_thenstop
\else\expandafter\xint_firstofthree_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintIsOne}, \csh{xintiiIsOne}}
% \lverb|Added in 1.03. 1.09a defines \xintIsOne. 1.1a adds \xintiiIsOne.
%
% \XINT_isOne rewritten for 1.2g. Works with expanded strict integers,
% positive or negative.|
% \begin{macrocode}
\def\xintiiIsOne {\romannumeral0\xintiiisone }%
\def\xintiiisone #1{\expandafter\XINT_isone\romannumeral`&&@#1XY}%
\def\xintIsOne {\romannumeral0\xintisone }%
\def\xintisone #1{\expandafter\XINT_isone\romannumeral0\xintnum{#1}XY}%
\def\XINT_isOne #1{\romannumeral0\XINT_isone #1XY}%
\def\XINT_isone #1#2#3Y%
{%
\unless\if#2X\xint_dothis{ 0}\fi
\unless\if#11\xint_dothis{ 0}\fi
\xint_orthat{ 1}%
}%
% \end{macrocode}
% \subsection{\csh{xintRev}}
% \lverb|&
% \xintRev: expands fully its argument \romannumeral-`0, and checks the sign.
% However this last aspect does not appear like a very useful thing. And despite
% the fact that a special check is made for a sign, actually the input is not
% given to \xintnum, contrarily to \xintLen. This is all a bit incoherent.
% Should be fixed.
%
% 1.2 has \xintReverseDigits and I thus make \xintRev an alias. Remarks above
% not addressed.|
% \begin{macrocode}
\let\xintRev\xintReverseDigits
% \end{macrocode}
% \subsection{\csh{xintLen}}
% \lverb|\xintLen is ONLY for (possibly long) integers. Gets extended to
% fractions by xintfrac.sty|
% \begin{macrocode}
\def\xintLen {\romannumeral0\xintlen }%
\def\xintlen #1%
{%
\expandafter\XINT_len_fork
\romannumeral0\xintnum{#1}\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_Len #1% variant which does not expand via \xintnum.
{%
\romannumeral0\XINT_len_fork
#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye
}%
\def\XINT_len_fork #1%
{%
\expandafter\XINT_length_loop
\xint_UDsignfork
#1{0.}%
-{0.#1}%
\krof
}%
% \end{macrocode}
% \subsection{\csh{xintBool}, \csh{xintToggle}}
% \lverb|1.09c|
% \begin{macrocode}
\def\xintBool #1{\romannumeral`&&@%
\csname if#1\endcsname\expandafter1\else\expandafter0\fi }%
\def\xintToggle #1{\romannumeral`&&@\iftoggle{#1}{1}{0}}%
% \end{macrocode}
% \subsection{\csh{xintifSgn}, \csh{xintiiifSgn}}
% \lverb|Expandable three-way fork added in 1.09a. Branches expandably
% depending on whether <0, =0, >0. Choice of branch guaranteed in two steps.
%
% 1.09i has \xint_firstofthreeafterstop (now _thenstop) etc for faster
% expansion.
%
% 1.1 adds \xintiiifSgn for optimization in xintexpr-essions. Should I move
% them to xintcore? (for bnumexpr)|
% \begin{macrocode}
\def\xintifSgn {\romannumeral0\xintifsgn }%
\def\xintifsgn #1%
{%
\ifcase \xintSgn{#1}
\expandafter\xint_secondofthree_thenstop
\or\expandafter\xint_thirdofthree_thenstop
\else\expandafter\xint_firstofthree_thenstop
\fi
}%
\def\xintiiifSgn {\romannumeral0\xintiiifsgn }%
\def\xintiiifsgn #1%
{%
\ifcase \xintiiSgn{#1}
\expandafter\xint_secondofthree_thenstop
\or\expandafter\xint_thirdofthree_thenstop
\else\expandafter\xint_firstofthree_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifZero}, \csh{xintifNotZero}, \csh{xintiiifZero}, \csh{xintiiifNotZero}}
% \lverb|Expandable two-way fork added in 1.09a. Branches expandably depending on
% whether the argument is zero (branch A) or not (branch B). 1.09i restyling. By
% the way it appears (not thoroughly tested, though) that \if tests are faster
% than \ifnum tests. 1.1 adds ii versions.|
% \begin{macrocode}
\def\xintifZero {\romannumeral0\xintifzero }%
\def\xintifzero #1%
{%
\if0\xintSgn{#1}%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintifNotZero {\romannumeral0\xintifnotzero }%
\def\xintifnotzero #1%
{%
\if0\xintSgn{#1}%
\expandafter\xint_secondoftwo_thenstop
\else
\expandafter\xint_firstoftwo_thenstop
\fi
}%
\def\xintiiifZero {\romannumeral0\xintiiifzero }%
\def\xintiiifzero #1%
{%
\if0\xintiiSgn{#1}%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintiiifNotZero {\romannumeral0\xintiiifnotzero }%
\def\xintiiifnotzero #1%
{%
\if0\xintiiSgn{#1}%
\expandafter\xint_secondoftwo_thenstop
\else
\expandafter\xint_firstoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifOne},\csh{xintiiifOne}}
% \lverb|added in 1.09i. 1.1a adds \xintiiifOne.|
% \begin{macrocode}
\def\xintiiifOne {\romannumeral0\xintiiifone }%
\def\xintiiifone #1%
{%
\if1\xintiiIsOne{#1}%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintifOne {\romannumeral0\xintifone }%
\def\xintifone #1%
{%
\if1\xintIsOne{#1}%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifTrueAelseB}, \csh{xintifFalseAelseB}}
% \lverb|1.09i. Warning, \xintifTrueFalse, \xintifTrue deprecated, to be
% removed|
% \begin{macrocode}
\let\xintifTrueAelseB\xintifNotZero
\let\xintifFalseAelseB\xintifZero
\let\xintifTrue\xintifNotZero
\let\xintifTrueFalse\xintifNotZero
% \end{macrocode}
% \subsection{\csh{xintifCmp}, \csh{xintiiifCmp}}
% \lverb|1.09e
% \xintifCmp {n}{m}{if n<m}{if n=m}{if n>m}. 1.1a adds ii variant|
% \begin{macrocode}
\def\xintifCmp {\romannumeral0\xintifcmp }%
\def\xintifcmp #1#2%
{%
\ifcase\xintCmp {#1}{#2}
\expandafter\xint_secondofthree_thenstop
\or\expandafter\xint_thirdofthree_thenstop
\else\expandafter\xint_firstofthree_thenstop
\fi
}%
\def\xintiiifCmp {\romannumeral0\xintiiifcmp }%
\def\xintiiifcmp #1#2%
{%
\ifcase\xintiiCmp {#1}{#2}
\expandafter\xint_secondofthree_thenstop
\or\expandafter\xint_thirdofthree_thenstop
\else\expandafter\xint_firstofthree_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifEq}, \csh{xintiiifEq}}
% \lverb|1.09a \xintifEq {n}{m}{YES if n=m}{NO if n<>m}. 1.1a adds ii variant|
% \begin{macrocode}
\def\xintifEq {\romannumeral0\xintifeq }%
\def\xintifeq #1#2%
{%
\if0\xintCmp{#1}{#2}%
\expandafter\xint_firstoftwo_thenstop
\else\expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintiiifEq {\romannumeral0\xintiiifeq }%
\def\xintiiifeq #1#2%
{%
\if0\xintiiCmp{#1}{#2}%
\expandafter\xint_firstoftwo_thenstop
\else\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifGt}, \csh{xintiiifGt}}
% \lverb|1.09a \xintifGt {n}{m}{YES if n>m}{NO if n<=m}. 1.1a adds ii variant|
% \begin{macrocode}
\def\xintifGt {\romannumeral0\xintifgt }%
\def\xintifgt #1#2%
{%
\if1\xintCmp{#1}{#2}%
\expandafter\xint_firstoftwo_thenstop
\else\expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintiiifGt {\romannumeral0\xintiiifgt }%
\def\xintiiifgt #1#2%
{%
\if1\xintiiCmp{#1}{#2}%
\expandafter\xint_firstoftwo_thenstop
\else\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifLt}, \csh{xintiiifLt}}
% \lverb|1.09a \xintifLt {n}{m}{YES if n<m}{NO if n>=m}. Restyled in 1.09i.
% 1.1a adds ii variant|
% \begin{macrocode}
\def\xintifLt {\romannumeral0\xintiflt }%
\def\xintiflt #1#2%
{%
\ifnum\xintCmp{#1}{#2}<\xint_c_
\expandafter\xint_firstoftwo_thenstop
\else \expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintiiifLt {\romannumeral0\xintiiiflt }%
\def\xintiiiflt #1#2%
{%
\ifnum\xintiiCmp{#1}{#2}<\xint_c_
\expandafter\xint_firstoftwo_thenstop
\else \expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintifOdd}, \csh{xintiiifOdd}}
% \lverb|1.09e. Restyled in 1.09i. 1.1a adds \xintiiifOdd.|
% \begin{macrocode}
\def\xintiiifOdd {\romannumeral0\xintiiifodd }%
\def\xintiiifodd #1%
{%
\if\xintiiOdd{#1}1%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
\def\xintifOdd {\romannumeral0\xintifodd }%
\def\xintifodd #1%
{%
\if\xintOdd{#1}1%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintCmp}, \csh{xintiiCmp}}
% \lverb|Faster than doing the full subtraction.|
% \begin{macrocode}
\def\xintCmp {\romannumeral0\xintcmp }%
\def\xintcmp #1{\expandafter\XINT_icmp\romannumeral0\xintnum{#1}\Z }%
\def\xintiiCmp {\romannumeral0\xintiicmp }%
\def\xintiicmp #1{\expandafter\XINT_iicmp\romannumeral`&&@#1\Z }%
\def\XINT_iicmp #1#2\Z #3%
{%
\expandafter\XINT_cmp_nfork\expandafter #1\romannumeral`&&@#3\Z #2\Z
}%
\let\XINT_Cmp \xintiiCmp
\def\XINT_icmp #1#2\Z #3%
{%
\expandafter\XINT_cmp_nfork\expandafter #1\romannumeral0\xintnum{#3}\Z #2\Z
}%
\def\XINT_cmp_nfork #1#2%
{%
\xint_UDzerofork
#1\XINT_cmp_firstiszero
#2\XINT_cmp_secondiszero
0{}%
\krof
\xint_UDsignsfork
#1#2\XINT_cmp_minusminus
#1-\XINT_cmp_minusplus
#2-\XINT_cmp_plusminus
--\XINT_cmp_plusplus
\krof #1#2%
}%
\def\XINT_cmp_firstiszero #1\krof 0#2#3\Z #4\Z
{%
\xint_UDzerominusfork
#2-{ 0}%
0#2{ 1}%
0-{ -1}%
\krof
}%
\def\XINT_cmp_secondiszero #1\krof #20#3\Z #4\Z
{%
\xint_UDzerominusfork
#2-{ 0}%
0#2{ -1}%
0-{ 1}%
\krof
}%
\def\XINT_cmp_plusminus #1\Z #2\Z{ 1}%
\def\XINT_cmp_minusplus #1\Z #2\Z{ -1}%
\def\XINT_cmp_minusminus
--{\expandafter\XINT_opp\romannumeral0\XINT_cmp_plusplus {}{}}%
\def\XINT_cmp_plusplus #1#2#3\Z
{%
\expandafter\XINT_cmp_pp
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W
#2#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\X #1%
}%
\def\XINT_cmp_pp #1.#2\X #3\Z
{%
\expandafter\XINT_cmp_checklengths
\the\numexpr #1\expandafter.%
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W
#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax \xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\Z!\Z!\Z!\Z!\Z!\W #2\Z!\Z!\Z!\Z!\Z!\W
}%
\def\XINT_cmp_checklengths #1.#2.%
{%
\ifnum #1=#2
\expandafter\xint_firstoftwo
\else
\expandafter\xint_secondoftwo
\fi
\XINT_cmp_aa {\XINT_cmp_distinctlengths {#1}{#2}}%
}%
\def\XINT_cmp_distinctlengths #1#2#3\W #4\W
{%
\ifnum #1>#2
\expandafter\xint_firstoftwo
\else
\expandafter\xint_secondoftwo
\fi
{ -1}{ 1}%
}%
\def\XINT_cmp_aa {\expandafter\XINT_cmp_w\the\numexpr\XINT_cmp_a \xint_c_i }%
\def\XINT_cmp_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!%
{%
\XINT_cmp_b #1!#6!#2!#7!#3!#8!#4!#9!#5\W
}%
\def\XINT_cmp_b #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_cmp_bi \Z
\expandafter\XINT_cmp_c\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_cmp_c 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_cmp_d #1%
}%
\def\XINT_cmp_d #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_cmp_di \Z
\expandafter\XINT_cmp_e\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_cmp_e 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_cmp_f #1%
}%
\def\XINT_cmp_f #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_cmp_fi \Z
\expandafter\XINT_cmp_g\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_cmp_g 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_cmp_h #1%
}%
\def\XINT_cmp_h #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_cmp_hi \Z
\expandafter\XINT_cmp_i\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_cmp_i 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_cmp_a #1%
}%
\def\XINT_cmp_bi\Z
\expandafter\XINT_cmp_c\the\numexpr#1+1#2-#3.#4!#5!#6!#7!#8!#9!\Z !\W
{%
\XINT_cmp_k #1#2!#5!#7!#9!%
}%
\def\XINT_cmp_di\Z
\expandafter\XINT_cmp_e\the\numexpr#1+1#2-#3.#4!#5!#6!#7!#8\W
{%
\XINT_cmp_k #1#2!#5!#7!%
}%
\def\XINT_cmp_fi\Z
\expandafter\XINT_cmp_g\the\numexpr#1+1#2-#3.#4!#5!#6\W
{%
\XINT_cmp_k #1#2!#5!%
}%
\def\XINT_cmp_hi\Z
\expandafter\XINT_cmp_i\the\numexpr#1+1#2-#3.#4\W
{%
\XINT_cmp_k #1#2!%
}%
\def\XINT_cmp_k #1#2\W
{%
\xint_UDzerofork
#1{-1\relax \XINT_cmp_greater}%
0{-1\relax \XINT_cmp_lessorequal}%
\krof
}%
\def\XINT_cmp_w #1-1#2{#2#11\Z!\W}%
\def\XINT_cmp_greater #1\Z!\W{ 1}%
\def\XINT_cmp_lessorequal 1#1!%
{\xint_gob_til_Z #1\XINT_cmp_equal\Z
\xint_gob_til_eightzeroes #1\XINT_cmp_continue 00000000%
\XINT_cmp_less }%
\def\XINT_cmp_less #1\W { -1}%
\def\XINT_cmp_continue 00000000\XINT_cmp_less {\XINT_cmp_lessorequal }%
\def\XINT_cmp_equal\Z\xint_gob_til_eightzeroes\Z\XINT_cmp_continue
00000000\XINT_cmp_less\W { 0}%
% \end{macrocode}
% \subsection{\csh{xintEq}, \csh{xintGt}, \csh{xintLt}}
% \lverb|1.09a.|
% \begin{macrocode}
\def\xintEq {\romannumeral0\xinteq }\def\xinteq #1#2{\xintifeq{#1}{#2}{1}{0}}%
\def\xintGt {\romannumeral0\xintgt }\def\xintgt #1#2{\xintifgt{#1}{#2}{1}{0}}%
\def\xintLt {\romannumeral0\xintlt }\def\xintlt #1#2{\xintiflt{#1}{#2}{1}{0}}%
% \end{macrocode}
% \subsection{\csh{xintNeq}, \csh{xintGtorEq}, \csh{xintLtorEq}}
% \lverb|1.1. Pour xintexpr. No lowercase macros|
% \begin{macrocode}
\def\xintLtorEq #1#2{\romannumeral0\xintifgt {#1}{#2}{0}{1}}%
\def\xintGtorEq #1#2{\romannumeral0\xintiflt {#1}{#2}{0}{1}}%
\def\xintNeq #1#2{\romannumeral0\xintifeq {#1}{#2}{0}{1}}%
% \end{macrocode}
% \subsection{\csh{xintiiEq}, \csh{xintiiGt}, \csh{xintiiLt}}
% \lverb|1.1a Pour \xintiiexpr. No lowercase macros.|
% \begin{macrocode}
\def\xintiiEq #1#2{\romannumeral0\xintiiifeq{#1}{#2}{1}{0}}%
\def\xintiiGt #1#2{\romannumeral0\xintiiifgt{#1}{#2}{1}{0}}%
\def\xintiiLt #1#2{\romannumeral0\xintiiiflt{#1}{#2}{1}{0}}%
% \end{macrocode}
% \subsection{\csh{xintiiNeq}, \csh{xintiiGtorEq}, \csh{xintiiLtorEq}}
% \lverb|1.1a. Pour \xintiiexpr. No lowercase macros.|
% \begin{macrocode}
\def\xintiiLtorEq #1#2{\romannumeral0\xintiiifgt {#1}{#2}{0}{1}}%
\def\xintiiGtorEq #1#2{\romannumeral0\xintiiiflt {#1}{#2}{0}{1}}%
\def\xintiiNeq #1#2{\romannumeral0\xintiiifeq {#1}{#2}{0}{1}}%
% \end{macrocode}
% \subsection{\csh{xintIsZero}, \csh{xintIsNotZero}, \csh{xintiiIsZero},
% \csh{xintiiIsNotZero}}
% \lverb|1.09a. restyled in 1.09i. 1.1 adds \xintiiIsZero, etc... for
% optimization in \xintexpr|
% \begin{macrocode}
\def\xintIsZero {\romannumeral0\xintiszero }%
\def\xintiszero #1{\if0\xintSgn{#1}\xint_afterfi{ 1}\else\xint_afterfi{ 0}\fi}%
\def\xintIsNotZero {\romannumeral0\xintisnotzero }%
\def\xintisnotzero
#1{\if0\xintSgn{#1}\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi}%
\def\xintiiIsZero {\romannumeral0\xintiiiszero }%
\def\xintiiiszero #1{\if0\xintiiSgn{#1}\xint_afterfi{ 1}\else\xint_afterfi{ 0}\fi}%
\def\xintiiIsNotZero {\romannumeral0\xintiiisnotzero }%
\def\xintiiisnotzero
#1{\if0\xintiiSgn{#1}\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi}%
% \end{macrocode}
% \subsection{\csh{xintIsTrue}, \csh{xintNot}, \csh{xintIsFalse}}
% \lverb|1.09c|
% \begin{macrocode}
\let\xintIsTrue\xintIsNotZero
\let\xintNot\xintIsZero
\let\xintIsFalse\xintIsZero
% \end{macrocode}
% \subsection{\csh{xintAND}, \csh{xintOR}, \csh{xintXOR}}
% \lverb|1.09a. Embarrasing bugs in \xintAND and \xintOR which inserted a space
% token corrected in 1.09i. \xintxor restyled with \if (faster) in 1.09i|
% \begin{macrocode}
\def\xintAND {\romannumeral0\xintand }%
\def\xintand #1#2{\if0\xintSgn{#1}\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo\fi
{ 0}{\xintisnotzero{#2}}}%
\def\xintOR {\romannumeral0\xintor }%
\def\xintor #1#2{\if0\xintSgn{#1}\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo\fi
{\xintisnotzero{#2}}{ 1}}%
\def\xintXOR {\romannumeral0\xintxor }%
\def\xintxor #1#2{\if\xintIsZero{#1}\xintIsZero{#2}%
\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi }%
% \end{macrocode}
% \subsection{\csh{xintANDof}}
% \lverb|New with 1.09a. \xintANDof works also with an empty list.|
% \begin{macrocode}
\def\xintANDof {\romannumeral0\xintandof }%
\def\xintandof #1{\expandafter\XINT_andof_a\romannumeral`&&@#1\relax }%
\def\XINT_andof_a #1{\expandafter\XINT_andof_b\romannumeral`&&@#1\Z }%
\def\XINT_andof_b #1%
{\xint_gob_til_relax #1\XINT_andof_e\relax\XINT_andof_c #1}%
\def\XINT_andof_c #1\Z
{\xintifTrueAelseB {#1}{\XINT_andof_a}{\XINT_andof_no}}%
\def\XINT_andof_no #1\relax { 0}%
\def\XINT_andof_e #1\Z { 1}%
% \end{macrocode}
% \subsection{\csh{xintORof}}
% \lverb|New with 1.09a. Works also with an empty list.|
% \begin{macrocode}
\def\xintORof {\romannumeral0\xintorof }%
\def\xintorof #1{\expandafter\XINT_orof_a\romannumeral`&&@#1\relax }%
\def\XINT_orof_a #1{\expandafter\XINT_orof_b\romannumeral`&&@#1\Z }%
\def\XINT_orof_b #1%
{\xint_gob_til_relax #1\XINT_orof_e\relax\XINT_orof_c #1}%
\def\XINT_orof_c #1\Z
{\xintifTrueAelseB {#1}{\XINT_orof_yes}{\XINT_orof_a}}%
\def\XINT_orof_yes #1\relax { 1}%
\def\XINT_orof_e #1\Z { 0}%
% \end{macrocode}
% \subsection{\csh{xintXORof}}
% \lverb|New with 1.09a. Works with an empty list, too. \XINT_xorof_c more
% efficient in 1.09i|
% \begin{macrocode}
\def\xintXORof {\romannumeral0\xintxorof }%
\def\xintxorof #1{\expandafter\XINT_xorof_a\expandafter
0\romannumeral`&&@#1\relax }%
\def\XINT_xorof_a #1#2{\expandafter\XINT_xorof_b\romannumeral`&&@#2\Z #1}%
\def\XINT_xorof_b #1%
{\xint_gob_til_relax #1\XINT_xorof_e\relax\XINT_xorof_c #1}%
\def\XINT_xorof_c #1\Z #2%
{\xintifTrueAelseB {#1}{\if #20\xint_afterfi{\XINT_xorof_a 1}%
\else\xint_afterfi{\XINT_xorof_a 0}\fi}%
{\XINT_xorof_a #2}%
}%
\def\XINT_xorof_e #1\Z #2{ #2}%
% \end{macrocode}
% \subsection{\csh{xintGeq}, \csh{xintiiGeq}}
% \lverb|&
% PLUS GRAND OU ÉGAL
% attention compare les **valeurs absolues**|
% \begin{macrocode}
\def\xintGeq {\romannumeral0\xintgeq }%
\def\xintgeq #1{\expandafter\XINT_geq\romannumeral0\xintnum{#1}\Z }%
\def\xintiiGeq {\romannumeral0\xintiigeq }%
\def\xintiigeq #1{\expandafter\XINT_iigeq\romannumeral`&&@#1\Z }%
\def\XINT_iigeq #1#2\Z #3%
{%
\expandafter\XINT_geq_fork\expandafter #1\romannumeral`&&@#3\Z #2\Z
}%
\let\XINT_geq_pre \xintiigeq % TEMPORAIRE (oui, mais depuis quand ?)
\let\XINT_Geq \xintGeq % TEMPORAIRE ATTENTION FAIT xintNum (et alors?)
\def\XINT_geq #1#2\Z #3%
{%
\expandafter\XINT_geq_fork\expandafter #1\romannumeral0\xintnum{#3}\Z #2\Z
}%
\def\XINT_geq_fork #1#2%
{%
\xint_UDzerofork
#1\XINT_geq_firstiszero
#2\XINT_geq_secondiszero
0{}%
\krof
\xint_UDsignsfork
#1#2\XINT_geq_minusminus
#1-\XINT_geq_minusplus
#2-\XINT_geq_plusminus
--\XINT_geq_plusplus
\krof #1#2%
}%
\def\XINT_geq_firstiszero #1\krof 0#2#3\Z #4\Z
{\xint_UDzerofork #2{ 1}0{ 0}\krof }%
\def\XINT_geq_secondiszero #1\krof #20#3\Z #4\Z { 1}%
\def\XINT_geq_plusminus #1-{\XINT_geq_plusplus #1{}}%
\def\XINT_geq_minusplus -#1{\XINT_geq_plusplus {}#1}%
\def\XINT_geq_minusminus --{\XINT_geq_plusplus {}{}}%
\def\XINT_geq_plusplus #1#2#3\Z #4\Z {\XINT_geq_pp #1#4\Z #2#3\Z }%
\def\XINT_geq_pp #1\Z
{%
\expandafter\XINT_geq_pp_a
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W
#1\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\X
}%
\def\XINT_geq_pp_a #1.#2\X #3\Z
{%
\expandafter\XINT_geq_checklengths
\the\numexpr #1\expandafter.%
\romannumeral0\expandafter\XINT_sepandrev_andcount
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W
#3\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678\relax \xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\Z!\Z!\Z!\Z!\Z!\W #2\Z!\Z!\Z!\Z!\Z!\W
}%
\def\XINT_geq_checklengths #1.#2.%
{%
\ifnum #1=#2
\expandafter\xint_firstoftwo
\else
\expandafter\xint_secondoftwo
\fi
\XINT_geq_aa {\XINT_geq_distinctlengths {#1}{#2}}%
}%
\def\XINT_geq_distinctlengths #1#2#3\W #4\W
{%
\ifnum #1>#2
\expandafter\xint_firstoftwo
\else
\expandafter\xint_secondoftwo
\fi
{ 1}{ 0}%
}%
\def\XINT_geq_aa {\expandafter\XINT_geq_w\the\numexpr\XINT_geq_a \xint_c_i }%
\def\XINT_geq_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!%
{%
\XINT_geq_b #1!#6!#2!#7!#3!#8!#4!#9!#5\W
}%
\def\XINT_geq_b #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_geq_bi \Z
\expandafter\XINT_geq_c\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_geq_c 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_geq_d #1%
}%
\def\XINT_geq_d #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_geq_di \Z
\expandafter\XINT_geq_e\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_geq_e 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_geq_f #1%
}%
\def\XINT_geq_f #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_geq_fi \Z
\expandafter\XINT_geq_g\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_geq_g 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_geq_h #1%
}%
\def\XINT_geq_h #1#2#3!#4!%
{%
\xint_gob_til_Z #2\XINT_geq_hi \Z
\expandafter\XINT_geq_i\the\numexpr#1+1#4-#3-\xint_c_i.%
}%
\def\XINT_geq_i 1#1#2.%
{%
1#2\expandafter!\the\numexpr\XINT_geq_a #1%
}%
\def\XINT_geq_bi\Z
\expandafter\XINT_geq_c\the\numexpr#1+1#2-#3.#4!#5!#6!#7!#8!#9!\Z !\W
{%
\XINT_geq_k #1#2!#5!#7!#9!%
}%
\def\XINT_geq_di\Z
\expandafter\XINT_geq_e\the\numexpr#1+1#2-#3.#4!#5!#6!#7!#8\W
{%
\XINT_geq_k #1#2!#5!#7!%
}%
\def\XINT_geq_fi\Z
\expandafter\XINT_geq_g\the\numexpr#1+1#2-#3.#4!#5!#6\W
{%
\XINT_geq_k #1#2!#5!%
}%
\def\XINT_geq_hi\Z
\expandafter\XINT_geq_i\the\numexpr#1+1#2-#3.#4\W
{%
\XINT_geq_k #1#2!%
}%
\def\XINT_geq_k #1#2\W
{%
\xint_UDzerofork
#1{-1\relax { 0}}%
0{-1\relax { 1}}%
\krof
}%
\def\XINT_geq_w #1-1#2{#2}%
% \end{macrocode}
% \subsection{\csh{xintiMax}, \csh{xintiiMax}}
% \lverb|&
% 1.2 REMOVES \xintMax, \xintMin, \xintMaxof, \xintMinof.|
% \begin{macrocode}
\def\xintiMax {\romannumeral0\xintimax }%
\def\xintimax #1%
{%
\expandafter\xint_max\expandafter {\romannumeral0\xintnum{#1}}%
}%
\def\xint_max #1#2%
{%
\expandafter\XINT_max_pre\expandafter {\romannumeral0\xintnum{#2}}{#1}%
}%
\def\xintiiMax {\romannumeral0\xintiimax }%
\def\xintiimax #1%
{%
\expandafter\xint_iimax\expandafter {\romannumeral`&&@#1}%
}%
\def\xint_iimax #1#2%
{%
\expandafter\XINT_max_pre\expandafter {\romannumeral`&&@#2}{#1}%
}%
\def\XINT_max_pre #1#2{\XINT_max_fork #1\Z #2\Z {#2}{#1}}%
\def\XINT_Max #1#2{\romannumeral0\XINT_max_fork #2\Z #1\Z {#1}{#2}}%
% \end{macrocode}
% \lverb|&
% #3#4 vient du *premier*,
% #1#2 vient du *second*|
% \begin{macrocode}
\def\XINT_max_fork #1#2\Z #3#4\Z
{%
\xint_UDsignsfork
#1#3\XINT_max_minusminus % A < 0, B < 0
#1-\XINT_max_minusplus % B < 0, A >= 0
#3-\XINT_max_plusminus % A < 0, B >= 0
--{\xint_UDzerosfork
#1#3\XINT_max_zerozero % A = B = 0
#10\XINT_max_zeroplus % B = 0, A > 0
#30\XINT_max_pluszero % A = 0, B > 0
00\XINT_max_plusplus % A, B > 0
\krof }%
\krof
{#2}{#4}#1#3%
}%
% \end{macrocode}
% \lverb|&
% A = #4#2, B = #3#1|
% \begin{macrocode}
\def\XINT_max_zerozero #1#2#3#4{\xint_firstoftwo_thenstop }%
\def\XINT_max_zeroplus #1#2#3#4{\xint_firstoftwo_thenstop }%
\def\XINT_max_pluszero #1#2#3#4{\xint_secondoftwo_thenstop }%
\def\XINT_max_minusplus #1#2#3#4{\xint_firstoftwo_thenstop }%
\def\XINT_max_plusminus #1#2#3#4{\xint_secondoftwo_thenstop }%
\def\XINT_max_plusplus #1#2#3#4%
{%
\ifodd\XINT_Geq {#4#2}{#3#1}
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \lverb+#3=-, #4=-, #1 = |B| = -B, #2 = |A| = -A+
% \begin{macrocode}
\def\XINT_max_minusminus #1#2#3#4%
{%
\ifodd\XINT_Geq {#1}{#2}
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintiMaxof}, \csh{xintiiMaxof}}
% \lverb|New with 1.09a. 1.2 has NO MORE \xintMaxof, requires \xintfracname.
% 1.2a adds \xintiiMaxof, as \xintiiMaxof:csv is not public.|
% \begin{macrocode}
\def\xintiMaxof {\romannumeral0\xintimaxof }%
\def\xintimaxof #1{\expandafter\XINT_imaxof_a\romannumeral`&&@#1\relax }%
\def\XINT_imaxof_a #1{\expandafter\XINT_imaxof_b\romannumeral0\xintnum{#1}\Z }%
\def\XINT_imaxof_b #1\Z #2%
{\expandafter\XINT_imaxof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_imaxof_c #1%
{\xint_gob_til_relax #1\XINT_imaxof_e\relax\XINT_imaxof_d #1}%
\def\XINT_imaxof_d #1\Z
{\expandafter\XINT_imaxof_b\romannumeral0\xintimax {#1}}%
\def\XINT_imaxof_e #1\Z #2\Z { #2}%
\def\xintiiMaxof {\romannumeral0\xintiimaxof }%
\def\xintiimaxof #1{\expandafter\XINT_iimaxof_a\romannumeral`&&@#1\relax }%
\def\XINT_iimaxof_a #1{\expandafter\XINT_iimaxof_b\romannumeral`&&@#1\Z }%
\def\XINT_iimaxof_b #1\Z #2%
{\expandafter\XINT_iimaxof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_iimaxof_c #1%
{\xint_gob_til_relax #1\XINT_iimaxof_e\relax\XINT_iimaxof_d #1}%
\def\XINT_iimaxof_d #1\Z
{\expandafter\XINT_iimaxof_b\romannumeral0\xintiimax {#1}}%
\def\XINT_iimaxof_e #1\Z #2\Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintiMin}, \csh{xintiiMin}}
% \lverb|\xintnum added New with 1.09a. I add \xintiiMin in 1.1 and mark as
% deprecated \xintMin, renamed \xintiMin. \xintMin NOW REMOVED (1.2, as
% \xintMax, \xintMaxof), only provided by \xintfracnameimp.|
% \begin{macrocode}
\def\xintiMin {\romannumeral0\xintimin }%
\def\xintimin #1%
{%
\expandafter\xint_min\expandafter {\romannumeral0\xintnum{#1}}%
}%
\def\xint_min #1#2%
{%
\expandafter\XINT_min_pre\expandafter {\romannumeral0\xintnum{#2}}{#1}%
}%
\def\xintiiMin {\romannumeral0\xintiimin }%
\def\xintiimin #1%
{%
\expandafter\xint_iimin\expandafter {\romannumeral`&&@#1}%
}%
\def\xint_iimin #1#2%
{%
\expandafter\XINT_min_pre\expandafter {\romannumeral`&&@#2}{#1}%
}%
\def\XINT_min_pre #1#2{\XINT_min_fork #1\Z #2\Z {#2}{#1}}%
\def\XINT_Min #1#2{\romannumeral0\XINT_min_fork #2\Z #1\Z {#1}{#2}}%
% \end{macrocode}
% \lverb|&
% #3#4 vient du *premier*,
% #1#2 vient du *second*|
% \begin{macrocode}
\def\XINT_min_fork #1#2\Z #3#4\Z
{%
\xint_UDsignsfork
#1#3\XINT_min_minusminus % A < 0, B < 0
#1-\XINT_min_minusplus % B < 0, A >= 0
#3-\XINT_min_plusminus % A < 0, B >= 0
--{\xint_UDzerosfork
#1#3\XINT_min_zerozero % A = B = 0
#10\XINT_min_zeroplus % B = 0, A > 0
#30\XINT_min_pluszero % A = 0, B > 0
00\XINT_min_plusplus % A, B > 0
\krof }%
\krof
{#2}{#4}#1#3%
}%
% \end{macrocode}
% \lverb|&
% A = #4#2, B = #3#1|
% \begin{macrocode}
\def\XINT_min_zerozero #1#2#3#4{\xint_firstoftwo_thenstop }%
\def\XINT_min_zeroplus #1#2#3#4{\xint_secondoftwo_thenstop }%
\def\XINT_min_pluszero #1#2#3#4{\xint_firstoftwo_thenstop }%
\def\XINT_min_minusplus #1#2#3#4{\xint_secondoftwo_thenstop }%
\def\XINT_min_plusminus #1#2#3#4{\xint_firstoftwo_thenstop }%
\def\XINT_min_plusplus #1#2#3#4%
{%
\ifodd\XINT_Geq {#4#2}{#3#1}
\expandafter\xint_secondoftwo_thenstop
\else
\expandafter\xint_firstoftwo_thenstop
\fi
}%
% \end{macrocode}
% \lverb+#3=-, #4=-, #1 = |B| = -B, #2 = |A| = -A+
% \begin{macrocode}
\def\XINT_min_minusminus #1#2#3#4%
{%
\ifodd\XINT_Geq {#1}{#2}
\expandafter\xint_secondoftwo_thenstop
\else
\expandafter\xint_firstoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintiMinof}, \csh{xintiiMinof}}
% \lverb|1.09a. 1.2a adds \xintiiMinof which was lacking.|
% \begin{macrocode}
\def\xintiMinof {\romannumeral0\xintiminof }%
\def\xintiminof #1{\expandafter\XINT_iminof_a\romannumeral`&&@#1\relax }%
\def\XINT_iminof_a #1{\expandafter\XINT_iminof_b\romannumeral0\xintnum{#1}\Z }%
\def\XINT_iminof_b #1\Z #2%
{\expandafter\XINT_iminof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_iminof_c #1%
{\xint_gob_til_relax #1\XINT_iminof_e\relax\XINT_iminof_d #1}%
\def\XINT_iminof_d #1\Z
{\expandafter\XINT_iminof_b\romannumeral0\xintimin {#1}}%
\def\XINT_iminof_e #1\Z #2\Z { #2}%
\def\xintiiMinof {\romannumeral0\xintiiminof }%
\def\xintiiminof #1{\expandafter\XINT_iiminof_a\romannumeral`&&@#1\relax }%
\def\XINT_iiminof_a #1{\expandafter\XINT_iiminof_b\romannumeral`&&@#1\Z }%
\def\XINT_iiminof_b #1\Z #2%
{\expandafter\XINT_iiminof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_iiminof_c #1%
{\xint_gob_til_relax #1\XINT_iiminof_e\relax\XINT_iiminof_d #1}%
\def\XINT_iiminof_d #1\Z
{\expandafter\XINT_iiminof_b\romannumeral0\xintiimin {#1}}%
\def\XINT_iiminof_e #1\Z #2\Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintiiSum}}
% \lverb|\xintiiSum {{a}{b}...{z}}, \xintiiSumExpr {a}{b}...{z}\relax
%|
% \begin{macrocode}
\def\xintiiSum {\romannumeral0\xintiisum }%
\def\xintiisum #1{\xintiisumexpr #1\relax }%
\def\xintiiSumExpr {\romannumeral0\xintiisumexpr }%
\def\xintiisumexpr {\expandafter\XINT_sumexpr\romannumeral`&&@}%
\def\XINT_sumexpr {\XINT_sum_loop_a 0\Z }%
\def\XINT_sum_loop_a #1\Z #2%
{\expandafter\XINT_sum_loop_b \romannumeral`&&@#2\Z #1\Z \Z}%
\def\XINT_sum_loop_b #1%
{\xint_gob_til_relax #1\XINT_sum_finished\relax\XINT_sum_loop_c #1}%
\def\XINT_sum_loop_c
{\expandafter\XINT_sum_loop_a\romannumeral0\XINT_add_fork }%
\def\XINT_sum_finished #1\Z #2\Z \Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintiiPrd}}
% \lverb|\xintiiPrd {{a}...{z}}, \xintiiPrdExpr {a}...{z}\relax
%|
% \begin{macrocode}
\def\xintiiPrd {\romannumeral0\xintiiprd }%
\def\xintiiprd #1{\xintiiprdexpr #1\relax }%
\def\xintiiPrdExpr {\romannumeral0\xintiiprdexpr }%
\def\xintiiprdexpr {\expandafter\XINT_prdexpr\romannumeral`&&@}%
\def\XINT_prdexpr {\XINT_prod_loop_a 1\Z }%
\def\XINT_prod_loop_a #1\Z #2%
{\expandafter\XINT_prod_loop_b \romannumeral`&&@#2\Z #1\Z \Z}%
\def\XINT_prod_loop_b #1%
{\xint_gob_til_relax #1\XINT_prod_finished\relax\XINT_prod_loop_c #1}%
\def\XINT_prod_loop_c
{\expandafter\XINT_prod_loop_a\romannumeral0\XINT_mul_fork }%
\def\XINT_prod_finished\relax\XINT_prod_loop_c #1\Z #2\Z \Z { #2}%
% \end{macrocode}
% \lverb|&
% &
% -----------------------------------------------------------------$\
% -----------------------------------------------------------------$\
% DECIMAL OPERATIONS: FIRST DIGIT, LASTDIGIT, (<- moved to xintcore
% because xintiiLDg need by division macros)
% ODDNESS,
% MULTIPLICATION BY TEN, QUOTIENT BY TEN, QUOTIENT OR
% MULTIPLICATION BY POWER OF TEN, SPLIT OPERATION.|
% \subsection{\csh{xintMON}, \csh{xintMMON}, \csh{xintiiMON}, \csh{xintiiMMON}}
% \lverb|&
% MINUS ONE TO THE POWER N and (-1)^{N-1}|
% \begin{macrocode}
\def\xintiiMON {\romannumeral0\xintiimon }%
\def\xintiimon #1%
{%
\ifodd\xintiiLDg {#1}
\xint_afterfi{ -1}%
\else
\xint_afterfi{ 1}%
\fi
}%
\def\xintiiMMON {\romannumeral0\xintiimmon }%
\def\xintiimmon #1%
{%
\ifodd\xintiiLDg {#1}
\xint_afterfi{ 1}%
\else
\xint_afterfi{ -1}%
\fi
}%
\def\xintMON {\romannumeral0\xintmon }%
\def\xintmon #1%
{%
\ifodd\xintLDg {#1}
\xint_afterfi{ -1}%
\else
\xint_afterfi{ 1}%
\fi
}%
\def\xintMMON {\romannumeral0\xintmmon }%
\def\xintmmon #1%
{%
\ifodd\xintLDg {#1}
\xint_afterfi{ 1}%
\else
\xint_afterfi{ -1}%
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintOdd}, \csh{xintiiOdd}, \csh{xintEven}, \csh{xintiiEven}}
% \begin{macrocode}
\def\xintiiOdd {\romannumeral0\xintiiodd }%
\def\xintiiodd #1%
{%
\ifodd\xintiiLDg{#1}
\xint_afterfi{ 1}%
\else
\xint_afterfi{ 0}%
\fi
}%
\def\xintiiEven {\romannumeral0\xintiieven }%
\def\xintiieven #1%
{%
\ifodd\xintiiLDg{#1}
\xint_afterfi{ 0}%
\else
\xint_afterfi{ 1}%
\fi
}%
\def\xintOdd {\romannumeral0\xintodd }%
\def\xintodd #1%
{%
\ifodd\xintLDg{#1}
\xint_afterfi{ 1}%
\else
\xint_afterfi{ 0}%
\fi
}%
\def\xintEven {\romannumeral0\xinteven }%
\def\xinteven #1%
{%
\ifodd\xintLDg{#1}
\xint_afterfi{ 0}%
\else
\xint_afterfi{ 1}%
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintDSL}}
% \lverb|DECIMAL SHIFT LEFT (=MULTIPLICATION PAR 10)|
% \begin{macrocode}
\def\xintDSL {\romannumeral0\xintdsl }%
\def\xintdsl #1%
{%
\expandafter\XINT_dsl \romannumeral`&&@#1\Z
}%
\def\XINT_DSL #1{\romannumeral0\XINT_dsl #1\Z }%
\def\XINT_dsl #1%
{%
\xint_gob_til_zero #1\xint_dsl_zero 0\XINT_dsl_ #1%
}%
\def\xint_dsl_zero 0\XINT_dsl_ 0#1\Z { 0}%
\def\XINT_dsl_ #1\Z { #10}%
% \end{macrocode}
% \subsection{\csh{xintDSR}}
% \lverb|DECIMAL SHIFT RIGHT (=DIVISION PAR 10).
% |
% \begin{macrocode}
\def\xintDSR {\romannumeral0\xintdsr }%
\def\xintdsr #1%
{%
\expandafter\XINT_dsr_a\expandafter {\romannumeral`&&@#1}\W\Z
}%
\def\XINT_DSR #1{\romannumeral0\XINT_dsr_a {#1}\W\Z }%
\def\XINT_dsr_a
{%
\expandafter\XINT_dsr_b\romannumeral0\xintreverseorder
}%
\def\XINT_dsr_b #1#2#3\Z
{%
\xint_gob_til_W #2\xint_dsr_onedigit\W
\xint_gob_til_minus #2\xint_dsr_onedigit-%
\expandafter\XINT_dsr_removew
\romannumeral0\xintreverseorder {#2#3}%
}%
\def\xint_dsr_onedigit #1\xintreverseorder #2{ 0}%
\def\XINT_dsr_removew #1\W { }%
% \end{macrocode}
% \subsection{\csh{xintDSH}, \csh{xintDSHr}}
% \lverb+DECIMAL SHIFTS \xintDSH {x}{A}$\
% si x <= 0, fait A -> A.10^(|x|).
% si x > 0, et A >=0, fait A -> quo(A,10^(x))$\
% si x > 0, et A < 0, fait A -> -quo(-A,10^(x))$\
% (donc pour x > 0 c'est comme DSR itéré x fois)$\
% \xintDSHr donne le `reste' (si x<=0 donne zéro).
% +
% \begin{macrocode}
\def\xintDSHr {\romannumeral0\xintdshr }%
\def\xintdshr #1%
{%
\expandafter\XINT_dshr_checkxpositive \the\numexpr #1\relax\Z
}%
\def\XINT_dshr_checkxpositive #1%
{%
\xint_UDzerominusfork
0#1\XINT_dshr_xzeroorneg
#1-\XINT_dshr_xzeroorneg
0-\XINT_dshr_xpositive
\krof #1%
}%
\def\XINT_dshr_xzeroorneg #1\Z #2{ 0}%
\def\XINT_dshr_xpositive #1\Z
{%
\expandafter\xint_secondoftwo_thenstop\romannumeral0\xintdsx {#1}%
}%
\def\xintDSH {\romannumeral0\xintdsh }%
\def\xintdsh #1#2%
{%
\expandafter\xint_dsh\expandafter {\romannumeral`&&@#2}{#1}%
}%
\def\xint_dsh #1#2%
{%
\expandafter\XINT_dsh_checksignx \the\numexpr #2\relax\Z {#1}%
}%
\def\XINT_dsh_checksignx #1%
{%
\xint_UDzerominusfork
#1-\XINT_dsh_xiszero
0#1\XINT_dsx_xisNeg_checkA % on passe direct dans DSx
0-{\XINT_dsh_xisPos #1}%
\krof
}%
\def\XINT_dsh_xiszero #1\Z #2{ #2}%
\def\XINT_dsh_xisPos #1\Z #2%
{%
\expandafter\xint_firstoftwo_thenstop
\romannumeral0\XINT_dsx_checksignA #2\Z {#1}% via DSx
}%
% \end{macrocode}
% \subsection{\csh{xintDSx}}
% \lverb+&
% --> Attention le cas x=0 est traité dans la même catégorie que x > 0 <--$\
% si x < 0, fait A -> A.10^(|x|)$\
% si x >= 0, et A >=0, fait A -> {quo(A,10^(x))}{rem(A,10^(x))}$\
% si x >= 0, et A < 0, d'abord on calcule {quo(-A,10^(x))}{rem(-A,10^(x))}$\
% puis, si le premier n'est pas nul on lui donne le signe -$\
% si le premier est nul on donne le signe - au second.
%
% On peut donc toujours reconstituer l'original A par 10^x Q \pm R
% où il faut prendre le signe plus si Q est positif ou nul et le signe moins si
% Q est strictement négatif.
%
% December 4, 2015: As the new techniques of the 1.2 release limit the basic
% arithmetic to less than about 20000 digits, I should again consider a faster
% dsx_loop possibly impacting the input save stack impacting style; preserving
% a special routine if really needed for \xintXTrunc or the other concerned
% routines (if \xintXTrunc really needs it, which I have to check.)
%
% 2016/03/12: this is old code. 1.2f has removed the part of it which
% checked the size of x parameter.
%
% +
% \begin{macrocode}
\def\xintDSx {\romannumeral0\xintdsx }%
\def\xintdsx #1#2%
{%
\expandafter\xint_dsx\expandafter {\romannumeral`&&@#2}{#1}%
}%
\def\xint_dsx #1#2%
{%
\expandafter\XINT_dsx_checksignx \the\numexpr #2\relax\Z {#1}%
}%
\def\XINT_DSx #1#2{\romannumeral0\XINT_dsx_checksignx #1\Z {#2}}%
\def\XINT_dsx #1#2{\XINT_dsx_checksignx #1\Z {#2}}%
\def\XINT_dsx_checksignx #1%
{%
\xint_UDzerominusfork
#1-\XINT_dsx_xisZero
0#1\XINT_dsx_xisNeg_checkA
0-{\XINT_dsx_xisPos #1}%
\krof
}%
\def\XINT_dsx_xisZero #1\Z #2{{#2}{0}}% attention comme x > 0
\def\XINT_dsx_xisNeg_checkA #1\Z #2%
{%
\XINT_dsx_xisNeg_checkA_ #2\Z {#1}%
}%
\def\XINT_dsx_xisNeg_checkA_ #1#2\Z #3%
{%
\xint_gob_til_zero #1\XINT_dsx_xisNeg_Azero 0%
\XINT_dsx_zeroloop #3.{}\Z {#1#2}%
}%
\def\XINT_dsx_xisNeg_Azero #1\Z #2{ 0}%
\def\XINT_dsx_addzerosnofuss #1{\XINT_dsx_zeroloop #1.{}\Z }%
\def\XINT_dsx_zeroloop #1.#2%
{%
\ifnum #1<\xint_c_ix \expandafter\XINT_dsx_exita\fi
\expandafter\XINT_dsx_zeroloop\the\numexpr #1-\xint_c_viii.{#200000000}%
}%
\def\XINT_dsx_exita
\expandafter\XINT_dsx_zeroloop\the\numexpr #1-\xint_c_viii.#2%
{%
\expandafter\expandafter\expandafter
\XINT_dsx_addzeros\csname xint_gobble_\expandafter
\romannumeral\numexpr \xint_c_viii-(#1)\endcsname #2%
}%
\def\XINT_dsx_addzeros #1\Z #2{ #2#1}%
\def\XINT_dsx_xisPos #1\Z #2%
{%
\XINT_dsx_checksignA #2\Z {#1}%
}%
\def\XINT_dsx_checksignA #1%
{%
\xint_UDzerominusfork
#1-\XINT_dsx_AisZero
0#1\XINT_dsx_AisNeg
0-{\XINT_dsx_AisPos #1}%
\krof
}%
\def\XINT_dsx_AisZero #1\Z #2{{0}{0}}%
\def\XINT_dsx_AisNeg #1\Z #2%
{%
\expandafter\XINT_dsx_AisNeg_checkiffirstempty
\romannumeral0\XINT_split_xfork #2.#1\W\W\W\W\W\W\W\W\Z
}%
\def\XINT_dsx_AisNeg_checkiffirstempty #1%
{%
\xint_gob_til_dot #1\XINT_dsx_AisNeg_finish_zero.%
\XINT_dsx_AisNeg_finish_notzero #1%
}%
\def\XINT_dsx_AisNeg_finish_zero.\XINT_dsx_AisNeg_finish_notzero.#1.%
{%
\expandafter\XINT_dsx_end
\expandafter {\romannumeral0\XINT_num {-#1}}{0}%
}%
\def\XINT_dsx_AisNeg_finish_notzero #1.#2.%
{%
\expandafter\XINT_dsx_end
\expandafter {\romannumeral0\XINT_num {#2}}{-#1}%
}%
\def\XINT_dsx_AisPos #1\Z #2%
{%
\expandafter\XINT_dsx_AisPos_finish
\romannumeral0\XINT_split_xfork #2.#1\W\W\W\W\W\W\W\W\Z
}%
\def\XINT_dsx_AisPos_finish #1.#2.%
{%
\expandafter\XINT_dsx_end
\expandafter {\romannumeral0\XINT_num {#2}}%
{\romannumeral0\XINT_num {#1}}%
}%
\def\XINT_dsx_end #1#2{\expandafter{#2}{#1}}%
% \end{macrocode}
% \subsection{\csh{xintDecSplit}, \csh{xintDecSplitL}, \csh{xintDecSplitR}}
% \lverb!DECIMAL SPLIT
%
% The macro \xintDecSplit {x}{A} first replaces A with |A| (*)
% This macro cuts the number into two pieces L and R. The concatenation LR
% always reproduces |A|, and R may be empty or have leading zeros. The
% position of the cut is specified by the first argument x. If x is zero or
% positive the cut location is x slots to the left of the right end of the
% number. If x becomes equal to or larger than the length of the number then L
% becomes empty. If x is negative the location of the cut is |x| slots to the
% right of the left end of the number.
%
% (*) warning: this may change in a future version. Only the behavior
% for A non-negative is guaranteed to remain the same.
%
% 2016/03/12: this is old code. 1.2f has removed the part of it which
% checked the size of x parameter.
%
% !
% \begin{macrocode}
\def\xintDecSplit {\romannumeral0\xintdecsplit }%
\def\xintdecsplit #1#2%
{%
\expandafter\XINT_split_finish
\romannumeral0\expandafter\XINT_split_xfork
\the\numexpr #1\expandafter.\romannumeral0\xintiiabs {#2}\W\W\W\W\W\W\W\W\Z
}%
\def\xintDecSplitL {\romannumeral0\xintdecsplitl }%
\def\xintdecsplitl #1#2%
{%
\expandafter\XINT_splitl_finish
\romannumeral0\expandafter\XINT_split_xfork
\the\numexpr #1\expandafter.\romannumeral0\xintiiabs {#2}\W\W\W\W\W\W\W\W\Z
}%
\def\xintDecSplitR {\romannumeral0\xintdecsplitr }%
\def\xintdecsplitr #1#2%
{%
\expandafter\XINT_splitr_finish
\romannumeral0\expandafter\XINT_split_xfork
\the\numexpr #1\expandafter.\romannumeral0\xintiiabs {#2}\W\W\W\W\W\W\W\W\Z
}%
\def\XINT_split_finish #1.#2.{{#1}{#2}}%
\def\XINT_splitl_finish #1.#2.{{#1}}%
\def\XINT_splitr_finish #1.#2.{{#2}}%
\def\XINT_split_xfork #1%
{%
\xint_UDzerominusfork
#1-\XINT_split_zerosplit
0#1\XINT_split_fromleft
0-{\XINT_split_fromright #1}%
\krof
}%
\def\XINT_split_zerosplit #1.#2\W\W\W\W\W\W\W\W\Z{ #2..}%
\def\XINT_split_fromleft #1.%#2\W\W\W\W\W\W\W\W\Z
{%
\XINT_split_fromleft_loop #1.{}%#2\W\W\W\W\W\W\W\W\Z
}%
\def\XINT_split_fromleft_loop #1.%
{%
\ifnum #1<\xint_c_viii\expandafter\XINT_split_fromleft_exita\fi
\expandafter\XINT_split_fromleft_loop_perhaps
\the\numexpr #1-\xint_c_viii\expandafter.\XINT_split_fromleft_eight
}%
\def\XINT_split_fromleft_eight #1#2#3#4#5#6#7#8#9{#9{#1#2#3#4#5#6#7#8#9}}%
\def\XINT_split_fromleft_loop_perhaps #1.#2%
{%
\xint_gob_til_W #2\XINT_split_fromleft_toofar\W
\XINT_split_fromleft_loop #1.%
}%
\def\XINT_split_fromleft_toofar\W\XINT_split_fromleft_loop #1.#2#3\Z
{%
\XINT_split_fromleft_toofar_b #2\Z
}%
\def\XINT_split_fromleft_toofar_b #1\W #2\Z { #1..}%
\def\XINT_split_fromleft_exita
\expandafter\XINT_split_fromleft_loop_perhaps
\the\numexpr #1-\xint_c_viii\expandafter.\XINT_split_fromleft_eight
{%
\csname XINT_split_fromleft_endsplit_\romannumeral #1\endcsname
}%
\def\XINT_split_fromleft_endsplit_ #1#2\W #3\Z { #1.#2.}%
\def\XINT_split_fromleft_endsplit_i #1#2%
{\XINT_split_fromleft_checkiftoofar #2{#1#2}}%
\def\XINT_split_fromleft_endsplit_ii #1#2#3%
{\XINT_split_fromleft_checkiftoofar #3{#1#2#3}}%
\def\XINT_split_fromleft_endsplit_iii #1#2#3#4%
{\XINT_split_fromleft_checkiftoofar #4{#1#2#3#4}}%
\def\XINT_split_fromleft_endsplit_iv #1#2#3#4#5%
{\XINT_split_fromleft_checkiftoofar #5{#1#2#3#4#5}}%
\def\XINT_split_fromleft_endsplit_v #1#2#3#4#5#6%
{\XINT_split_fromleft_checkiftoofar #6{#1#2#3#4#5#6}}%
\def\XINT_split_fromleft_endsplit_vi #1#2#3#4#5#6#7%
{\XINT_split_fromleft_checkiftoofar #7{#1#2#3#4#5#6#7}}%
\def\XINT_split_fromleft_endsplit_vii #1#2#3#4#5#6#7#8%
{\XINT_split_fromleft_checkiftoofar #8{#1#2#3#4#5#6#7#8}}%
\def\XINT_split_fromleft_checkiftoofar #1#2#3\W #4\Z
{%
\xint_gob_til_W #1\XINT_split_fromleft_wenttoofar\W \space#2.#3.%
}%
\def\XINT_split_fromleft_wenttoofar\W\space #1.%
{%
\XINT_split_fromleft_wenttoofar_b #1\Z
}%
\def\XINT_split_fromleft_wenttoofar_b #1\W #2\Z { #1.}%
\def\XINT_split_fromright #1.#2\W\W\W\W\W\W\W\W\Z
{%
\expandafter\XINT_split_fromright_loop
\the\numexpr #1\expandafter.\expandafter{\expandafter}%
\romannumeral0\xintreverseorder{#2}\W\W\W\W\W\W\W\W\Z #2.%
}%
\def\XINT_split_fromright_loop #1.%
{%
\ifnum #1<\xint_c_viii\expandafter\XINT_split_fromright_exita\fi
\expandafter\XINT_split_fromright_loop_perhaps
\the\numexpr #1-\xint_c_viii\expandafter.\XINT_split_fromright_eight
}%
\def\XINT_split_fromright_eight #1#2#3#4#5#6#7#8#9{#9{#9#8#7#6#5#4#3#2#1}}%
\def\XINT_split_fromright_loop_perhaps #1.#2%
{%
\xint_gob_til_W #2\XINT_split_fromright_toofar\W
\XINT_split_fromright_loop #1.%
}%
\def\XINT_split_fromright_toofar\W\XINT_split_fromright_loop #1\Z {.}%
\def\XINT_split_fromright_exita
\expandafter\XINT_split_fromright_loop_perhaps
\the\numexpr #1-\xint_c_viii\expandafter.\XINT_split_fromright_eight
{%
\csname XINT_split_fromright_endsplit_\romannumeral #1\endcsname
}%
\def\XINT_split_fromright_endsplit_ #1#2\W #3\Z #4.%
{%
\xintreverseorder {#2}.#1.%
}%
\def\XINT_split_fromright_endsplit_i #1#2%
{\XINT_split_fromright_checkiftoofar #2{#2#1}}%
\def\XINT_split_fromright_endsplit_ii #1#2#3%
{\XINT_split_fromright_checkiftoofar #3{#3#2#1}}%
\def\XINT_split_fromright_endsplit_iii #1#2#3#4%
{\XINT_split_fromright_checkiftoofar #4{#4#3#2#1}}%
\def\XINT_split_fromright_endsplit_iv #1#2#3#4#5%
{\XINT_split_fromright_checkiftoofar #5{#5#4#3#2#1}}%
\def\XINT_split_fromright_endsplit_v #1#2#3#4#5#6%
{\XINT_split_fromright_checkiftoofar #6{#6#5#4#3#2#1}}%
\def\XINT_split_fromright_endsplit_vi #1#2#3#4#5#6#7%
{\XINT_split_fromright_checkiftoofar #7{#7#6#5#4#3#2#1}}%
\def\XINT_split_fromright_endsplit_vii #1#2#3#4#5#6#7#8%
{\XINT_split_fromright_checkiftoofar #8{#8#7#6#5#4#3#2#1}}%
\def\XINT_split_fromright_checkiftoofar #1%
{%
\xint_gob_til_W #1\XINT_split_fromright_wenttoofar\W
\XINT_split_fromright_endsplit_
}%
\def\XINT_split_fromright_wenttoofar\W
\XINT_split_fromright_endsplit_ #1\Z {.}%
% \end{macrocode}
% \subsection{\csh{xintiiSqrt}, \csh{xintiiSqrtR}, \csh{xintiiSquareRoot}}
% \lverb|First done with 1.08.
%
% 1.1 added \xintiiSquareRoot.
%
% 1.1a added \xintiiSqrtR.
%
% 1.2f (2016/03/01-02-03) has rewritten the implementation, the underlying
% mathematics remaining about the same. The routine is much faster for inputs
% having up to 16 digits (because it does it all with \numexpr directly now),
% and also much faster for very long inputs (because it now fetches only the
% needed new digits after the first 16 (or 17) ones, via the geometric
% sequence 16, then 32, then 64, etc...; earlier version did the computations
% with all remaining digits after a suitable starting point with correct 4 or
% 5 leading digits). Note however that the fetching of tokens is via
% intrinsically O(N^2) macros, hence inevitably inputs with thousands of
% digits start being treated less well.
%
% Actually there is some room for improvements, one could prepare better
% input X for the upcoming treatment of fetching its digits by 16, then 32,
% then 64, etc...
%
% Incidently, as \xintiiSqrt uses subtraction and subtraction was broken from
% 1.2 to 1.2c, then for another reason from 1.2c to 1.2f, it could
% get wrong in certain (relatively rare) cases. There was also a bug that
% made it unneedlessly slow for odd number of digits on input.
%
% 1.2f also modifies \xintFloatSqrt in xintfrac.sty which now has more
% code in common with here and benefits from the same speed improvements.
%
% |
%
% \begin{macrocode}
\def\xintiiSqrt {\romannumeral0\xintiisqrt }%
\def\xintiiSqrtR {\romannumeral0\xintiisqrtr }%
\def\xintiiSquareRoot {\romannumeral0\xintiisquareroot }%
\def\xintiSqrt {\romannumeral0\xintisqrt }%
\def\xintiSquareRoot {\romannumeral0\xintisquareroot }%
\def\xintisqrt {\expandafter\XINT_sqrt_post\romannumeral0\xintisquareroot }%
\def\xintiisqrt {\expandafter\XINT_sqrt_post\romannumeral0\xintiisquareroot }%
\def\xintiisqrtr {\expandafter\XINT_sqrtr_post\romannumeral0\xintiisquareroot }%
\def\XINT_sqrt_post #1#2{\XINT_dec_pos #1\Z }%
% \end{macrocode}
% \lverb|N = (#1)^2 - #2 avec #1 le plus petit possible et #2>0 (hence #2<2*#1).
% (#1-.5)^2=#1^2-#1+.25=N+#2-#1+.25. Si 0<#2<#1, <= N-0.75<N, donc rounded->#1
% si #2>=#1, (#1-.5)^2>=N+.25>N, donc rounded->#1-1.|
% \begin{macrocode}
\def\XINT_sqrtr_post #1#2{\xintiiifLt {#2}{#1}{ #1}{\XINT_dec_pos #1\Z}}%
\def\xintisquareroot #1%
{\expandafter\XINT_sqrt_checkin\romannumeral0\xintnum{#1}\Z }%
\def\xintiisquareroot #1{\expandafter\XINT_sqrt_checkin\romannumeral`&&@#1\Z }%
\def\XINT_sqrt_checkin #1%
{%
\xint_UDzerominusfork
#1-\XINT_sqrt_iszero
0#1\XINT_sqrt_isneg
0-{\XINT_sqrt #1}%
\krof
}%
\def\XINT_sqrt_iszero #1\Z { 11}%
\edef\XINT_sqrt_isneg #1\Z {\noexpand\xintError:RootOfNegative\space 11}%
\def\XINT_sqrt #1\Z
{%
\expandafter\XINT_sqrt_start\romannumeral0\xintlength {#1}.#1.%
}%
\def\XINT_sqrt_start #1.%
{%
\ifnum #1<\xint_c_x\xint_dothis\XINT_sqrt_small_a\fi
\xint_orthat\XINT_sqrt_big_a #1.%
}%
\def\XINT_sqrt_small_a #1.{\XINT_sqrt_a #1.\XINT_sqrt_small_d }%
\def\XINT_sqrt_big_a #1.{\XINT_sqrt_a #1.\XINT_sqrt_big_d }%
\def\XINT_sqrt_a #1.%
{%
\ifodd #1
\expandafter\XINT_sqrt_bO
\else
\expandafter\XINT_sqrt_bE
\fi
#1.%
}%
\def\XINT_sqrt_bE #1.#2#3#4%
{%
\XINT_sqrt_c {#3#4}#2{#1}#3#4%
}%
\def\XINT_sqrt_bO #1.#2#3%
{%
\XINT_sqrt_c #3#2{#1}#3%
}%
\def\XINT_sqrt_c #1#2%
{%
\expandafter #2%
\the\numexpr \ifnum #1>\xint_c_ii
\ifnum #1>\xint_c_vi
\ifnum #1>12 \ifnum #1>20 \ifnum #1>30
\ifnum #1>42 \ifnum #1>56 \ifnum #1>72
\ifnum #1>90
10\else 9\fi \else 8\fi \else 7\fi \else 6\fi \else 5\fi
\else 4\fi \else 3\fi \else 2\fi \else 1\fi .%
}%
\def\XINT_sqrt_small_d #1.#2%
{%
\expandafter\XINT_sqrt_small_e
\the\numexpr #1\ifcase \numexpr #2/\xint_c_ii-\xint_c_i\relax
\or 0\or 00\or 000\or 0000\fi .%
}%
\def\XINT_sqrt_small_e #1.#2.%
{%
\expandafter\XINT_sqrt_small_ea\the\numexpr #1*#1-#2.#1.%
}%
\def\XINT_sqrt_small_ea #1%
{%
\if0#1\xint_dothis\XINT_sqrt_small_ez\fi
\if-#1\xint_dothis\XINT_sqrt_small_eb\fi
\xint_orthat\XINT_sqrt_small_f #1%
}%
\def\XINT_sqrt_small_ez 0.#1.{\expandafter{\the\numexpr#1+\xint_c_i
\expandafter}\expandafter{\the\numexpr #1*\xint_c_ii+\xint_c_i}}%
\def\XINT_sqrt_small_eb -#1.#2.%
{%
\expandafter\XINT_sqrt_small_ec \the\numexpr
(#1-\xint_c_i+#2)/(\xint_c_ii*#2).#1.#2.%
}%
\def\XINT_sqrt_small_ec #1.#2.#3.%
{%
\expandafter\XINT_sqrt_small_f \the\numexpr
-#2+\xint_c_ii*#3*#1+#1*#1\expandafter.\the\numexpr #3+#1.%
}%
\def\XINT_sqrt_small_f #1.#2.%
{%
\expandafter\XINT_sqrt_small_g
\the\numexpr (#1+#2)/(\xint_c_ii*#2)-\xint_c_i.#1.#2.%
}%
\def\XINT_sqrt_small_g #1#2.%
{%
\if 0#1%
\expandafter\XINT_sqrt_small_end
\else
\expandafter\XINT_sqrt_small_h
\fi
#1#2.%
}%
\def\XINT_sqrt_small_h #1.#2.#3.%
{%
\expandafter\XINT_sqrt_small_f
\the\numexpr #2-\xint_c_ii*#1*#3+#1*#1\expandafter.%
\the\numexpr #3-#1.%
}%
\def\XINT_sqrt_small_end #1.#2.#3.{{#3}{#2}}%
\def\XINT_sqrt_big_d #1.#2%
{%
\ifodd #2 \xint_dothis{\expandafter\XINT_sqrt_big_eO}\fi
\xint_orthat{\expandafter\XINT_sqrt_big_eE}%
\the\numexpr (#2-\xint_c_i)/\xint_c_ii.#1;%
}%
\def\XINT_sqrt_big_eE #1;#2#3#4#5#6#7#8#9%
{%
\XINT_sqrt_big_eE_a #1;{#2#3#4#5#6#7#8#9}%
}%
\def\XINT_sqrt_big_eE_a #1.#2;#3%
{%
\expandafter\XINT_sqrt_bigormed_f
\romannumeral0\XINT_sqrt_small_e #2000.#3.#1;%
}%
\def\XINT_sqrt_big_eO #1;#2#3#4#5#6#7#8#9%
{%
\XINT_sqrt_big_eO_a #1;{#2#3#4#5#6#7#8#9}%
}%
\def\XINT_sqrt_big_eO_a #1.#2;#3#4%
{%
\expandafter\XINT_sqrt_bigormed_f
\romannumeral0\XINT_sqrt_small_e #20000.#3#4.#1;%
}%
\def\XINT_sqrt_bigormed_f #1#2#3;%
{%
\ifnum#3<\xint_c_ix
\xint_dothis {\csname XINT_sqrt_med_f\romannumeral#3\endcsname}%
\fi
\xint_orthat\XINT_sqrt_big_f #1.#2.#3;%
}%
\def\XINT_sqrt_med_fv {\XINT_sqrt_med_fa .}%
\def\XINT_sqrt_med_fvi {\XINT_sqrt_med_fa 0.}%
\def\XINT_sqrt_med_fvii {\XINT_sqrt_med_fa 00.}%
\def\XINT_sqrt_med_fviii{\XINT_sqrt_med_fa 000.}%
\def\XINT_sqrt_med_fa #1.#2.#3.#4;%
{%
\expandafter\XINT_sqrt_med_fb
\the\numexpr (#30#1-5#1)/(\xint_c_ii*#2).#1.#2.#3.%
}%
\def\XINT_sqrt_med_fb #1.#2.#3.#4.#5.%
{%
\expandafter\XINT_sqrt_small_ea
\the\numexpr (#40#2-\xint_c_ii*#3*#1)*10#2+(#1*#1-#5)\expandafter.%
\the\numexpr #30#2-#1.%
}%
\def\XINT_sqrt_big_f #1;#2#3#4#5#6#7#8#9%
{%
\XINT_sqrt_big_fa #1;{#2#3#4#5#6#7#8#9}%
}%
\def\XINT_sqrt_big_fa #1.#2.#3;#4%
{%
\expandafter\XINT_sqrt_big_ga
\the\numexpr #3-\xint_c_viii\expandafter.%
\romannumeral0\XINT_sqrt_med_fa 000.#1.#2.;#4.%
}%
%
\def\XINT_sqrt_big_ga #1.#2#3%
{%
\ifnum #1>\xint_c_viii
\expandafter\XINT_sqrt_big_gb\else
\expandafter\XINT_sqrt_big_ka
\fi #1.#3.#2.%
}%
\def\XINT_sqrt_big_gb #1.#2.#3.%
{%
\expandafter\XINT_sqrt_big_gc
\the\numexpr (\xint_c_ii*#2-\xint_c_i)*\xint_c_x^viii/(\xint_c_iv*#3).%
#3.#2.#1;%
}%
\def\XINT_sqrt_big_gc #1.#2.#3.%
{%
\expandafter\XINT_sqrt_big_gd
\romannumeral0\xintiiadd
{\xintiiSub {#300000000}{\xintDouble{\xintiiMul{#2}{#1}}}00000000}%
{\xintiiSqr {#1}}.%
\romannumeral0\xintiisub{#200000000}{#1}.%
}%
\def\XINT_sqrt_big_gd #1.#2.%
{%
\expandafter\XINT_sqrt_big_ge #2.#1.%
}%
\def\XINT_sqrt_big_ge #1;#2#3#4#5#6#7#8#9%
{\XINT_sqrt_big_gf #1.#2#3#4#5#6#7#8#9;}%
\def\XINT_sqrt_big_gf #1;#2#3#4#5#6#7#8#9%
{\XINT_sqrt_big_gg #1#2#3#4#5#6#7#8#9.}%
\def\XINT_sqrt_big_gg #1.#2.#3.#4.%
{%
\expandafter\XINT_sqrt_big_gloop
\expandafter\xint_c_xvi\expandafter.%
\the\numexpr #3-\xint_c_viii\expandafter.%
\romannumeral0\xintiisub {#2}{\xintiNum{#4}}.#1.%
}%
\def\XINT_sqrt_big_gloop #1.#2.%
{%
\unless\ifnum #1<#2 \xint_dothis\XINT_sqrt_big_ka \fi
\xint_orthat{\XINT_sqrt_big_gi #1.}#2.%
}%
\def\XINT_sqrt_big_gi #1.%
{%
\expandafter\XINT_sqrt_big_gj
\romannumeral0\XINT_dsx_addzerosnofuss{#1}{}.#1.%
}%
\def\XINT_sqrt_big_gj #1.#2.#3.#4.#5.%
{%
\expandafter\XINT_sqrt_big_gk
\romannumeral0\xintiidivision {#4#1}{\XINT_dbl_pos #5\Z}.%
#1.#5.#2.#3.%
}%
\def\XINT_sqrt_big_gk #1#2.#3.#4.%
{%
\expandafter\XINT_sqrt_big_gl
\romannumeral0\xintiiadd {#2#3}{\xintiiSqr{#1}}.%
\romannumeral0\xintiisub {#4#3}{#1}.%
}%
\def\XINT_sqrt_big_gl #1.#2.%
{%
\expandafter\XINT_sqrt_big_gm #2.#1.%
}%
\def\XINT_sqrt_big_gm #1.#2.#3.#4.#5.%
{%
\expandafter\XINT_sqrt_big_gn
\romannumeral0\expandafter\XINT_split_fromleft_loop
\the\numexpr\xint_c_ii*#3.{}#5\W\W\W\W\W\W\W\W\Z
#1.#2.#3.#4.%
}%
\def\XINT_sqrt_big_gn #1.#2.#3.#4.#5.#6.%
{%
\expandafter\XINT_sqrt_big_gloop
\the\numexpr \xint_c_ii*#5\expandafter.%
\the\numexpr #6-#5\expandafter.%
\romannumeral0\xintiisub{#4}{\xintiNum{#1}}.#3.#2.%
}%
\def\XINT_sqrt_big_ka #1.#2.#3.#4.%
{%
\expandafter\XINT_sqrt_big_kb
\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#3}.%
\romannumeral0\xintiisub
{\XINT_dsx_addzerosnofuss {\numexpr\xint_c_ii*#1}{#2}}%
{\xintiNum{#4}}.%
}%
\def\XINT_sqrt_big_kb #1.#2.%
{%
\expandafter\XINT_sqrt_big_kc #2.#1.%
}%
\def\XINT_sqrt_big_kc #1%
{%
\if0#1\xint_dothis\XINT_sqrt_big_kz\fi
\xint_orthat\XINT_sqrt_big_kloop #1%
}%
\def\XINT_sqrt_big_kz 0.#1.%
{%
\expandafter\XINT_sqrt_big_kend
\romannumeral0\xintinc{\XINT_dbl_pos #1\Z}.#1.%
}%
\def\XINT_sqrt_big_kend #1.#2.%
{%
\expandafter{\romannumeral0\xintinc{#2}}{#1}%
}%
\def\XINT_sqrt_big_kloop #1.#2.%
{%
\expandafter\XINT_sqrt_big_ke
\romannumeral0\xintiidivision{#1}{\romannumeral0\XINT_dbl_pos #2\Z}{#2}%
}%
\def\XINT_sqrt_big_ke #1%
{%
\if0\XINT_Sgn #1\Z
\expandafter \XINT_sqrt_big_end
\else \expandafter \XINT_sqrt_big_kf
\fi {#1}%
}%
\def\XINT_sqrt_big_kf #1#2#3%
{%
\expandafter\XINT_sqrt_big_kg
\romannumeral0\xintiisub {#3}{#1}.%
\romannumeral0\xintiiadd {#2}{\xintiiSqr {#1}}.%
}%
\def\XINT_sqrt_big_kg #1.#2.%
{%
\expandafter\XINT_sqrt_big_kloop #2.#1.%
}%
\def\XINT_sqrt_big_end #1#2#3{{#3}{#2}}%
% \end{macrocode}
% \subsection{\csh{xintiiBinomial}, \csh{xintiBinomial}}
% \lverb|2015/11/28-29 for 1.2f.
%
% 2016/11/19 for 1.2h: I truly can't understand why I hard-coded last
% year an error-message for arguments outside of the range for binomial
% formula. Naturally there should be no error but a rather a 0 return
% value for binomial(x,y), if y<0 or x<y !
%
% I really lack some kind of infinity or NaN value.|
% \begin{macrocode}
\def\xintiiBinomial {\romannumeral0\xintiibinomial }%
\def\xintiibinomial #1#2%
{%
\expandafter\XINT_binom_pre\the\numexpr #1\expandafter.\the\numexpr #2.%
}%
\def\XINT_binom_pre #1.#2.%
{%
\expandafter\XINT_binom_fork \the\numexpr#1-#2.#2.#1.%
}%
\def\xintiBinomial{\romannumeral0\xintibinomial}%
\let\xintibinomial\xintiibinomial
% \end{macrocode}
% \lverb|k.x-k.x. I hesitated to restrict maximal allowed value of x to 10000.
% Finally I don't. But due to using small multiplication and small division, x
% must have at most eight digits. If x>=2^31 an arithmetic overflow error will
% have happened already.|
% \begin{macrocode}
\def\XINT_binom_fork #1#2.#3#4.#5#6.%
{%
\if-#5\xint_dothis{\xintError:OutOfRangeBinomial\space 0}\fi
\if-#1\xint_dothis{ 0}\fi
\if-#3\xint_dothis{ 0}\fi
\if0#1\xint_dothis{ 1}\fi
\if0#3\xint_dothis{ 1}\fi
\ifnum #5#6>\xint_c_x^viii_mone\xint_dothis{\xintError:OutOfRangeBinomial\space 0}\fi
\ifnum #1#2>#3#4 \xint_dothis{\XINT_binom_a #1#2.#3#4.}\fi
\xint_orthat{\XINT_binom_a #3#4.#1#2.}%
}%
% \end{macrocode}
% \lverb|x-k.k. avec 0<k<x, k<=x-k. Les divisions produiront en extra après le
% quotient un terminateur 1!\Z!0!. On va procéder par petite multiplication
% suivie par petite division. Donc ici on met le 1!\Z!0! pour amorcer.
%
% Le 1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W est le terminateur pour le
% \XINT_unsep_cuzsmall final.|
% \begin{macrocode}
\def\XINT_binom_a #1.#2.%
{%
\expandafter\XINT_binom_b\the\numexpr \xint_c_i+#1.1.#2.100000001!1!\Z!0!%
}%
% \end{macrocode}
% \lverb|y=x-k+1.j=1.k. On va évaluer par y/1*(y+1)/2*(y+2)/3 etc... On essaie
% de regrouper de manière à utiliser au mieux \numexpr. On peut aller jusqu'à
% x=10000 car 9999*10000<10^8. 463*464*465=99896880, 98*99*100*101=97990200.
% On va vérifier à chaque étape si on dépasse un seuil. Le style de
% l'implémentation diffère de celui que j'avais utilisé pour \xintiiFac. On
% pourrait tout-à-fait avoir une verybigloop, mais bon. Je rajoute aussi un
% verysmall. Le traitement est un peu différent pour elle afin d'aller jusqu'à
% x=29 (et pas seulement 26 si je suivais le modèle des autres, mais je veux
% pouvoir faire binomial(29,1), binomial(29,2), ... en vsmall).|
% \begin{macrocode}
\def\XINT_binom_b #1.%
{%
\ifnum #1>9999 \xint_dothis\XINT_binom_vbigloop \fi
\ifnum #1>463 \xint_dothis\XINT_binom_bigloop \fi
\ifnum #1>98 \xint_dothis\XINT_binom_medloop \fi
\ifnum #1>29 \xint_dothis\XINT_binom_smallloop \fi
\xint_orthat\XINT_binom_vsmallloop #1.%
}%
% \end{macrocode}
% \lverb|y.j.k. Au départ on avait x-k+1.1.k. Ensuite on a des blocs 1<8d>!
% donnant le résultat intermédiaire, dans l'ordre, et à la fin on a 1!1\Z!0!.
% Dans smallloop on peut prendre 4 par 4.|
% \begin{macrocode}
\def\XINT_binom_smallloop #1.#2.#3.%
{%
\ifcase\numexpr #3-#2\relax
\expandafter\XINT_binom_end_
\or \expandafter\XINT_binom_end_i
\or \expandafter\XINT_binom_end_ii
\or \expandafter\XINT_binom_end_iii
\else\expandafter\XINT_binom_smallloop_a
\fi #1.#2.#3.%
}%
% \end{macrocode}
% \lverb|Ça m'ennuie un peu de reprendre les #1, #2, #3 ici. On a besoin de
% \numexpr pour \XINT_binom_div, mais de \romannumeral0 pour le unsep après
% \XINT_binom_mul.|
% \begin{macrocode}
\def\XINT_binom_smallloop_a #1.#2.#3.%
{%
\expandafter\XINT_binom_smallloop_b
\the\numexpr #1+\xint_c_iv\expandafter.%
\the\numexpr #2+\xint_c_iv\expandafter.%
\the\numexpr #3\expandafter.%
\the\numexpr\expandafter\XINT_binom_div
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter
!\romannumeral0\expandafter\XINT_binom_mul
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_binom_smallloop_b #1.%
{%
\ifnum #1>98 \expandafter\XINT_binom_medloop \else
\expandafter\XINT_binom_smallloop \fi #1.%
}%
% \end{macrocode}
% \lverb|Ici on prend trois par trois.|
% \begin{macrocode}
\def\XINT_binom_medloop #1.#2.#3.%
{%
\ifcase\numexpr #3-#2\relax
\expandafter\XINT_binom_end_
\or \expandafter\XINT_binom_end_i
\or \expandafter\XINT_binom_end_ii
\else\expandafter\XINT_binom_medloop_a
\fi #1.#2.#3.%
}%
\def\XINT_binom_medloop_a #1.#2.#3.%
{%
\expandafter\XINT_binom_medloop_b
\the\numexpr #1+\xint_c_iii\expandafter.%
\the\numexpr #2+\xint_c_iii\expandafter.%
\the\numexpr #3\expandafter.%
\the\numexpr\expandafter\XINT_binom_div
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)\expandafter
!\romannumeral0\expandafter\XINT_binom_mul
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_binom_medloop_b #1.%
{%
\ifnum #1>463 \expandafter\XINT_binom_bigloop \else
\expandafter\XINT_binom_medloop \fi #1.%
}%
% \end{macrocode}
% \lverb|Ici on prend deux par deux.|
% \begin{macrocode}
\def\XINT_binom_bigloop #1.#2.#3.%
{%
\ifcase\numexpr #3-#2\relax
\expandafter\XINT_binom_end_
\or \expandafter\XINT_binom_end_i
\else\expandafter\XINT_binom_bigloop_a
\fi #1.#2.#3.%
}%
\def\XINT_binom_bigloop_a #1.#2.#3.%
{%
\expandafter\XINT_binom_bigloop_b
\the\numexpr #1+\xint_c_ii\expandafter.%
\the\numexpr #2+\xint_c_ii\expandafter.%
\the\numexpr #3\expandafter.%
\the\numexpr\expandafter\XINT_binom_div
\the\numexpr #2*(#2+\xint_c_i)\expandafter
!\romannumeral0\expandafter\XINT_binom_mul
\the\numexpr #1*(#1+\xint_c_i)!%
}%
\def\XINT_binom_bigloop_b #1.%
{%
\ifnum #1>9999 \expandafter\XINT_binom_vbigloop \else
\expandafter\XINT_binom_bigloop \fi #1.%
}%
% \end{macrocode}
% \lverb|Et finalement un par un.|
% \begin{macrocode}
\def\XINT_binom_vbigloop #1.#2.#3.%
{%
\ifnum #3=#2
\expandafter\XINT_binom_end_
\else\expandafter\XINT_binom_vbigloop_a
\fi #1.#2.#3.%
}%
\def\XINT_binom_vbigloop_a #1.#2.#3.%
{%
\expandafter\XINT_binom_vbigloop
\the\numexpr #1+\xint_c_i\expandafter.%
\the\numexpr #2+\xint_c_i\expandafter.%
\the\numexpr #3\expandafter.%
\the\numexpr\expandafter\XINT_binom_div\the\numexpr #2\expandafter
!\romannumeral0\XINT_binom_mul #1!%
}%
% \end{macrocode}
% \lverb|y.j.k. La partie very small. y est au plus 26 (non 29 mais retesté
% dans \XINT_binom_vsmallloop_a), et tous les binomial(29,n) sont <10^8. On
% peut donc faire y(y+1)(y+2)(y+3) et aussi il y a le fait que etex fait a*b/c
% en double precision. Pour ne pas bifurquer à la fin sur smallloop, si n=27,
% 27, ou 29 on procède un peu différemment des autres boucles. Si je testais
% aussi #1 après #3-#2 pour les autres il faudrait des terminaisons
% différentes.|
% \begin{macrocode}
\def\XINT_binom_vsmallloop #1.#2.#3.%
{%
\ifcase\numexpr #3-#2\relax
\expandafter\XINT_binom_vsmallend_
\or \expandafter\XINT_binom_vsmallend_i
\or \expandafter\XINT_binom_vsmallend_ii
\or \expandafter\XINT_binom_vsmallend_iii
\else\expandafter\XINT_binom_vsmallloop_a
\fi #1.#2.#3.%
}%
\def\XINT_binom_vsmallloop_a #1.%
{%
\ifnum #1>26 \expandafter\XINT_binom_smallloop_a \else
\expandafter\XINT_binom_vsmallloop_b \fi #1.%
}%
\def\XINT_binom_vsmallloop_b #1.#2.#3.%
{%
\expandafter\XINT_binom_vsmallloop
\the\numexpr #1+\xint_c_iv\expandafter.%
\the\numexpr #2+\xint_c_iv\expandafter.%
\the\numexpr #3\expandafter.%
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter
!\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_binom_mul #1!#21!\Z!0!%
{%
\expandafter\XINT_rev_nounsep\expandafter{\expandafter}%
\the\numexpr\expandafter\XINT_smallmul
\the\numexpr\xint_c_x^viii+#1\expandafter
!\romannumeral0\XINT_rev_nounsep {}1\Z!#2%
\R!\R!\R!\R!\R!\R!\R!\R!\W
\R!\R!\R!\R!\R!\R!\R!\R!\W
1\Z!%
}%
\def\XINT_binom_div #1!1\Z!%
{%
\expandafter\XINT_smalldivx_a
\the\numexpr #1/\xint_c_ii\expandafter.%
\the\numexpr \xint_c_x^viii+#1!%
}%
% \end{macrocode}
% \lverb|Vaguement envisagé d'éviter le 10^8+ mais bon.|
% \begin{macrocode}
\def\XINT_binom_vsmallmuldiv #1!#2!1#3!{\xint_c_x^viii+#2*#3/#1!}%
% \end{macrocode}
% \lverb|On a des terminaisons communes aux trois situations small, med, big,
% et on est sûr de pouvoir faire les multiplications dans \numexpr, car on
% vient ici *après* avoir comparé à 9999 ou 463 ou 98.|
% \begin{macrocode}
\def\XINT_binom_end_iii #1.#2.#3.%
{%
\expandafter\XINT_binom_finish
\the\numexpr\expandafter\XINT_binom_div
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter
!\romannumeral0\expandafter\XINT_binom_mul
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_binom_end_ii #1.#2.#3.%
{%
\expandafter\XINT_binom_finish
\the\numexpr\expandafter\XINT_binom_div
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)\expandafter
!\romannumeral0\expandafter\XINT_binom_mul
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_binom_end_i #1.#2.#3.%
{%
\expandafter\XINT_binom_finish
\the\numexpr\expandafter\XINT_binom_div
\the\numexpr #2*(#2+\xint_c_i)\expandafter
!\romannumeral0\expandafter\XINT_binom_mul
\the\numexpr #1*(#1+\xint_c_i)!%
}%
\def\XINT_binom_end_ #1.#2.#3.%
{%
\expandafter\XINT_binom_finish
\the\numexpr\expandafter\XINT_binom_div\the\numexpr #2\expandafter
!\romannumeral0\XINT_binom_mul #1!%
}%
\def\XINT_binom_finish #1\Z!0!%
{\XINT_unsep_cuzsmall #11\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W }%
% \end{macrocode}
% \lverb|Duplication de code seulement pour la boucle avec très
% petits coeffs, mais en plus on fait au maximum des possibilités. (on
% pourrait tester plus le résultat déjà obtenu).|
% \begin{macrocode}
\def\XINT_binom_vsmallend_iii #1.%
{%
\ifnum #1>26 \expandafter\XINT_binom_end_iii \else
\expandafter\XINT_binom_vsmallend_iiib \fi #1.%
}%
\def\XINT_binom_vsmallend_iiib #1.#2.#3.%
{%
\expandafter\XINT_binom_vsmallfinish
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter
!\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_binom_vsmallend_ii #1.%
{%
\ifnum #1>27 \expandafter\XINT_binom_end_ii \else
\expandafter\XINT_binom_vsmallend_iib \fi #1.%
}%
\def\XINT_binom_vsmallend_iib #1.#2.#3.%
{%
\expandafter\XINT_binom_vsmallfinish
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)\expandafter
!\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_binom_vsmallend_i #1.%
{%
\ifnum #1>28 \expandafter\XINT_binom_end_i \else
\expandafter\XINT_binom_vsmallend_ib \fi #1.%
}%
\def\XINT_binom_vsmallend_ib #1.#2.#3.%
{%
\expandafter\XINT_binom_vsmallfinish
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv
\the\numexpr #2*(#2+\xint_c_i)\expandafter
!\the\numexpr #1*(#1+\xint_c_i)!%
}%
\def\XINT_binom_vsmallend_ #1.%
{%
\ifnum #1>29 \expandafter\XINT_binom_end_ \else
\expandafter\XINT_binom_vsmallend_b \fi #1.%
}%
\def\XINT_binom_vsmallend_b #1.#2.#3.%
{%
\expandafter\XINT_binom_vsmallfinish
\the\numexpr\XINT_binom_vsmallmuldiv #2!#1!%
}%
\edef\XINT_binom_vsmallfinish 1#1!1!\Z!0!%
{\noexpand\expandafter\space\noexpand\the\numexpr #1\relax}%
% \end{macrocode}
% \subsection{\csh{xintiiPFactorial}, \csh{xintiPFactorial}}
% \lverb?2015/11/29 for 1.2f. Partial factorial pfac(a,b)=(a+1)...b, only for
% non-negative integers with a<=b<10^8.
%
% 1.2h (2016/11/20) removes the non-negativity condition. It was a bit
% unfortunate that the code raised \xintError:OutOfRangePFac if 0<=a<=b<10^8
% was violated. The rule now applied is to interpret pfac(a,b) as the product
% for a<j<=b (not as a ratio of Gamma function), hence if a>=b, return 1
% because of an empty product. If a<b: if a<0, return 0 for b>=0 and
% (-1)^(b-a) times |b|...(|a|-1) for b<0. But only for the range 0<=
% a <= b < 10^8 is the macro result to be considered as stable.?
% \begin{macrocode}
\def\xintiiPFactorial {\romannumeral0\xintiipfactorial }%
\def\xintiipfactorial #1#2%
{%
\expandafter\XINT_pfac_fork\the\numexpr#1\expandafter.\the\numexpr #2.%
}%
\def\xintiPFactorial{\romannumeral0\xintipfactorial}%
\let\xintipfactorial\xintiipfactorial
% \end{macrocode}
% \lverb|Code is a simplified version of the one for \xintiiBinomial, with no
% attempt at implementing a "very small" branch.|
% \begin{macrocode}
\def\XINT_pfac_fork #1#2.#3#4.%
{%
\unless\ifnum #1#2<#3#4 \xint_dothis\XINT_pfac_one\fi
\if-#3\xint_dothis\XINT_pfac_neg\fi
\if-#1\xint_dothis\XINT_pfac_zero\fi
\ifnum #3#4>\xint_c_x^viii_mone\xint_dothis\XINT_pfac_outofrange\fi
\xint_orthat \XINT_pfac_a #1#2.#3#4.%
}%
\def\XINT_pfac_outofrange #1.#2.{\xintError:OutOfRangePFac\space 0}%
\def\XINT_pfac_one #1.#2.{ 1}%
\def\XINT_pfac_zero #1.#2.{ 0}%
\def\XINT_pfac_neg -#1.-#2.%
{%
\ifnum #1>\xint_c_x^viii\xint_dothis\XINT_pfac_outofrange\fi
\xint_orthat
{\ifodd\numexpr#2-#1\relax\xint_afterfi{\expandafter-\romannumeral`&&@}\fi
\expandafter\XINT_pfac_a }%
\the\numexpr #2-\xint_c_i\expandafter.\the\numexpr#1-\xint_c_i.%
}%
\def\XINT_pfac_a #1.#2.%
{%
\expandafter\XINT_pfac_b\the\numexpr \xint_c_i+#1.#2.100000001!1\Z!%
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\XINT_pfac_b #1.%
{%
\ifnum #1>9999 \xint_dothis\XINT_pfac_vbigloop \fi
\ifnum #1>463 \xint_dothis\XINT_pfac_bigloop \fi
\ifnum #1>98 \xint_dothis\XINT_pfac_medloop \fi
\xint_orthat\XINT_pfac_smallloop #1.%
}%
\def\XINT_pfac_smallloop #1.#2.%
{%
\ifcase\numexpr #2-#1\relax
\expandafter\XINT_pfac_end_
\or \expandafter\XINT_pfac_end_i
\or \expandafter\XINT_pfac_end_ii
\or \expandafter\XINT_pfac_end_iii
\else\expandafter\XINT_pfac_smallloop_a
\fi #1.#2.%
}%
\def\XINT_pfac_smallloop_a #1.#2.%
{%
\expandafter\XINT_pfac_smallloop_b
\the\numexpr #1+\xint_c_iv\expandafter.%
\the\numexpr #2\expandafter.%
\the\numexpr\expandafter\XINT_smallmul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_pfac_smallloop_b #1.%
{%
\ifnum #1>98 \expandafter\XINT_pfac_medloop \else
\expandafter\XINT_pfac_smallloop \fi #1.%
}%
\def\XINT_pfac_medloop #1.#2.%
{%
\ifcase\numexpr #2-#1\relax
\expandafter\XINT_pfac_end_
\or \expandafter\XINT_pfac_end_i
\or \expandafter\XINT_pfac_end_ii
\else\expandafter\XINT_pfac_medloop_a
\fi #1.#2.%
}%
\def\XINT_pfac_medloop_a #1.#2.%
{%
\expandafter\XINT_pfac_medloop_b
\the\numexpr #1+\xint_c_iii\expandafter.%
\the\numexpr #2\expandafter.%
\the\numexpr\expandafter\XINT_smallmul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_pfac_medloop_b #1.%
{%
\ifnum #1>463 \expandafter\XINT_pfac_bigloop \else
\expandafter\XINT_pfac_medloop \fi #1.%
}%
\def\XINT_pfac_bigloop #1.#2.%
{%
\ifcase\numexpr #2-#1\relax
\expandafter\XINT_pfac_end_
\or \expandafter\XINT_pfac_end_i
\else\expandafter\XINT_pfac_bigloop_a
\fi #1.#2.%
}%
\def\XINT_pfac_bigloop_a #1.#2.%
{%
\expandafter\XINT_pfac_bigloop_b
\the\numexpr #1+\xint_c_ii\expandafter.%
\the\numexpr #2\expandafter.%
\the\numexpr\expandafter
\XINT_smallmul\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!%
}%
\def\XINT_pfac_bigloop_b #1.%
{%
\ifnum #1>9999 \expandafter\XINT_pfac_vbigloop \else
\expandafter\XINT_pfac_bigloop \fi #1.%
}%
\def\XINT_pfac_vbigloop #1.#2.%
{%
\ifnum #2=#1
\expandafter\XINT_pfac_end_
\else\expandafter\XINT_pfac_vbigloop_a
\fi #1.#2.%
}%
\def\XINT_pfac_vbigloop_a #1.#2.%
{%
\expandafter\XINT_pfac_vbigloop
\the\numexpr #1+\xint_c_i\expandafter.%
\the\numexpr #2\expandafter.%
\the\numexpr\expandafter\XINT_smallmul\the\numexpr\xint_c_x^viii+#1!%
}%
\def\XINT_pfac_end_iii #1.#2.%
{%
\expandafter\XINT_mul_out
\the\numexpr\expandafter\XINT_smallmul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_pfac_end_ii #1.#2.%
{%
\expandafter\XINT_mul_out
\the\numexpr\expandafter\XINT_smallmul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_pfac_end_i #1.#2.%
{%
\expandafter\XINT_mul_out
\the\numexpr\expandafter\XINT_smallmul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!%
}%
\def\XINT_pfac_end_ #1.#2.%
{%
\expandafter\XINT_mul_out
\the\numexpr\expandafter\XINT_smallmul\the\numexpr \xint_c_x^viii+#1!%
}%
% \end{macrocode}
% \subsection{\csh{xintiiE}}
% \lverb|Originally was used in \xintiiexpr. Transferred from xintfrac for 1.1.|
% \begin{macrocode}
\def\xintiiE {\romannumeral0\xintiie }% used in \xintMod.
\def\xintiie #1#2%
{\expandafter\XINT_iie\the\numexpr #2\expandafter.\expandafter{\romannumeral`&&@#1}}%
\def\XINT_iie #1.#2{\ifnum#1>\xint_c_ \xint_dothis{\xint_dsh {#2}{-#1}}\fi
\xint_orthat{ #2}}%
% \end{macrocode}
% \subsection{``Load \xintfracnameimp'' macros}
% \lverb|Originally was used in \xintiiexpr. Transferred from xintfrac for 1.1.|
% \begin{macrocode}
\catcode`! 11
\def\xintMax {\Did_you_mean_iiMax?or_load_xintfrac!}%
\def\xintMin {\Did_you_mean_iiMin?or_load_xintfrac!}%
\def\xintMaxof {\Did_you_mean_iMaxof?or_load_xintfrac!}%
\def\xintMinof {\Did_you_mean_iMinof?or_load_xintfrac!}%
\def\xintSum {\Did_you_mean_iiSum?or_load_xintfrac!}%
\def\xintPrd {\Did_you_mean_iiPrd?or_load_xintfrac!}%
\def\xintPrdExpr {\Did_you_mean_iiPrdExpr?or_load_xintfrac!}%
\def\xintSumExpr {\Did_you_mean_iiSumExpr?or_load_xintfrac!}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xint}
%
%\gardesactifs
%\let</xint>\relax
%\let<*xintbinhex>\gardesinactifs
%</xint>^^A-------------------------------------------------------
%<*xintbinhex>^^A-------------------------------------------------
% \clearpage
% \section{Package \xintbinhexnameimp implementation}
% \label{sec:binheximp}
%
% \localtableofcontents
%
% The commenting is currently (\xintdocdate) very sparse.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xintbinhex.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintcore.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintbinhex}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintbinhex.sty
\ifx\w\relax % but xintcore.sty not yet loaded.
\def\z{\endgroup\input xintcore.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintcore.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintcore}}%
\fi
\else
\aftergroup\endinput % xintbinhex already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintbinhex}%
[2016/11/20 1.2h Expandable binary and hexadecimal conversions (JFB)]%
% \end{macrocode}
% \subsection{Constants, etc...}
% \lverb!1.08!
% \begin{macrocode}
\newcount\xint_c_ii^xv \xint_c_ii^xv 32768
\newcount\xint_c_ii^xvi \xint_c_ii^xvi 65536
\newcount\xint_c_x^v \xint_c_x^v 100000
\def\XINT_tmpa #1{\ifx\relax#1\else
\expandafter\edef\csname XINT_sdth_#1\endcsname
{\ifcase #1 0\or 1\or 2\or 3\or 4\or 5\or 6\or 7\or
8\or 9\or A\or B\or C\or D\or E\or F\fi}%
\expandafter\XINT_tmpa\fi }%
\XINT_tmpa {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}\relax
\def\XINT_tmpa #1{\ifx\relax#1\else
\expandafter\edef\csname XINT_sdtb_#1\endcsname
{\ifcase #1
0000\or 0001\or 0010\or 0011\or 0100\or 0101\or 0110\or 0111\or
1000\or 1001\or 1010\or 1011\or 1100\or 1101\or 1110\or 1111\fi}%
\expandafter\XINT_tmpa\fi }%
\XINT_tmpa {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}\relax
\let\XINT_tmpa\relax
\expandafter\def\csname XINT_sbtd_0000\endcsname {0}%
\expandafter\def\csname XINT_sbtd_0001\endcsname {1}%
\expandafter\def\csname XINT_sbtd_0010\endcsname {2}%
\expandafter\def\csname XINT_sbtd_0011\endcsname {3}%
\expandafter\def\csname XINT_sbtd_0100\endcsname {4}%
\expandafter\def\csname XINT_sbtd_0101\endcsname {5}%
\expandafter\def\csname XINT_sbtd_0110\endcsname {6}%
\expandafter\def\csname XINT_sbtd_0111\endcsname {7}%
\expandafter\def\csname XINT_sbtd_1000\endcsname {8}%
\expandafter\def\csname XINT_sbtd_1001\endcsname {9}%
\expandafter\def\csname XINT_sbtd_1010\endcsname {10}%
\expandafter\def\csname XINT_sbtd_1011\endcsname {11}%
\expandafter\def\csname XINT_sbtd_1100\endcsname {12}%
\expandafter\def\csname XINT_sbtd_1101\endcsname {13}%
\expandafter\def\csname XINT_sbtd_1110\endcsname {14}%
\expandafter\def\csname XINT_sbtd_1111\endcsname {15}%
\expandafter\let\csname XINT_sbth_0000\expandafter\endcsname
\csname XINT_sbtd_0000\endcsname
\expandafter\let\csname XINT_sbth_0001\expandafter\endcsname
\csname XINT_sbtd_0001\endcsname
\expandafter\let\csname XINT_sbth_0010\expandafter\endcsname
\csname XINT_sbtd_0010\endcsname
\expandafter\let\csname XINT_sbth_0011\expandafter\endcsname
\csname XINT_sbtd_0011\endcsname
\expandafter\let\csname XINT_sbth_0100\expandafter\endcsname
\csname XINT_sbtd_0100\endcsname
\expandafter\let\csname XINT_sbth_0101\expandafter\endcsname
\csname XINT_sbtd_0101\endcsname
\expandafter\let\csname XINT_sbth_0110\expandafter\endcsname
\csname XINT_sbtd_0110\endcsname
\expandafter\let\csname XINT_sbth_0111\expandafter\endcsname
\csname XINT_sbtd_0111\endcsname
\expandafter\let\csname XINT_sbth_1000\expandafter\endcsname
\csname XINT_sbtd_1000\endcsname
\expandafter\let\csname XINT_sbth_1001\expandafter\endcsname
\csname XINT_sbtd_1001\endcsname
\expandafter\def\csname XINT_sbth_1010\endcsname {A}%
\expandafter\def\csname XINT_sbth_1011\endcsname {B}%
\expandafter\def\csname XINT_sbth_1100\endcsname {C}%
\expandafter\def\csname XINT_sbth_1101\endcsname {D}%
\expandafter\def\csname XINT_sbth_1110\endcsname {E}%
\expandafter\def\csname XINT_sbth_1111\endcsname {F}%
\expandafter\def\csname XINT_shtb_0\endcsname {0000}%
\expandafter\def\csname XINT_shtb_1\endcsname {0001}%
\expandafter\def\csname XINT_shtb_2\endcsname {0010}%
\expandafter\def\csname XINT_shtb_3\endcsname {0011}%
\expandafter\def\csname XINT_shtb_4\endcsname {0100}%
\expandafter\def\csname XINT_shtb_5\endcsname {0101}%
\expandafter\def\csname XINT_shtb_6\endcsname {0110}%
\expandafter\def\csname XINT_shtb_7\endcsname {0111}%
\expandafter\def\csname XINT_shtb_8\endcsname {1000}%
\expandafter\def\csname XINT_shtb_9\endcsname {1001}%
\def\XINT_shtb_A {1010}%
\def\XINT_shtb_B {1011}%
\def\XINT_shtb_C {1100}%
\def\XINT_shtb_D {1101}%
\def\XINT_shtb_E {1110}%
\def\XINT_shtb_F {1111}%
\def\XINT_shtb_G {}%
\def\XINT_smallhex #1%
{%
\expandafter\XINT_smallhex_a\expandafter
{\the\numexpr (#1+\xint_c_viii)/\xint_c_xvi-\xint_c_i}{#1}%
}%
\def\XINT_smallhex_a #1#2%
{%
\csname XINT_sdth_#1\expandafter\expandafter\expandafter\endcsname
\csname XINT_sdth_\the\numexpr #2-\xint_c_xvi*#1\endcsname
}%
\def\XINT_smallbin #1%
{%
\expandafter\XINT_smallbin_a\expandafter
{\the\numexpr (#1+\xint_c_viii)/\xint_c_xvi-\xint_c_i}{#1}%
}%
\def\XINT_smallbin_a #1#2%
{%
\csname XINT_sdtb_#1\expandafter\expandafter\expandafter\endcsname
\csname XINT_sdtb_\the\numexpr #2-\xint_c_xvi*#1\endcsname
}%
% \end{macrocode}
% \subsection{\csh{XINT_OQ}}
% \lverb|Moved with release 1.2 from xintcore 1.1 as it is used only here.
% Will be probably suppressed once I review the code of xintbinhex.|
% \begin{macrocode}
\def\XINT_OQ #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_OQ_end_a\R\XINT_OQ {#9#8#7#6#5#4#3#2#1}%
}%
\def\XINT_OQ_end_a\R\XINT_OQ #1#2\Z
{%
\XINT_OQ_end_b #1\Z
}%
\def\XINT_OQ_end_b #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_R
#8\XINT_OQ_end_viii
#7\XINT_OQ_end_vii
#6\XINT_OQ_end_vi
#5\XINT_OQ_end_v
#4\XINT_OQ_end_iv
#3\XINT_OQ_end_iii
#2\XINT_OQ_end_ii
\R\XINT_OQ_end_i
\Z #2#3#4#5#6#7#8%
}%
\def\XINT_OQ_end_viii #1\Z #2#3#4#5#6#7#8#9\Z { #9}%
\def\XINT_OQ_end_vii #1\Z #2#3#4#5#6#7#8#9\Z { #8#90000000}%
\def\XINT_OQ_end_vi #1\Z #2#3#4#5#6#7#8#9\Z { #7#8#9000000}%
\def\XINT_OQ_end_v #1\Z #2#3#4#5#6#7#8#9\Z { #6#7#8#900000}%
\def\XINT_OQ_end_iv #1\Z #2#3#4#5#6#7#8#9\Z { #5#6#7#8#90000}%
\def\XINT_OQ_end_iii #1\Z #2#3#4#5#6#7#8#9\Z { #4#5#6#7#8#9000}%
\def\XINT_OQ_end_ii #1\Z #2#3#4#5#6#7#8#9\Z { #3#4#5#6#7#8#900}%
\def\XINT_OQ_end_i \Z #1#2#3#4#5#6#7#8\Z { #1#2#3#4#5#6#7#80}%
% \end{macrocode}
% \subsection{\csh{xintDecToHex}, \csh{xintDecToBin}}
% \lverb!1.08!
% \begin{macrocode}
\def\xintDecToHex {\romannumeral0\xintdectohex }%
\def\xintdectohex #1%
{\expandafter\XINT_dth_checkin\romannumeral`&&@#1\W\W\W\W \T}%
\def\XINT_dth_checkin #1%
{%
\xint_UDsignfork
#1\XINT_dth_N
-{\XINT_dth_P #1}%
\krof
}%
\def\XINT_dth_N {\expandafter-\romannumeral0\XINT_dth_P }%
\def\XINT_dth_P {\expandafter\XINT_dth_III\romannumeral`&&@\XINT_dtbh_I {0.}}%
\def\xintDecToBin {\romannumeral0\xintdectobin }%
\def\xintdectobin #1%
{\expandafter\XINT_dtb_checkin\romannumeral`&&@#1\W\W\W\W \T }%
\def\XINT_dtb_checkin #1%
{%
\xint_UDsignfork
#1\XINT_dtb_N
-{\XINT_dtb_P #1}%
\krof
}%
\def\XINT_dtb_N {\expandafter-\romannumeral0\XINT_dtb_P }%
\def\XINT_dtb_P {\expandafter\XINT_dtb_III\romannumeral`&&@\XINT_dtbh_I {0.}}%
\def\XINT_dtbh_I #1#2#3#4#5%
{%
\xint_gob_til_W #5\XINT_dtbh_II_a\W\XINT_dtbh_I_a {}{#2#3#4#5}#1\Z.%
}%
\def\XINT_dtbh_II_a\W\XINT_dtbh_I_a #1#2{\XINT_dtbh_II_b #2}%
\def\XINT_dtbh_II_b #1#2#3#4%
{%
\xint_gob_til_W
#1\XINT_dtbh_II_c
#2\XINT_dtbh_II_ci
#3\XINT_dtbh_II_cii
\W\XINT_dtbh_II_ciii #1#2#3#4%
}%
\def\XINT_dtbh_II_c \W\XINT_dtbh_II_ci
\W\XINT_dtbh_II_cii
\W\XINT_dtbh_II_ciii \W\W\W\W {{}}%
\def\XINT_dtbh_II_ci #1\XINT_dtbh_II_ciii #2\W\W\W
{\XINT_dtbh_II_d {}{#2}{0}}%
\def\XINT_dtbh_II_cii\W\XINT_dtbh_II_ciii #1#2\W\W
{\XINT_dtbh_II_d {}{#1#2}{00}}%
\def\XINT_dtbh_II_ciii #1#2#3\W
{\XINT_dtbh_II_d {}{#1#2#3}{000}}%
\def\XINT_dtbh_I_a #1#2#3.%
{%
\xint_gob_til_Z #3\XINT_dtbh_I_z\Z
\expandafter\XINT_dtbh_I_b\the\numexpr #2+#30000.{#1}%
}%
\def\XINT_dtbh_I_b #1.%
{%
\expandafter\XINT_dtbh_I_c\the\numexpr
(#1+\xint_c_ii^xv)/\xint_c_ii^xvi-\xint_c_i.#1.%
}%
\def\XINT_dtbh_I_c #1.#2.%
{%
\expandafter\XINT_dtbh_I_d\expandafter
{\the\numexpr #2-\xint_c_ii^xvi*#1}{#1}%
}%
\def\XINT_dtbh_I_d #1#2#3{\XINT_dtbh_I_a {#3#1.}{#2}}%
\def\XINT_dtbh_I_z\Z\expandafter\XINT_dtbh_I_b\the\numexpr #1+#2.%
{%
\ifnum #1=\xint_c_ \expandafter\XINT_dtbh_I_end_zb\fi
\XINT_dtbh_I_end_za {#1}%
}%
\def\XINT_dtbh_I_end_za #1#2{\XINT_dtbh_I {#2#1.}}%
\def\XINT_dtbh_I_end_zb\XINT_dtbh_I_end_za #1#2{\XINT_dtbh_I {#2}}%
\def\XINT_dtbh_II_d #1#2#3#4.%
{%
\xint_gob_til_Z #4\XINT_dtbh_II_z\Z
\expandafter\XINT_dtbh_II_e\the\numexpr #2+#4#3.{#1}{#3}%
}%
\def\XINT_dtbh_II_e #1.%
{%
\expandafter\XINT_dtbh_II_f\the\numexpr
(#1+\xint_c_ii^xv)/\xint_c_ii^xvi-\xint_c_i.#1.%
}%
\def\XINT_dtbh_II_f #1.#2.%
{%
\expandafter\XINT_dtbh_II_g\expandafter
{\the\numexpr #2-\xint_c_ii^xvi*#1}{#1}%
}%
\def\XINT_dtbh_II_g #1#2#3{\XINT_dtbh_II_d {#3#1.}{#2}}%
\def\XINT_dtbh_II_z\Z\expandafter\XINT_dtbh_II_e\the\numexpr #1+#2.%
{%
\ifnum #1=\xint_c_ \expandafter\XINT_dtbh_II_end_zb\fi
\XINT_dtbh_II_end_za {#1}%
}%
\def\XINT_dtbh_II_end_za #1#2#3{{}#2#1.\Z.}%
\def\XINT_dtbh_II_end_zb\XINT_dtbh_II_end_za #1#2#3{{}#2\Z.}%
\def\XINT_dth_III #1#2.%
{%
\xint_gob_til_Z #2\XINT_dth_end\Z
\expandafter\XINT_dth_III\expandafter
{\romannumeral`&&@\XINT_dth_small #2.#1}%
}%
\def\XINT_dth_small #1.%
{%
\expandafter\XINT_smallhex\expandafter
{\the\numexpr (#1+\xint_c_ii^vii)/\xint_c_ii^viii-\xint_c_i\expandafter}%
\romannumeral`&&@\expandafter\XINT_smallhex\expandafter
{\the\numexpr
#1-((#1+\xint_c_ii^vii)/\xint_c_ii^viii-\xint_c_i)*\xint_c_ii^viii}%
}%
\def\XINT_dth_end\Z\expandafter\XINT_dth_III\expandafter #1#2\T
{%
\XINT_dth_end_b #1%
}%
\def\XINT_dth_end_b #1.{\XINT_dth_end_c }%
\def\XINT_dth_end_c #1{\xint_gob_til_zero #1\XINT_dth_end_d 0\space #1}%
\def\XINT_dth_end_d 0\space 0#1%
{%
\xint_gob_til_zero #1\XINT_dth_end_e 0\space #1%
}%
\def\XINT_dth_end_e 0\space 0#1%
{%
\xint_gob_til_zero #1\XINT_dth_end_f 0\space #1%
}%
\def\XINT_dth_end_f 0\space 0{ }%
\def\XINT_dtb_III #1#2.%
{%
\xint_gob_til_Z #2\XINT_dtb_end\Z
\expandafter\XINT_dtb_III\expandafter
{\romannumeral`&&@\XINT_dtb_small #2.#1}%
}%
\def\XINT_dtb_small #1.%
{%
\expandafter\XINT_smallbin\expandafter
{\the\numexpr (#1+\xint_c_ii^vii)/\xint_c_ii^viii-\xint_c_i\expandafter}%
\romannumeral`&&@\expandafter\XINT_smallbin\expandafter
{\the\numexpr
#1-((#1+\xint_c_ii^vii)/\xint_c_ii^viii-\xint_c_i)*\xint_c_ii^viii}%
}%
\def\XINT_dtb_end\Z\expandafter\XINT_dtb_III\expandafter #1#2\T
{%
\XINT_dtb_end_b #1%
}%
\def\XINT_dtb_end_b #1.{\XINT_dtb_end_c }%
\def\XINT_dtb_end_c #1#2#3#4#5#6#7#8%
{%
\expandafter\XINT_dtb_end_d\the\numexpr #1#2#3#4#5#6#7#8\relax
}%
\edef\XINT_dtb_end_d #1#2#3#4#5#6#7#8#9%
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8#9\relax
}%
% \end{macrocode}
% \subsection{\csh{xintHexToDec}}
% \lverb!1.08!
% \begin{macrocode}
\def\xintHexToDec {\romannumeral0\xinthextodec }%
\def\xinthextodec #1%
{\expandafter\XINT_htd_checkin\romannumeral`&&@#1\W\W\W\W \T }%
\def\XINT_htd_checkin #1%
{%
\xint_UDsignfork
#1\XINT_htd_neg
-{\XINT_htd_I {0000}#1}%
\krof
}%
\def\XINT_htd_neg {\expandafter-\romannumeral0\XINT_htd_I {0000}}%
\def\XINT_htd_I #1#2#3#4#5%
{%
\xint_gob_til_W #5\XINT_htd_II_a\W
\XINT_htd_I_a {}{"#2#3#4#5}#1\Z\Z\Z\Z
}%
\def\XINT_htd_II_a \W\XINT_htd_I_a #1#2{\XINT_htd_II_b #2}%
\def\XINT_htd_II_b "#1#2#3#4%
{%
\xint_gob_til_W
#1\XINT_htd_II_c
#2\XINT_htd_II_ci
#3\XINT_htd_II_cii
\W\XINT_htd_II_ciii #1#2#3#4%
}%
\def\XINT_htd_II_c \W\XINT_htd_II_ci
\W\XINT_htd_II_cii
\W\XINT_htd_II_ciii \W\W\W\W #1\Z\Z\Z\Z\T
{%
\expandafter\xint_cleanupzeros_andstop
\romannumeral0\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
}%
\def\XINT_htd_II_ci #1\XINT_htd_II_ciii
#2\W\W\W {\XINT_htd_II_d {}{"#2}{\xint_c_xvi}}%
\def\XINT_htd_II_cii\W\XINT_htd_II_ciii
#1#2\W\W {\XINT_htd_II_d {}{"#1#2}{\xint_c_ii^viii}}%
\def\XINT_htd_II_ciii #1#2#3\W {\XINT_htd_II_d {}{"#1#2#3}{\xint_c_ii^xii}}%
\def\XINT_htd_I_a #1#2#3#4#5#6%
{%
\xint_gob_til_Z #3\XINT_htd_I_end_a\Z
\expandafter\XINT_htd_I_b\the\numexpr
#2+\xint_c_ii^xvi*#6#5#4#3+\xint_c_x^ix\relax {#1}%
}%
\def\XINT_htd_I_b 1#1#2#3#4#5#6#7#8#9{\XINT_htd_I_c {#1#2#3#4#5}{#9#8#7#6}}%
\def\XINT_htd_I_c #1#2#3{\XINT_htd_I_a {#3#2}{#1}}%
\def\XINT_htd_I_end_a\Z\expandafter\XINT_htd_I_b\the\numexpr #1+#2\relax
{%
\expandafter\XINT_htd_I_end_b\the\numexpr \xint_c_x^v+#1\relax
}%
\def\XINT_htd_I_end_b 1#1#2#3#4#5%
{%
\xint_gob_til_zero #1\XINT_htd_I_end_bz0%
\XINT_htd_I_end_c #1#2#3#4#5%
}%
\def\XINT_htd_I_end_c #1#2#3#4#5#6{\XINT_htd_I {#6#5#4#3#2#1000}}%
\def\XINT_htd_I_end_bz0\XINT_htd_I_end_c 0#1#2#3#4%
{%
\xint_gob_til_zeros_iv #1#2#3#4\XINT_htd_I_end_bzz 0000%
\XINT_htd_I_end_D {#4#3#2#1}%
}%
\def\XINT_htd_I_end_D #1#2{\XINT_htd_I {#2#1}}%
\def\XINT_htd_I_end_bzz 0000\XINT_htd_I_end_D #1{\XINT_htd_I }%
\def\XINT_htd_II_d #1#2#3#4#5#6#7%
{%
\xint_gob_til_Z #4\XINT_htd_II_end_a\Z
\expandafter\XINT_htd_II_e\the\numexpr
#2+#3*#7#6#5#4+\xint_c_x^viii\relax {#1}{#3}%
}%
\def\XINT_htd_II_e 1#1#2#3#4#5#6#7#8{\XINT_htd_II_f {#1#2#3#4}{#5#6#7#8}}%
\def\XINT_htd_II_f #1#2#3{\XINT_htd_II_d {#2#3}{#1}}%
\def\XINT_htd_II_end_a\Z\expandafter\XINT_htd_II_e
\the\numexpr #1+#2\relax #3#4\T
{%
\XINT_htd_II_end_b #1#3%
}%
\edef\XINT_htd_II_end_b #1#2#3#4#5#6#7#8%
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8\relax
}%
% \end{macrocode}
% \subsection{\csh{xintBinToDec}}
% \lverb!1.08!
% \begin{macrocode}
\def\xintBinToDec {\romannumeral0\xintbintodec }%
\def\xintbintodec #1{\expandafter\XINT_btd_checkin
\romannumeral`&&@#1\W\W\W\W\W\W\W\W \T }%
\def\XINT_btd_checkin #1%
{%
\xint_UDsignfork
#1\XINT_btd_neg
-{\XINT_btd_I {000000}#1}%
\krof
}%
\def\XINT_btd_neg {\expandafter-\romannumeral0\XINT_btd_I {000000}}%
\def\XINT_btd_I #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_W #9\XINT_btd_II_a {#2#3#4#5#6#7#8#9}\W
\XINT_btd_I_a {}{\csname XINT_sbtd_#2#3#4#5\endcsname*\xint_c_xvi+%
\csname XINT_sbtd_#6#7#8#9\endcsname}%
#1\Z\Z\Z\Z\Z\Z
}%
\def\XINT_btd_II_a #1\W\XINT_btd_I_a #2#3{\XINT_btd_II_b #1}%
\def\XINT_btd_II_b #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_W
#1\XINT_btd_II_c
#2\XINT_btd_II_ci
#3\XINT_btd_II_cii
#4\XINT_btd_II_ciii
#5\XINT_btd_II_civ
#6\XINT_btd_II_cv
#7\XINT_btd_II_cvi
\W\XINT_btd_II_cvii #1#2#3#4#5#6#7#8%
}%
\def\XINT_btd_II_c #1\XINT_btd_II_cvii \W\W\W\W\W\W\W\W #2\Z\Z\Z\Z\Z\Z\T
{%
\expandafter\XINT_btd_II_c_end
\romannumeral0\XINT_rord_main {}#2%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
}%
\edef\XINT_btd_II_c_end #1#2#3#4#5#6%
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6\relax
}%
\def\XINT_btd_II_ci #1\XINT_btd_II_cvii #2\W\W\W\W\W\W\W
{\XINT_btd_II_d {}{#2}{\xint_c_ii }}%
\def\XINT_btd_II_cii #1\XINT_btd_II_cvii #2\W\W\W\W\W\W
{\XINT_btd_II_d {}{\csname XINT_sbtd_00#2\endcsname }{\xint_c_iv }}%
\def\XINT_btd_II_ciii #1\XINT_btd_II_cvii #2\W\W\W\W\W
{\XINT_btd_II_d {}{\csname XINT_sbtd_0#2\endcsname }{\xint_c_viii }}%
\def\XINT_btd_II_civ #1\XINT_btd_II_cvii #2\W\W\W\W
{\XINT_btd_II_d {}{\csname XINT_sbtd_#2\endcsname}{\xint_c_xvi }}%
\def\XINT_btd_II_cv #1\XINT_btd_II_cvii #2#3#4#5#6\W\W\W
{%
\XINT_btd_II_d {}{\csname XINT_sbtd_#2#3#4#5\endcsname*\xint_c_ii+%
#6}{\xint_c_ii^v }%
}%
\def\XINT_btd_II_cvi #1\XINT_btd_II_cvii #2#3#4#5#6#7\W\W
{%
\XINT_btd_II_d {}{\csname XINT_sbtd_#2#3#4#5\endcsname*\xint_c_iv+%
\csname XINT_sbtd_00#6#7\endcsname}{\xint_c_ii^vi }%
}%
\def\XINT_btd_II_cvii #1#2#3#4#5#6#7\W
{%
\XINT_btd_II_d {}{\csname XINT_sbtd_#1#2#3#4\endcsname*\xint_c_viii+%
\csname XINT_sbtd_0#5#6#7\endcsname}{\xint_c_ii^vii }%
}%
\def\XINT_btd_II_d #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_Z #4\XINT_btd_II_end_a\Z
\expandafter\XINT_btd_II_e\the\numexpr
#2+(\xint_c_x^ix+#3*#9#8#7#6#5#4)\relax {#1}{#3}%
}%
\def\XINT_btd_II_e 1#1#2#3#4#5#6#7#8#9{\XINT_btd_II_f {#1#2#3}{#4#5#6#7#8#9}}%
\def\XINT_btd_II_f #1#2#3{\XINT_btd_II_d {#2#3}{#1}}%
\def\XINT_btd_II_end_a\Z\expandafter\XINT_btd_II_e
\the\numexpr #1+(#2\relax #3#4\T
{%
\XINT_btd_II_end_b #1#3%
}%
\edef\XINT_btd_II_end_b #1#2#3#4#5#6#7#8#9%
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8#9\relax
}%
\def\XINT_btd_I_a #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_Z #3\XINT_btd_I_end_a\Z
\expandafter\XINT_btd_I_b\the\numexpr
#2+\xint_c_ii^viii*#8#7#6#5#4#3+\xint_c_x^ix\relax {#1}%
}%
\def\XINT_btd_I_b 1#1#2#3#4#5#6#7#8#9{\XINT_btd_I_c {#1#2#3}{#9#8#7#6#5#4}}%
\def\XINT_btd_I_c #1#2#3{\XINT_btd_I_a {#3#2}{#1}}%
\def\XINT_btd_I_end_a\Z\expandafter\XINT_btd_I_b
\the\numexpr #1+\xint_c_ii^viii #2\relax
{%
\expandafter\XINT_btd_I_end_b\the\numexpr 1000+#1\relax
}%
\def\XINT_btd_I_end_b 1#1#2#3%
{%
\xint_gob_til_zeros_iii #1#2#3\XINT_btd_I_end_bz 000%
\XINT_btd_I_end_c #1#2#3%
}%
\def\XINT_btd_I_end_c #1#2#3#4{\XINT_btd_I {#4#3#2#1000}}%
\def\XINT_btd_I_end_bz 000\XINT_btd_I_end_c 000{\XINT_btd_I }%
% \end{macrocode}
% \subsection{\csh{xintBinToHex}}
% \lverb!1.08!
% \begin{macrocode}
\def\xintBinToHex {\romannumeral0\xintbintohex }%
\def\xintbintohex #1%
{%
\expandafter\XINT_bth_checkin
\romannumeral0\expandafter\XINT_num_loop
\romannumeral`&&@#1\xint_relax\xint_relax
\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z
\R\R\R\R\R\R\R\R\Z \W\W\W\W\W\W\W\W
}%
\def\XINT_bth_checkin #1%
{%
\xint_UDsignfork
#1\XINT_bth_N
-{\XINT_bth_P #1}%
\krof
}%
\def\XINT_bth_N {\expandafter-\romannumeral0\XINT_bth_P }%
\def\XINT_bth_P {\expandafter\XINT_bth_I\expandafter{\expandafter}%
\romannumeral0\XINT_OQ {}}%
\def\XINT_bth_I #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_W #9\XINT_bth_end_a\W
\expandafter\expandafter\expandafter
\XINT_bth_I
\expandafter\expandafter\expandafter
{\csname XINT_sbth_#9#8#7#6\expandafter\expandafter\expandafter\endcsname
\csname XINT_sbth_#5#4#3#2\endcsname #1}%
}%
\def\XINT_bth_end_a\W \expandafter\expandafter\expandafter
\XINT_bth_I \expandafter\expandafter\expandafter #1%
{%
\XINT_bth_end_b #1%
}%
\def\XINT_bth_end_b #1\endcsname #2\endcsname #3%
{%
\xint_gob_til_zero #3\XINT_bth_end_z 0\space #3%
}%
\def\XINT_bth_end_z0\space 0{ }%
% \end{macrocode}
% \subsection{\csh{xintHexToBin}}
% \lverb!1.08!
% \begin{macrocode}
\def\xintHexToBin {\romannumeral0\xinthextobin }%
\def\xinthextobin #1%
{%
\expandafter\XINT_htb_checkin\romannumeral`&&@#1GGGGGGGG\T
}%
\def\XINT_htb_checkin #1%
{%
\xint_UDsignfork
#1\XINT_htb_N
-{\XINT_htb_P #1}%
\krof
}%
\def\XINT_htb_N {\expandafter-\romannumeral0\XINT_htb_P }%
\def\XINT_htb_P {\XINT_htb_I_a {}}%
\def\XINT_htb_I_a #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_G #9\XINT_htb_II_a G%
\expandafter\expandafter\expandafter
\XINT_htb_I_b
\expandafter\expandafter\expandafter
{\csname XINT_shtb_#2\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#3\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#4\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#5\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#6\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#7\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#8\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#9\endcsname }{#1}%
}%
\def\XINT_htb_I_b #1#2{\XINT_htb_I_a {#2#1}}%
\def\XINT_htb_II_a G\expandafter\expandafter\expandafter\XINT_htb_I_b
{%
\expandafter\expandafter\expandafter \XINT_htb_II_b
}%
\def\XINT_htb_II_b #1#2#3\T
{%
\XINT_num_loop #2#1%
\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z
}%
% \end{macrocode}
% \subsection{\csh{xintCHexToBin}}
% \lverb!1.08!
% \begin{macrocode}
\def\xintCHexToBin {\romannumeral0\xintchextobin }%
\def\xintchextobin #1%
{%
\expandafter\XINT_chtb_checkin\romannumeral`&&@#1%
\R\R\R\R\R\R\R\R\Z \W\W\W\W\W\W\W\W
}%
\def\XINT_chtb_checkin #1%
{%
\xint_UDsignfork
#1\XINT_chtb_N
-{\XINT_chtb_P #1}%
\krof
}%
\def\XINT_chtb_N {\expandafter-\romannumeral0\XINT_chtb_P }%
\def\XINT_chtb_P {\expandafter\XINT_chtb_I\expandafter{\expandafter}%
\romannumeral0\XINT_OQ {}}%
\def\XINT_chtb_I #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_W #9\XINT_chtb_end_a\W
\expandafter\expandafter\expandafter
\XINT_chtb_I
\expandafter\expandafter\expandafter
{\csname XINT_shtb_#9\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#8\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#7\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#6\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#5\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#4\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#3\expandafter\expandafter\expandafter\endcsname
\csname XINT_shtb_#2\endcsname
#1}%
}%
\def\XINT_chtb_end_a\W\expandafter\expandafter\expandafter
\XINT_chtb_I\expandafter\expandafter\expandafter #1%
{%
\XINT_chtb_end_b #1%
\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z
}%
\def\XINT_chtb_end_b #1\W#2\W#3\W#4\W#5\W#6\W#7\W#8\W\endcsname
{%
\XINT_num_loop
}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintbinhex}
%
%\gardesactifs
%\let</xintbinhex>\relax
%\let<*xintgcd>\gardesinactifs
%</xintbinhex>^^A-------------------------------------------------
%<*xintgcd>^^A----------------------------------------------------
% \clearpage
% \section{Package \xintgcdnameimp implementation}
% \label{sec:gcdimp}
%
% \localtableofcontents
%
% The commenting is currently (\xintdocdate) very sparse. Release |1.09h| has
% modified a bit the |\xintTypesetEuclideAlgorithm| and
% |\xintTypesetBezoutAlgorithm| layout with respect to line indentation in
% particular. And they use the \xinttoolsnameimp |\xintloop| rather than the
% Plain \TeX{} or \LaTeX{}'s |\loop|.
%
% Since |1.1| the package only loads \xintcorenameimp, not \xintnameimp. And
% for the |\xintTypesetEuclideAlgorithm| and |\xintTypesetBezoutAlgorithm|
% macros to be functional the package \xinttoolsnameimp needs to be loaded
% explicitely by the user.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xintgcd.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintcore.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintgcd}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintgcd.sty
\ifx\w\relax % but xintcore.sty not yet loaded.
\def\z{\endgroup\input xintcore.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintcore.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintcore}}%
\fi
\else
\aftergroup\endinput % xintgcd already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintgcd}%
[2016/11/20 1.2h Euclide algorithm with xint package (JFB)]%
% \end{macrocode}
% \subsection{\csh{xintGCD}, \csh{xintiiGCD}}
% \begin{macrocode}
\def\xintGCD {\romannumeral0\xintgcd }%
\def\xintgcd #1%
{%
\expandafter\XINT_gcd\expandafter{\romannumeral0\xintiabs {#1}}%
}%
\def\XINT_gcd #1#2%
{%
\expandafter\XINT_gcd_fork\romannumeral0\xintiabs {#2}\Z #1\Z
}%
\def\xintiiGCD {\romannumeral0\xintiigcd }%
\def\xintiigcd #1%
{%
\expandafter\XINT_iigcd\expandafter{\romannumeral0\xintiiabs {#1}}%
}%
\def\XINT_iigcd #1#2%
{%
\expandafter\XINT_gcd_fork\romannumeral0\xintiiabs {#2}\Z #1\Z
}%
% \end{macrocode}
% \lverb|&
% Ici #3#4=A, #1#2=B|
% \begin{macrocode}
\def\XINT_gcd_fork #1#2\Z #3#4\Z
{%
\xint_UDzerofork
#1\XINT_gcd_BisZero
#3\XINT_gcd_AisZero
0\XINT_gcd_loop
\krof
{#1#2}{#3#4}%
}%
\def\XINT_gcd_AisZero #1#2{ #1}%
\def\XINT_gcd_BisZero #1#2{ #2}%
\def\XINT_gcd_CheckRem #1#2\Z
{%
\xint_gob_til_zero #1\xint_gcd_end0\XINT_gcd_loop {#1#2}%
}%
\def\xint_gcd_end0\XINT_gcd_loop #1#2{ #2}%
% \end{macrocode}
% \lverb|#1=B, #2=A|
% \begin{macrocode}
\def\XINT_gcd_loop #1#2%
{%
\expandafter\expandafter\expandafter
\XINT_gcd_CheckRem
\expandafter\xint_secondoftwo
\romannumeral0\XINT_div_prepare {#1}{#2}\Z
{#1}%
}%
% \end{macrocode}
% \subsection{\csh{xintLCM}, \csh{xintiiLCM}}
% \begin{macrocode}
\def\xintLCM {\romannumeral0\xintlcm}%
\def\xintlcm #1%
{%
\expandafter\XINT_lcm\expandafter{\romannumeral0\xintiabs {#1}}%
}%
\def\XINT_lcm #1#2%
{%
\expandafter\XINT_lcm_fork\romannumeral0\xintiabs {#2}\Z #1\Z
}%
\def\xintiiLCM {\romannumeral0\xintiilcm}%
\def\xintiilcm #1%
{%
\expandafter\XINT_iilcm\expandafter{\romannumeral0\xintiiabs {#1}}%
}%
\def\XINT_iilcm #1#2%
{%
\expandafter\XINT_lcm_fork\romannumeral0\xintiiabs {#2}\Z #1\Z
}%
\def\XINT_lcm_fork #1#2\Z #3#4\Z
{%
\xint_UDzerofork
#1\XINT_lcm_BisZero
#3\XINT_lcm_AisZero
0\expandafter
\krof
\XINT_lcm_notzero\expandafter{\romannumeral0\XINT_gcd_loop {#1#2}{#3#4}}%
{#1#2}{#3#4}%
}%
\def\XINT_lcm_AisZero #1#2#3#4#5{ 0}%
\def\XINT_lcm_BisZero #1#2#3#4#5{ 0}%
\def\XINT_lcm_notzero #1#2#3{\xintiimul {#2}{\xintiiQuo{#3}{#1}}}%
% \end{macrocode}
% \subsection{\csh{xintBezout}}
% \begin{macrocode}
\def\xintBezout {\romannumeral0\xintbezout }%
\def\xintbezout #1%
{%
\expandafter\xint_bezout\expandafter {\romannumeral0\xintnum{#1}}%
}%
\def\xint_bezout #1#2%
{%
\expandafter\XINT_bezout_fork \romannumeral0\xintnum{#2}\Z #1\Z
}%
% \end{macrocode}
% \lverb|#3#4 = A, #1#2=B|
% \begin{macrocode}
\def\XINT_bezout_fork #1#2\Z #3#4\Z
{%
\xint_UDzerosfork
#1#3\XINT_bezout_botharezero
#10\XINT_bezout_secondiszero
#30\XINT_bezout_firstiszero
00{\xint_UDsignsfork
#1#3\XINT_bezout_minusminus % A < 0, B < 0
#1-\XINT_bezout_minusplus % A > 0, B < 0
#3-\XINT_bezout_plusminus % A < 0, B > 0
--\XINT_bezout_plusplus % A > 0, B > 0
\krof }%
\krof
{#2}{#4}#1#3{#3#4}{#1#2}% #1#2=B, #3#4=A
}%
\edef\XINT_bezout_botharezero #1#2#3#4#5#6%
{%
\noexpand\xintError:NoBezoutForZeros\space {0}{0}{0}{0}{0}%
}%
% \end{macrocode}
% \lverb|&
% attention première entrée doit être ici (-1)^n donc 1$\
% #4#2 = 0 = A, B = #3#1|
% \begin{macrocode}
\def\XINT_bezout_firstiszero #1#2#3#4#5#6%
{%
\xint_UDsignfork
#3{ {0}{#3#1}{0}{1}{#1}}%
-{ {0}{#3#1}{0}{-1}{#1}}%
\krof
}%
% \end{macrocode}
% \lverb|#4#2 = A, B = #3#1 = 0|
% \begin{macrocode}
\def\XINT_bezout_secondiszero #1#2#3#4#5#6%
{%
\xint_UDsignfork
#4{ {#4#2}{0}{-1}{0}{#2}}%
-{ {#4#2}{0}{1}{0}{#2}}%
\krof
}%
% \end{macrocode}
% \lverb|#4#2= A < 0, #3#1 = B < 0|
% \begin{macrocode}
\def\XINT_bezout_minusminus #1#2#3#4%
{%
\expandafter\XINT_bezout_mm_post
\romannumeral0\XINT_bezout_loop_a 1{#1}{#2}1001%
}%
\def\XINT_bezout_mm_post #1#2%
{%
\expandafter\XINT_bezout_mm_postb\expandafter
{\romannumeral0\xintiiopp{#2}}{\romannumeral0\xintiiopp{#1}}%
}%
\def\XINT_bezout_mm_postb #1#2%
{%
\expandafter\XINT_bezout_mm_postc\expandafter {#2}{#1}%
}%
\edef\XINT_bezout_mm_postc #1#2#3#4#5%
{%
\space {#4}{#5}{#1}{#2}{#3}%
}%
% \end{macrocode}
% \lverb|minusplus #4#2= A > 0, B < 0|
% \begin{macrocode}
\def\XINT_bezout_minusplus #1#2#3#4%
{%
\expandafter\XINT_bezout_mp_post
\romannumeral0\XINT_bezout_loop_a 1{#1}{#4#2}1001%
}%
\def\XINT_bezout_mp_post #1#2%
{%
\expandafter\XINT_bezout_mp_postb\expandafter
{\romannumeral0\xintiiopp {#2}}{#1}%
}%
\edef\XINT_bezout_mp_postb #1#2#3#4#5%
{%
\space {#4}{#5}{#2}{#1}{#3}%
}%
% \end{macrocode}
% \lverb|plusminus A < 0, B > 0|
% \begin{macrocode}
\def\XINT_bezout_plusminus #1#2#3#4%
{%
\expandafter\XINT_bezout_pm_post
\romannumeral0\XINT_bezout_loop_a 1{#3#1}{#2}1001%
}%
\def\XINT_bezout_pm_post #1%
{%
\expandafter \XINT_bezout_pm_postb \expandafter
{\romannumeral0\xintiiopp{#1}}%
}%
\edef\XINT_bezout_pm_postb #1#2#3#4#5%
{%
\space {#4}{#5}{#1}{#2}{#3}%
}%
% \end{macrocode}
% \lverb|plusplus|
% \begin{macrocode}
\def\XINT_bezout_plusplus #1#2#3#4%
{%
\expandafter\XINT_bezout_pp_post
\romannumeral0\XINT_bezout_loop_a 1{#3#1}{#4#2}1001%
}%
% \end{macrocode}
% \lverb|la parité (-1)^N est en #1, et on la jette ici.|
% \begin{macrocode}
\edef\XINT_bezout_pp_post #1#2#3#4#5%
{%
\space {#4}{#5}{#1}{#2}{#3}%
}%
% \end{macrocode}
% \lverb|&
% n = 0: 1BAalpha(0)beta(0)alpha(-1)beta(-1)$\
% n général:
% {(-1)^n}{r(n-1)}{r(n-2)}{alpha(n-1)}{beta(n-1)}{alpha(n-2)}{beta(n-2)}$\
% #2 = B, #3 = A|
% \begin{macrocode}
\def\XINT_bezout_loop_a #1#2#3%
{%
\expandafter\XINT_bezout_loop_b
\expandafter{\the\numexpr -#1\expandafter }%
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}%
}%
% \end{macrocode}
% \lverb|&
% Le q(n) a ici une existence éphémère, dans le version Bezout Algorithm
% il faudra le conserver. On voudra à la fin
% {{q(n)}{r(n)}{alpha(n)}{beta(n)}}.
% De plus ce n'est plus (-1)^n que l'on veut mais n. (ou dans un autre ordre)$\
% {-(-1)^n}{q(n)}{r(n)}{r(n-1)}{alpha(n-1)}{beta(n-1)}{alpha(n-2)}{beta(n-2)}|
% \begin{macrocode}
\def\XINT_bezout_loop_b #1#2#3#4#5#6#7#8%
{%
\expandafter \XINT_bezout_loop_c \expandafter
{\romannumeral0\xintiiadd{\XINT_mul_fork #5\Z #2\Z}{#7}}%
{\romannumeral0\xintiiadd{\XINT_mul_fork #6\Z #2\Z}{#8}}%
{#1}{#3}{#4}{#5}{#6}%
}%
% \end{macrocode}
% \lverb|{alpha(n)}{->beta(n)}{-(-1)^n}{r(n)}{r(n-1)}{alpha(n-1)}{beta(n-1)}|
% \begin{macrocode}
\def\XINT_bezout_loop_c #1#2%
{%
\expandafter \XINT_bezout_loop_d \expandafter
{#2}{#1}%
}%
% \end{macrocode}
% \lverb|{beta(n)}{alpha(n)}{(-1)^(n+1)}{r(n)}{r(n-1)}{alpha(n-1)}{beta(n-1)}|
% \begin{macrocode}
\def\XINT_bezout_loop_d #1#2#3#4#5%
{%
\XINT_bezout_loop_e #4\Z {#3}{#5}{#2}{#1}%
}%
% \end{macrocode}
% \lverb|r(n)\Z {(-1)^(n+1)}{r(n-1)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}|
% \begin{macrocode}
\def\XINT_bezout_loop_e #1#2\Z
{%
\xint_gob_til_zero #1\xint_bezout_loop_exit0\XINT_bezout_loop_f
{#1#2}%
}%
% \end{macrocode}
% \lverb|{r(n)}{(-1)^(n+1)}{r(n-1)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}|
% \begin{macrocode}
\def\XINT_bezout_loop_f #1#2%
{%
\XINT_bezout_loop_a {#2}{#1}%
}%
% \end{macrocode}
% \lverb|{(-1)^(n+1)}{r(n)}{r(n-1)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}
% et itération|
% \begin{macrocode}
\def\xint_bezout_loop_exit0\XINT_bezout_loop_f #1#2%
{%
\ifcase #2
\or \expandafter\XINT_bezout_exiteven
\else\expandafter\XINT_bezout_exitodd
\fi
}%
\edef\XINT_bezout_exiteven #1#2#3#4#5%
{%
\space {#5}{#4}{#1}%
}%
\edef\XINT_bezout_exitodd #1#2#3#4#5%
{%
\space {-#5}{-#4}{#1}%
}%
% \end{macrocode}
% \subsection{\csh{xintEuclideAlgorithm}}
% \lverb|&
% Pour Euclide:
% {N}{A}{D=r(n)}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0}$\
% u<2n> = u<2n+3>u<2n+2> + u<2n+4> à la n ième étape|
% \begin{macrocode}
\def\xintEuclideAlgorithm {\romannumeral0\xinteuclidealgorithm }%
\def\xinteuclidealgorithm #1%
{%
\expandafter \XINT_euc \expandafter{\romannumeral0\xintiabs {#1}}%
}%
\def\XINT_euc #1#2%
{%
\expandafter\XINT_euc_fork \romannumeral0\xintiabs {#2}\Z #1\Z
}%
% \end{macrocode}
% \lverb|Ici #3#4=A, #1#2=B|
% \begin{macrocode}
\def\XINT_euc_fork #1#2\Z #3#4\Z
{%
\xint_UDzerofork
#1\XINT_euc_BisZero
#3\XINT_euc_AisZero
0\XINT_euc_a
\krof
{0}{#1#2}{#3#4}{{#3#4}{#1#2}}{}\Z
}%
% \end{macrocode}
% \lverb|&
% Le {} pour protéger {{A}{B}} si on s'arrête après une étape (B divise
% A).
% On va renvoyer:$\
% {N}{A}{D=r(n)}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0}|
% \begin{macrocode}
\def\XINT_euc_AisZero #1#2#3#4#5#6{ {1}{0}{#2}{#2}{0}{0}}%
\def\XINT_euc_BisZero #1#2#3#4#5#6{ {1}{0}{#3}{#3}{0}{0}}%
% \end{macrocode}
% \lverb|&
% {n}{rn}{an}{{qn}{rn}}...{{A}{B}}{}\Z$\
% a(n) = r(n-1). Pour n=0 on a juste {0}{B}{A}{{A}{B}}{}\Z$\
% \XINT_div_prepare {u}{v} divise v par u|
% \begin{macrocode}
\def\XINT_euc_a #1#2#3%
{%
\expandafter\XINT_euc_b
\expandafter {\the\numexpr #1+1\expandafter }%
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}%
}%
% \end{macrocode}
% \lverb|{n+1}{q(n+1)}{r(n+1)}{rn}{{qn}{rn}}...|
% \begin{macrocode}
\def\XINT_euc_b #1#2#3#4%
{%
\XINT_euc_c #3\Z {#1}{#3}{#4}{{#2}{#3}}%
}%
% \end{macrocode}
% \lverb|r(n+1)\Z {n+1}{r(n+1)}{r(n)}{{q(n+1)}{r(n+1)}}{{qn}{rn}}...$\
% Test si r(n+1) est nul.|
% \begin{macrocode}
\def\XINT_euc_c #1#2\Z
{%
\xint_gob_til_zero #1\xint_euc_end0\XINT_euc_a
}%
% \end{macrocode}
% \lverb|&
% {n+1}{r(n+1)}{r(n)}{{q(n+1)}{r(n+1)}}...{}\Z
% Ici r(n+1) = 0. On arrête on se prépare à inverser
% {n+1}{0}{r(n)}{{q(n+1)}{r(n+1)}}.....{{q1}{r1}}{{A}{B}}{}\Z$\
% On veut renvoyer: {N=n+1}{A}{D=r(n)}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0}|
% \begin{macrocode}
\def\xint_euc_end0\XINT_euc_a #1#2#3#4\Z%
{%
\expandafter\xint_euc_end_
\romannumeral0%
\XINT_rord_main {}#4{{#1}{#3}}%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
}%
\edef\xint_euc_end_ #1#2#3%
{%
\space {#1}{#3}{#2}%
}%
% \end{macrocode}
% \subsection{\csh{xintBezoutAlgorithm}}
% \lverb|&
% Pour Bezout: objectif, renvoyer$\
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}$\
% alpha0=1, beta0=0, alpha(-1)=0, beta(-1)=1|
% \begin{macrocode}
\def\xintBezoutAlgorithm {\romannumeral0\xintbezoutalgorithm }%
\def\xintbezoutalgorithm #1%
{%
\expandafter \XINT_bezalg \expandafter{\romannumeral0\xintiabs {#1}}%
}%
\def\XINT_bezalg #1#2%
{%
\expandafter\XINT_bezalg_fork \romannumeral0\xintiabs {#2}\Z #1\Z
}%
% \end{macrocode}
% \lverb|Ici #3#4=A, #1#2=B|
% \begin{macrocode}
\def\XINT_bezalg_fork #1#2\Z #3#4\Z
{%
\xint_UDzerofork
#1\XINT_bezalg_BisZero
#3\XINT_bezalg_AisZero
0\XINT_bezalg_a
\krof
0{#1#2}{#3#4}1001{{#3#4}{#1#2}}{}\Z
}%
\def\XINT_bezalg_AisZero #1#2#3\Z{ {1}{0}{0}{1}{#2}{#2}{1}{0}{0}{0}{0}{1}}%
\def\XINT_bezalg_BisZero #1#2#3#4\Z{ {1}{0}{0}{1}{#3}{#3}{1}{0}{0}{0}{0}{1}}%
% \end{macrocode}
% \lverb|&
% pour préparer l'étape n+1 il faut
% {n}{r(n)}{r(n-1)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}&
% {{q(n)}{r(n)}{alpha(n)}{beta(n)}}...
% division de #3 par #2|
% \begin{macrocode}
\def\XINT_bezalg_a #1#2#3%
{%
\expandafter\XINT_bezalg_b
\expandafter {\the\numexpr #1+1\expandafter }%
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}%
}%
% \end{macrocode}
% \lverb|&
% {n+1}{q(n+1)}{r(n+1)}{r(n)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}...|
% \begin{macrocode}
\def\XINT_bezalg_b #1#2#3#4#5#6#7#8%
{%
\expandafter\XINT_bezalg_c\expandafter
{\romannumeral0\xintiiadd {\xintiiMul {#6}{#2}}{#8}}%
{\romannumeral0\xintiiadd {\xintiiMul {#5}{#2}}{#7}}%
{#1}{#2}{#3}{#4}{#5}{#6}%
}%
% \end{macrocode}
% \lverb|&
% {beta(n+1)}{alpha(n+1)}{n+1}{q(n+1)}{r(n+1)}{r(n)}{alpha(n)}{beta(n}}|
% \begin{macrocode}
\def\XINT_bezalg_c #1#2#3#4#5#6%
{%
\expandafter\XINT_bezalg_d\expandafter {#2}{#3}{#4}{#5}{#6}{#1}%
}%
% \end{macrocode}
% \lverb|{alpha(n+1)}{n+1}{q(n+1)}{r(n+1)}{r(n)}{beta(n+1)}|
% \begin{macrocode}
\def\XINT_bezalg_d #1#2#3#4#5#6#7#8%
{%
\XINT_bezalg_e #4\Z {#2}{#4}{#5}{#1}{#6}{#7}{#8}{{#3}{#4}{#1}{#6}}%
}%
% \end{macrocode}
% \lverb|r(n+1)\Z {n+1}{r(n+1)}{r(n)}{alpha(n+1)}{beta(n+1)}$\
% {alpha(n)}{beta(n)}{q,r,alpha,beta(n+1)}$\
% Test si r(n+1) est nul.|
% \begin{macrocode}
\def\XINT_bezalg_e #1#2\Z
{%
\xint_gob_til_zero #1\xint_bezalg_end0\XINT_bezalg_a
}%
% \end{macrocode}
% \lverb|&
% Ici r(n+1) = 0. On arrête on se prépare à inverser.$\
% {n+1}{r(n+1)}{r(n)}{alpha(n+1)}{beta(n+1)}{alpha(n)}{beta(n)}$\
% {q,r,alpha,beta(n+1)}...{{A}{B}}{}\Z$\
% On veut renvoyer$\
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}|
% \begin{macrocode}
\def\xint_bezalg_end0\XINT_bezalg_a #1#2#3#4#5#6#7#8\Z
{%
\expandafter\xint_bezalg_end_
\romannumeral0%
\XINT_rord_main {}#8{{#1}{#3}}%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
}%
% \end{macrocode}
% \lverb|&
% {N}{D}{A}{B}{q1}{r1}{alpha1=q1}{beta1=1}{q2}{r2}{alpha2}{beta2}$\
% ....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}$\
% On veut renvoyer$\
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}|
% \begin{macrocode}
\edef\xint_bezalg_end_ #1#2#3#4%
{%
\space {#1}{#3}{0}{1}{#2}{#4}{1}{0}%
}%
% \end{macrocode}
% \subsection{\csh{xintGCDof}}
% \begin{macrocode}
\def\xintGCDof {\romannumeral0\xintgcdof }%
\def\xintgcdof #1{\expandafter\XINT_gcdof_a\romannumeral`&&@#1\relax }%
\def\XINT_gcdof_a #1{\expandafter\XINT_gcdof_b\romannumeral`&&@#1\Z }%
\def\XINT_gcdof_b #1\Z #2{\expandafter\XINT_gcdof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_gcdof_c #1{\xint_gob_til_relax #1\XINT_gcdof_e\relax\XINT_gcdof_d #1}%
\def\XINT_gcdof_d #1\Z {\expandafter\XINT_gcdof_b\romannumeral0\xintgcd {#1}}%
\def\XINT_gcdof_e #1\Z #2\Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintLCMof}}
% \lverb|New with 1.09a|
% \begin{macrocode}
\def\xintLCMof {\romannumeral0\xintlcmof }%
\def\xintlcmof #1{\expandafter\XINT_lcmof_a\romannumeral`&&@#1\relax }%
\def\XINT_lcmof_a #1{\expandafter\XINT_lcmof_b\romannumeral`&&@#1\Z }%
\def\XINT_lcmof_b #1\Z #2{\expandafter\XINT_lcmof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_lcmof_c #1{\xint_gob_til_relax #1\XINT_lcmof_e\relax\XINT_lcmof_d #1}%
\def\XINT_lcmof_d #1\Z {\expandafter\XINT_lcmof_b\romannumeral0\xintlcm {#1}}%
\def\XINT_lcmof_e #1\Z #2\Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintTypesetEuclideAlgorithm}}
% \lverb|&
% TYPESETTING
%
% Organisation:
%
% {N}{A}{D}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0}$\
% \U1 = N = nombre d'étapes, \U3 = PGCD, \U2 = A, \U4=B
% q1 = \U5, q2 = \U7 --> qn = \U<2n+3>, rn = \U<2n+4>
% bn = rn. B = r0. A=r(-1)
%
% r(n-2) = q(n)r(n-1)+r(n) (n e étape)
%
% \U{2n} = \U{2n+3} \times \U{2n+2} + \U{2n+4}, n e étape.
% (avec n entre 1 et N)
%
% 1.09h uses \xintloop, and \par rather than \endgraf; and \par rather than
% \hfill\break|
% \begin{macrocode}
\def\xintTypesetEuclideAlgorithm {%
\unless\ifdefined\xintAssignArray
\errmessage
{xintgcd: package xinttools is required for \string\xintTypesetEuclideAlgorithm}%
\expandafter\xint_gobble_iii
\fi
\XINT_TypesetEuclideAlgorithm
}%
\def\XINT_TypesetEuclideAlgorithm #1#2%
{% l'algo remplace #1 et #2 par |#1| et |#2|
\par
\begingroup
\xintAssignArray\xintEuclideAlgorithm {#1}{#2}\to\U
\edef\A{\U2}\edef\B{\U4}\edef\N{\U1}%
\setbox 0 \vbox{\halign {$##$\cr \A\cr \B \cr}}%
\count 255 1
\xintloop
\indent\hbox to \wd 0 {\hfil$\U{\numexpr 2*\count255\relax}$}%
${} = \U{\numexpr 2*\count255 + 3\relax}
\times \U{\numexpr 2*\count255 + 2\relax}
+ \U{\numexpr 2*\count255 + 4\relax}$%
\ifnum \count255 < \N
\par
\advance \count255 1
\repeat
\endgroup
}%
% \end{macrocode}
% \subsection{\csh{xintTypesetBezoutAlgorithm}}
% \lverb|&
% Pour Bezout on a:
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}%
% Donc 4N+8 termes:
% U1 = N, U2= A, U5=D, U6=B, q1 = U9, qn = U{4n+5}, n au moins 1$\
% rn = U{4n+6}, n au moins -1$\
% alpha(n) = U{4n+7}, n au moins -1$\
% beta(n) = U{4n+8}, n au moins -1
%
% 1.09h uses \xintloop, and \par rather than \endgraf; and no more \parindent0pt
% |
% \begin{macrocode}
\def\xintTypesetBezoutAlgorithm {%
\unless\ifdefined\xintAssignArray
\errmessage
{xintgcd: package xinttools is required for \string\xintTypesetBezoutAlgorithm}%
\expandafter\xint_gobble_iii
\fi
\XINT_TypesetBezoutAlgorithm
}%
\def\XINT_TypesetBezoutAlgorithm #1#2%
{%
\par
\begingroup
\xintAssignArray\xintBezoutAlgorithm {#1}{#2}\to\BEZ
\edef\A{\BEZ2}\edef\B{\BEZ6}\edef\N{\BEZ1}% A = |#1|, B = |#2|
\setbox 0 \vbox{\halign {$##$\cr \A\cr \B \cr}}%
\count255 1
\xintloop
\indent\hbox to \wd 0 {\hfil$\BEZ{4*\count255 - 2}$}%
${} = \BEZ{4*\count255 + 5}
\times \BEZ{4*\count255 + 2}
+ \BEZ{4*\count255 + 6}$\hfill\break
\hbox to \wd 0 {\hfil$\BEZ{4*\count255 +7}$}%
${} = \BEZ{4*\count255 + 5}
\times \BEZ{4*\count255 + 3}
+ \BEZ{4*\count255 - 1}$\hfill\break
\hbox to \wd 0 {\hfil$\BEZ{4*\count255 +8}$}%
${} = \BEZ{4*\count255 + 5}
\times \BEZ{4*\count255 + 4}
+ \BEZ{4*\count255 }$
\par
\ifnum \count255 < \N
\advance \count255 1
\repeat
\edef\U{\BEZ{4*\N + 4}}%
\edef\V{\BEZ{4*\N + 3}}%
\edef\D{\BEZ5}%
\ifodd\N
$\U\times\A - \V\times \B = -\D$%
\else
$\U\times\A - \V\times\B = \D$%
\fi
\par
\endgroup
}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintgcd}
%
%\gardesactifs
%\let</xintgcd>\relax
%\let<*xintfrac>\gardesinactifs
%</xintgcd>^^A----------------------------------------------------
%<*xintfrac>^^A---------------------------------------------------
% \clearpage
% \section{Package \xintfracnameimp implementation}
% \label{sec:fracimp}
%
% \localtableofcontents
%
% The commenting is currently (\xintdocdate) very sparse.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xintfrac.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xint.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintfrac}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintfrac.sty
\ifx\w\relax % but xint.sty not yet loaded.
\def\z{\endgroup\input xint.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xint.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xint}}%
\fi
\else
\aftergroup\endinput % xintfrac already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintfrac}%
[2016/11/20 1.2h Expandable operations on fractions (JFB)]%
% \end{macrocode}
% \subsection{\csh{XINT_cntSgnFork}}
% \lverb|1.09i. Used internally, #1 must expand to \m@ne, \z@, or \@ne or
% equivalent. \XINT_cntSgnFork does not insert a romannumeral stopper.|
% \begin{macrocode}
\def\XINT_cntSgnFork #1%
{%
\ifcase #1\expandafter\xint_secondofthree
\or\expandafter\xint_thirdofthree
\else\expandafter\xint_firstofthree
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintLen}}
% \lverb|The used formula is disputable, the idea is that A/1 and A should have
% same length.|
% \begin{macrocode}
\def\xintLen {\romannumeral0\xintlen }%
\def\xintlen #1%
{%
\expandafter\XINT_flen\romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_flen #1#2#3%
{%
\expandafter\space
\the\numexpr -1+\XINT_Abs {#1}+\XINT_Len {#2}+\XINT_Len {#3}\relax
}%
% \end{macrocode}
% \subsection{\csh{XINT_lenrord_loop}}
% \lverb|& attention que & est comment dans mes \lverb
% Faire \romannumeral`$&$&@\XINT_lenrord_loop 0.{}foobar\Z\W\W\W\W\W\W\W\Z, et
% en sortie on aura : longueur.raboof\Z. C'est une vieille routine, employée
% uniquement par \xintFloat et \XINTinFloat, et uniquement pour des chiffres.
% Donc j'ai plus rapide maintenant mais elle n'est utilisée que pour des
% choses assez courtes, alors à voir.|
% \begin{macrocode}
\def\XINT_lenrord_loop #1.#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_W #9\XINT_lenrord_W\W
\expandafter\XINT_lenrord_loop\the\numexpr #1+\xint_c_vii.{#9#8#7#6#5#4#3#2}%
}%
\def\XINT_lenrord_W\W\expandafter\XINT_lenrord_loop #1.#2#3\Z
{%
\expandafter\XINT_lenrord_X #1.#2\Z
}%
\def\XINT_lenrord_X #1.#2\Z
{%
\XINT_lenrord_Y #2\R\R\R\R\R\R\T {#1}%
}%
\def\XINT_lenrord_Y #1#2#3#4#5#6#7#8\T
{%
\xint_gob_til_W
#7\XINT_lenrord_Z \xint_c_viii
#6\XINT_lenrord_Z \xint_c_vii
#5\XINT_lenrord_Z \xint_c_vi
#4\XINT_lenrord_Z \xint_c_v
#3\XINT_lenrord_Z \xint_c_iv
#2\XINT_lenrord_Z \xint_c_iii
\W\XINT_lenrord_Z \xint_c_ii \Z
}%
\def\XINT_lenrord_Z #1#2\Z #3{\the\numexpr #3-#1.}%
% \end{macrocode}
% \subsection{\csh{XINT_outfrac}}
% \lverb|&
% Months later (2014/10/22): perhaps I should document what this macro does
% before I forget? from {e}{N}{D} it outputs N/D[e], checking in passing if
% D=0 or if N=0. It also makes sure D is not < 0. I am not sure but I don't
% think there is any place in the code which could call \XINT_outfrac with a D
% < 0, but I should check.|
% \begin{macrocode}
\def\XINT_outfrac #1#2#3%
{%
\ifcase\XINT_cntSgn #3\Z
\expandafter \XINT_outfrac_divisionbyzero
\or
\expandafter \XINT_outfrac_P
\else
\expandafter \XINT_outfrac_N
\fi
{#2}{#3}[#1]%
}%
\def\XINT_outfrac_divisionbyzero #1#2{\xintError:DivisionByZero\space #1/0}%
\edef\XINT_outfrac_P #1#2%
{%
\noexpand\if0\noexpand\XINT_Sgn #1\noexpand\Z
\noexpand\expandafter\noexpand\XINT_outfrac_Zero
\noexpand\fi
\space #1/#2%
}%
\def\XINT_outfrac_Zero #1[#2]{ 0/1[0]}%
\def\XINT_outfrac_N #1#2%
{%
\expandafter\XINT_outfrac_N_a\expandafter
{\romannumeral0\XINT_opp #2}{\romannumeral0\XINT_opp #1}%
}%
\def\XINT_outfrac_N_a #1#2%
{%
\expandafter\XINT_outfrac_P\expandafter {#2}{#1}%
}%
% \end{macrocode}
% \subsection{\csh{XINT_inFrac}}
% \lverb|Extended in 1.07 to accept scientific notation on input. With lowercase
% e only. The \xintexpr parser does accept uppercase E also. Ah, by the way,
% perhaps I should at least say what this macro does? (belated addition
% 2014/10/22...), before I forget! It prepares the fraction in the internal
% format {exponent}{Numerator}{Denominator} where Denominator is at least 1.
%
% 2015/10/09: this venerable macro from the very early days (1.03, 2013/04/14)
% has gotten a lifting for release 1.2. There were two kinds of issues:
%
% 1) use of \W, \Z, \T delimiters was very poor choice as this could clash with
% user input,
%
% 2) the new \XINT_frac_gen handles macros (possibly empty) in the input as
% general as \A.\Be\C/\D.\Ee\F. The earlier version would not have expanded
% the \B or \E: digits after decimal mark were constrained to arise from
% expansion of the first token. Thus the 1.03 original code would have
% expanded only \A, \D, \C, and \F for this input.
%
% This reminded me think I should revisit the remaining earlier
% portions of code, as I was still learning TeX coding when I wrote them.
%
% Also I thought about parsing even faster the A/B[N] input, not expanding B,
% but this turned out to clash with some established uses in the documentation
% such as 1/\xintiiSqr{...}[0]. For the implementation, careful here about
% potential brace removals with parameter patterns such as like #1/#2#3[#4]for
% example.
%
% While I was at it 1.2 added \numexpr parsing of the N, which earlier was
% restricted to be only explicit digits. I allowed [] with empty N, but the
% way I did it in 1.2 with \the\numexpr 0#1 was buggy, as it did not allow #1
% to be a \count for example or itself a \numexpr (although such inputs were
% not previously allowed, I later turned out to use them in the code itself,
% e.g. the float factorial of version 1.2f). The better way would be
% \the\numexpr#1+\xint_c_ but 1.2f finally does only \the\numexpr #1 and #1 is
% not allowed to be empty.
%
% The 1.2 \XINT_frac_gen had two locations with such a problematic \numexpr
% 0#1 which I replaced for 1.2f with \numexpr#1+\xint_c_.
%
% Regarding calling the macro with an argument A[<expression>], a / inthe
% expression must be suitably hidden for example in \firstofone type
% constructs.
%
% Note: when the numerator is found to be zero \XINT_infrac *always* returns
% {0}{0}{1}. This behaviour must not change because 1.2g \xintFloat and
% XINTinFloat (for example) rely upon it: if the denominator on output is not
% 1, then \xintFloat assumes that the numerator is not zero.
%
% As described in the manual, if the input contains a (final) [N] part, it is
% assumed that it is in the shape A[N] or A/B[N] with A (and B) not containing
% neither decimal mark nor scientific part, moreover B must be positive and A
% have at most one minus sign (and no plus sign). Else there will be errors,
% for example -0/2[0] would not be recognized as being zero at this stage and
% this could cause issues afterwards. When there is no ending [N] part, both
% numerator and denominator will be parsed for the more general format
% allowing decimal digits and scientific part and possibly multiple leading
% signs.
%
% |
% \begin{macrocode}
\def\XINT_inFrac {\romannumeral0\XINT_infrac }%
\def\XINT_infrac #1%
{%
\expandafter\XINT_infrac_fork\romannumeral`&&@#1/\XINT_W[\XINT_W\XINT_T
}%
\def\XINT_infrac_fork #1[#2%
{%
\xint_UDXINTWfork
#2\XINT_frac_gen
\XINT_W\XINT_infrac_res_a % strict A[N] or A/B[N] input
\krof
#1[#2%
}%
\def\XINT_infrac_res_a #1%
{%
\xint_gob_til_zero #1\XINT_infrac_res_zero 0\XINT_infrac_res_b #1%
}%
\def\XINT_infrac_res_zero 0\XINT_infrac_res_b #1\XINT_T {{0}{0}{1}}%
\def\XINT_infrac_res_b #1/#2%
{%
\xint_UDXINTWfork
#2\XINT_infrac_res_ca
\XINT_W\XINT_infrac_res_cb
\krof
#1/#2%
}%
% \end{macrocode}
% \lverb|An empty [] is not allowed. (this was authorized in 1.2, removed in
% 1.2f). As nobody reads xint documentation, no one will have noticed the
% fleeting possibility.|
% \begin{macrocode}
\def\XINT_infrac_res_ca #1[#2]/\XINT_W[\XINT_W\XINT_T
{\expandafter{\the\numexpr #2}{#1}{1}}%
\def\XINT_infrac_res_cb #1/#2[%
{\expandafter\XINT_infrac_res_cc\romannumeral`&&@#2~#1[}%
\def\XINT_infrac_res_cc #1~#2[#3]/\XINT_W[\XINT_W\XINT_T
{\expandafter{\the\numexpr #3}{#2}{#1}}%
% \end{macrocode}
% \subsection{\csh{XINT_frac_gen}}
% \lverb|Extended in 1.07 to recognize and accept scientific notation both at
% the numerator and (possible) denominator. Only a lowercase e will do here,
% but uppercase E is possible within an \xintexpr..\relax
%
% Completely rewritten for 1.2 2015/10/10. The parsing handles inputs such as
% \A.\Be\C/\D.\Ee\F where each of \A, \B, \D, and \E may need \fexpan sion and
% \C and \F will end up in \numexpr.
%
% 1.2f corrects an issue to allow \C and \F to be \count variable (or
% expressions with \numexpr): 1.2 did a bad \numexpr0#1 which allowed only
% explicit digits for expanded #1.|
% \begin{macrocode}
\def\XINT_frac_gen #1/#2%
{%
\xint_UDXINTWfork
#2\XINT_frac_gen_A
\XINT_W\XINT_frac_gen_B
\krof
#1/#2%
}%
\def\XINT_frac_gen_A #1/\XINT_W [\XINT_W {\XINT_frac_gen_C 0~1!#1ee.\XINT_W }%
\def\XINT_frac_gen_B #1/#2/\XINT_W[%\XINT_W
{%
\expandafter\XINT_frac_gen_Ba
\romannumeral`&&@#2ee.\XINT_W\XINT_Z #1ee.%\XINT_W
}%
\def\XINT_frac_gen_Ba #1.#2%
{%
\xint_UDXINTWfork
#2\XINT_frac_gen_Bb
\XINT_W\XINT_frac_gen_Bc
\krof
#1.#2%
}%
\def\XINT_frac_gen_Bb #1e#2e#3\XINT_Z
{\expandafter\XINT_frac_gen_C\the\numexpr #2+\xint_c_~#1!}%
\def\XINT_frac_gen_Bc #1.#2e%
{%
\expandafter\XINT_frac_gen_Bd\romannumeral`&&@#2.#1e%
}%
% \end{macrocode}
% \lverb|Here in \XINT_frac_gen_Bd, the 1.2 rewrite of \XINT_infrac did
% \the\numexpr0#3-, but if #3 is a \count for example this was bad (although
% such inputs never have been explicitely allowed in the doc). And why this 0?
% to handle empty #3? But empty #3 was fine here. Another bug of 1.2 ! Fixed
% in 1.2f. Same in \XINT_frac_gen_Bb above, with the difference however that
% an empty #2 there indeed had to be handled properly.|
% \begin{macrocode}
\def\XINT_frac_gen_Bd #1.#2e#3e#4\XINT_Z
{%
\expandafter\XINT_frac_gen_C\the\numexpr #3-\romannumeral0\expandafter
\XINT_length_loop
0.#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye~#2#1!%
}%
\def\XINT_frac_gen_C #1!#2.#3%
{%
\xint_UDXINTWfork
#3\XINT_frac_gen_Ca
\XINT_W\XINT_frac_gen_Cb
\krof
#1!#2.#3%
}%
\def\XINT_frac_gen_Ca #1~#2!#3e#4e#5\XINT_T
{%
\expandafter\XINT_frac_gen_F\the\numexpr #4-#1\expandafter
~\romannumeral0\XINT_num_loop
#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z~#3~%
}%
\def\XINT_frac_gen_Cb #1.#2e%
{%
\expandafter\XINT_frac_gen_Cc\romannumeral`&&@#2.#1e%
}%
\def\XINT_frac_gen_Cc #1.#2~#3!#4e#5e#6\XINT_T
{%
\expandafter\XINT_frac_gen_F\the\numexpr #5-#2-%
\romannumeral0\XINT_length_loop
0.#1\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\xint_bye\expandafter
~\romannumeral0\XINT_num_loop
#3\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z
~#4#1~%
}%
\def\XINT_frac_gen_F #1~#2%
{%
\xint_UDzerominusfork
#2-\XINT_frac_gen_Gdivbyzero
0#2{\XINT_frac_gen_G -{}}%
0-{\XINT_frac_gen_G {}#2}%
\krof #1~%
}%
\def\XINT_frac_gen_Gdivbyzero #1~~#2~%
{%
\expandafter\XINT_frac_gen_Gdivbyzero_a
\romannumeral0\XINT_num_loop
#2\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z~#1~%
}%
\def\XINT_frac_gen_Gdivbyzero_a #1~#2~%
{%
\xintError:DivisionByZero {#2}{#1}{0}%
}%
\def\XINT_frac_gen_G #1#2#3~#4~#5~%
{%
\expandafter\XINT_frac_gen_Ga
\romannumeral0\XINT_num_loop
#1#5\xint_relax\xint_relax\xint_relax\xint_relax
\xint_relax\xint_relax\xint_relax\xint_relax\Z~#3~{#2#4}%
}%
\def\XINT_frac_gen_Ga #1#2~#3~%
{%
\xint_gob_til_zero #1\XINT_frac_gen_zero 0%
{#3}{#1#2}%
}%
\def\XINT_frac_gen_zero 0#1#2#3{{0}{0}{1}}%
% \end{macrocode}
% \subsection{\csh{XINT_factortens}, \csh{XINT_cuz_cnt}}
% \lverb|Old routines.|
% \begin{macrocode}
\def\XINT_factortens #1%
{%
\expandafter\XINT_cuz_cnt_loop\expandafter
{\expandafter}\romannumeral0\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
\R\R\R\R\R\R\R\R\Z
}%
\def\XINT_cuz_cnt #1%
{%
\XINT_cuz_cnt_loop {}#1\R\R\R\R\R\R\R\R\Z
}%
\def\XINT_cuz_cnt_loop #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_cuz_cnt_toofara \R
\expandafter\XINT_cuz_cnt_checka\expandafter
{\the\numexpr #1+8\relax}{#2#3#4#5#6#7#8#9}%
}%
\def\XINT_cuz_cnt_toofara\R
\expandafter\XINT_cuz_cnt_checka\expandafter #1#2%
{%
\XINT_cuz_cnt_toofarb {#1}#2%
}%
\def\XINT_cuz_cnt_toofarb #1#2\Z {\XINT_cuz_cnt_toofarc #2\Z {#1}}%
\def\XINT_cuz_cnt_toofarc #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_R #2\XINT_cuz_cnt_toofard 7%
#3\XINT_cuz_cnt_toofard 6%
#4\XINT_cuz_cnt_toofard 5%
#5\XINT_cuz_cnt_toofard 4%
#6\XINT_cuz_cnt_toofard 3%
#7\XINT_cuz_cnt_toofard 2%
#8\XINT_cuz_cnt_toofard 1%
\Z #1#2#3#4#5#6#7#8%
}%
\def\XINT_cuz_cnt_toofard #1#2\Z #3\R #4\Z #5%
{%
\expandafter\XINT_cuz_cnt_toofare
\the\numexpr #3\relax \R\R\R\R\R\R\R\R\Z
{\the\numexpr #5-#1\relax}\R\Z
}%
\def\XINT_cuz_cnt_toofare #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_R #2\XINT_cuz_cnt_stopc 1%
#3\XINT_cuz_cnt_stopc 2%
#4\XINT_cuz_cnt_stopc 3%
#5\XINT_cuz_cnt_stopc 4%
#6\XINT_cuz_cnt_stopc 5%
#7\XINT_cuz_cnt_stopc 6%
#8\XINT_cuz_cnt_stopc 7%
\Z #1#2#3#4#5#6#7#8%
}%
\def\XINT_cuz_cnt_checka #1#2%
{%
\expandafter\XINT_cuz_cnt_checkb\the\numexpr #2\relax \Z {#1}%
}%
\def\XINT_cuz_cnt_checkb #1%
{%
\xint_gob_til_zero #1\expandafter\XINT_cuz_cnt_loop\xint_gob_til_Z
0\XINT_cuz_cnt_stopa #1%
}%
\def\XINT_cuz_cnt_stopa #1\Z
{%
\XINT_cuz_cnt_stopb #1\R\R\R\R\R\R\R\R\Z %
}%
\def\XINT_cuz_cnt_stopb #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #2\XINT_cuz_cnt_stopc 1%
#3\XINT_cuz_cnt_stopc 2%
#4\XINT_cuz_cnt_stopc 3%
#5\XINT_cuz_cnt_stopc 4%
#6\XINT_cuz_cnt_stopc 5%
#7\XINT_cuz_cnt_stopc 6%
#8\XINT_cuz_cnt_stopc 7%
#9\XINT_cuz_cnt_stopc 8%
\Z #1#2#3#4#5#6#7#8#9%
}%
\def\XINT_cuz_cnt_stopc #1#2\Z #3\R #4\Z #5%
{%
\expandafter\XINT_cuz_cnt_stopd\expandafter
{\the\numexpr #5-#1}#3%
}%
\def\XINT_cuz_cnt_stopd #1#2\R #3\Z
{%
\expandafter\space\expandafter
{\romannumeral0\XINT_rord_main {}#2%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax }{#1}%
}%
% \end{macrocode}
% \subsection{\csh{XINT_addm_A}}
% \lverb|This is a routine from xintcore 1.0x, which is now only needed by
% \xintFloat, \XINTinFloat and \xintRound, for the time being.|
% \begin{macrocode}
\def\XINT_addm_A #1#2#3#4#5#6%
{%
\xint_gob_til_W #3\XINT_addm_az\W
\XINT_addm_AB #1{#3#4#5#6}{#2}%
}%
\def\XINT_addm_az\W\XINT_addm_AB #1#2%
{%
\XINT_addm_AC_checkcarry #1%
}%
\def\XINT_addm_AB #1#2#3#4\W\X\Y\Z #5#6#7#8%
{%
\XINT_addm_ABE #1#2{#8#7#6#5}{#3}#4\W\X\Y\Z
}%
\def\XINT_addm_ABE #1#2#3#4#5#6%
{%
\expandafter\XINT_addm_ABEA\the\numexpr #1+10#5#4#3#2+#6.%
}%
\def\XINT_addm_ABEA #1#2#3.#4%
{%
\XINT_addm_A #2{#3#4}%
}%
\def\XINT_addm_AC_checkcarry #1%
{%
\xint_gob_til_zero #1\XINT_addm_AC_nocarry 0\XINT_addm_C
}%
\def\XINT_addm_AC_nocarry 0\XINT_addm_C #1#2\W\X\Y\Z
{%
\expandafter
\xint_cleanupzeros_andstop
\romannumeral0%
\XINT_rord_main {}#2%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
#1%
}%
\def\XINT_addm_C #1#2#3#4#5%
{%
\xint_gob_til_W
#5\XINT_addm_cw
#4\XINT_addm_cx
#3\XINT_addm_cy
#2\XINT_addm_cz
\W\XINT_addm_CD {#5#4#3#2}{#1}%
}%
\def\XINT_addm_CD #1%
{%
\expandafter\XINT_addm_CC\the\numexpr 1+10#1.%
}%
\def\XINT_addm_CC #1#2#3.#4%
{%
\XINT_addm_AC_checkcarry #2{#3#4}%
}%
\def\XINT_addm_cw
#1\XINT_addm_cx
#2\XINT_addm_cy
#3\XINT_addm_cz
\W\XINT_addm_CD
{%
\expandafter\XINT_addm_CDw\the\numexpr 1+#1#2#3.%
}%
\def\XINT_addm_CDw #1.#2#3\X\Y\Z
{%
\XINT_addm_end #1#3%
}%
\def\XINT_addm_cx
#1\XINT_addm_cy
#2\XINT_addm_cz
\W\XINT_addm_CD
{%
\expandafter\XINT_addm_CDx\the\numexpr 1+#1#2.%
}%
\def\XINT_addm_CDx #1.#2#3\Y\Z
{%
\XINT_addm_end #1#3%
}%
\def\XINT_addm_cy
#1\XINT_addm_cz
\W\XINT_addm_CD
{%
\expandafter\XINT_addm_CDy\the\numexpr 1+#1.%
}%
\def\XINT_addm_CDy #1.#2#3\Z
{%
\XINT_addm_end #1#3%
}%
\def\XINT_addm_cz\W\XINT_addm_CD #1#2#3{\XINT_addm_end #1#3}%
\edef\XINT_addm_end #1#2#3#4#5%
{\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5\relax}%
% \end{macrocode}
% \subsection{\csh{xintRaw}}
% \lverb|&
% 1.07: this macro simply prints in a user readable form the fraction after its
% initial scanning. Useful when put inside braces in an \xintexpr, when the
% input is not yet in the A/B[n] form.|
% \begin{macrocode}
\def\xintRaw {\romannumeral0\xintraw }%
\def\xintraw
{%
\expandafter\XINT_raw\romannumeral0\XINT_infrac
}%
\def\XINT_raw #1#2#3{ #2/#3[#1]}%
% \end{macrocode}
% \subsection{\csh{xintPRaw}}
% \lverb|1.09b|
% \begin{macrocode}
\def\xintPRaw {\romannumeral0\xintpraw }%
\def\xintpraw
{%
\expandafter\XINT_praw\romannumeral0\XINT_infrac
}%
\def\XINT_praw #1%
{%
\ifnum #1=\xint_c_ \expandafter\XINT_praw_a\fi \XINT_praw_A {#1}%
}%
\def\XINT_praw_A #1#2#3%
{%
\if\XINT_isOne{#3}1\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi { #2[#1]}{ #2/#3[#1]}%
}%
\def\XINT_praw_a\XINT_praw_A #1#2#3%
{%
\if\XINT_isOne{#3}1\expandafter\xint_firstoftwo
\else\expandafter\xint_secondoftwo
\fi { #2}{ #2/#3}%
}%
% \end{macrocode}
% \subsection{\csh{xintRawWithZeros}}
% \lverb|&
% This was called \xintRaw in versions earlier than 1.07|
% \begin{macrocode}
\def\xintRawWithZeros {\romannumeral0\xintrawwithzeros }%
\def\xintrawwithzeros
{%
\expandafter\XINT_rawz\romannumeral0\XINT_infrac
}%
\def\XINT_rawz #1%
{%
\ifcase\XINT_cntSgn #1\Z
\expandafter\XINT_rawz_Ba
\or
\expandafter\XINT_rawz_A
\else
\expandafter\XINT_rawz_Ba
\fi
{#1}%
}%
\def\XINT_rawz_A #1#2#3{\xint_dsh {#2}{-#1}/#3}%
\def\XINT_rawz_Ba #1#2#3{\expandafter\XINT_rawz_Bb
\expandafter{\romannumeral0\xint_dsh {#3}{#1}}{#2}}%
\def\XINT_rawz_Bb #1#2{ #2/#1}%
% \end{macrocode}
% \subsection{\csh{xintFloor}, \csh{xintiFloor}}
% \lverb|1.09a, 1.1 for \xintiFloor/\xintFloor. Not efficient if big negative
% decimal exponent. Also sub-efficient if big positive decimal exponent.|
% \begin{macrocode}
\def\xintFloor {\romannumeral0\xintfloor }%
\def\xintfloor #1% devrais-je faire \xintREZ?
{\expandafter\XINT_ifloor \romannumeral0\xintrawwithzeros {#1}./1[0]}%
\def\xintiFloor {\romannumeral0\xintifloor }%
\def\xintifloor #1%
{\expandafter\XINT_ifloor \romannumeral0\xintrawwithzeros {#1}.}%
\def\XINT_ifloor #1/#2.{\xintiiquo {#1}{#2}}%
% \end{macrocode}
% \subsection{\csh{xintCeil}, \csh{xintiCeil}}
% \lverb|1.09a|
% \begin{macrocode}
\def\xintCeil {\romannumeral0\xintceil }%
\def\xintceil #1{\xintiiopp {\xintFloor {\xintOpp{#1}}}}%
\def\xintiCeil {\romannumeral0\xinticeil }%
\def\xinticeil #1{\xintiiopp {\xintiFloor {\xintOpp{#1}}}}%
% \end{macrocode}
% \subsection{\csh{xintNumerator}}
% \begin{macrocode}
\def\xintNumerator {\romannumeral0\xintnumerator }%
\def\xintnumerator
{%
\expandafter\XINT_numer\romannumeral0\XINT_infrac
}%
\def\XINT_numer #1%
{%
\ifcase\XINT_cntSgn #1\Z
\expandafter\XINT_numer_B
\or
\expandafter\XINT_numer_A
\else
\expandafter\XINT_numer_B
\fi
{#1}%
}%
\def\XINT_numer_A #1#2#3{\xint_dsh {#2}{-#1}}%
\def\XINT_numer_B #1#2#3{ #2}%
% \end{macrocode}
% \subsection{\csh{xintDenominator}}
% \begin{macrocode}
\def\xintDenominator {\romannumeral0\xintdenominator }%
\def\xintdenominator
{%
\expandafter\XINT_denom\romannumeral0\XINT_infrac
}%
\def\XINT_denom #1%
{%
\ifcase\XINT_cntSgn #1\Z
\expandafter\XINT_denom_B
\or
\expandafter\XINT_denom_A
\else
\expandafter\XINT_denom_B
\fi
{#1}%
}%
\def\XINT_denom_A #1#2#3{ #3}%
\def\XINT_denom_B #1#2#3{\xint_dsh {#3}{#1}}%
% \end{macrocode}
% \subsection{\csh{xintFrac}}
% \lverb|Useless typesetting macro.|
% \begin{macrocode}
\def\xintFrac {\romannumeral0\xintfrac }%
\def\xintfrac #1%
{%
\expandafter\XINT_fracfrac_A\romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_fracfrac_A #1{\XINT_fracfrac_B #1\Z }%
\catcode`^=7
\def\XINT_fracfrac_B #1#2\Z
{%
\xint_gob_til_zero #1\XINT_fracfrac_C 0\XINT_fracfrac_D {10^{#1#2}}%
}%
\def\XINT_fracfrac_C 0\XINT_fracfrac_D #1#2#3%
{%
\if1\XINT_isOne {#3}%
\xint_afterfi {\expandafter\xint_firstoftwo_thenstop\xint_gobble_ii }%
\fi
\space
\frac {#2}{#3}%
}%
\def\XINT_fracfrac_D #1#2#3%
{%
\if1\XINT_isOne {#3}\XINT_fracfrac_E\fi
\space
\frac {#2}{#3}#1%
}%
\def\XINT_fracfrac_E \fi\space\frac #1#2{\fi \space #1\cdot }%
% \end{macrocode}
% \subsection{\csh{xintSignedFrac}}
% \begin{macrocode}
\def\xintSignedFrac {\romannumeral0\xintsignedfrac }%
\def\xintsignedfrac #1%
{%
\expandafter\XINT_sgnfrac_a\romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_sgnfrac_a #1#2%
{%
\XINT_sgnfrac_b #2\Z {#1}%
}%
\def\XINT_sgnfrac_b #1%
{%
\xint_UDsignfork
#1\XINT_sgnfrac_N
-{\XINT_sgnfrac_P #1}%
\krof
}%
\def\XINT_sgnfrac_P #1\Z #2%
{%
\XINT_fracfrac_A {#2}{#1}%
}%
\def\XINT_sgnfrac_N
{%
\expandafter-\romannumeral0\XINT_sgnfrac_P
}%
% \end{macrocode}
% \subsection{\csh{xintFwOver}}
% \begin{macrocode}
\def\xintFwOver {\romannumeral0\xintfwover }%
\def\xintfwover #1%
{%
\expandafter\XINT_fwover_A\romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_fwover_A #1{\XINT_fwover_B #1\Z }%
\def\XINT_fwover_B #1#2\Z
{%
\xint_gob_til_zero #1\XINT_fwover_C 0\XINT_fwover_D {10^{#1#2}}%
}%
\catcode`^=11
\def\XINT_fwover_C #1#2#3#4#5%
{%
\if0\XINT_isOne {#5}\xint_afterfi { {#4\over #5}}%
\else\xint_afterfi { #4}%
\fi
}%
\def\XINT_fwover_D #1#2#3%
{%
\if0\XINT_isOne {#3}\xint_afterfi { {#2\over #3}}%
\else\xint_afterfi { #2\cdot }%
\fi
#1%
}%
% \end{macrocode}
% \subsection{\csh{xintSignedFwOver}}
% \begin{macrocode}
\def\xintSignedFwOver {\romannumeral0\xintsignedfwover }%
\def\xintsignedfwover #1%
{%
\expandafter\XINT_sgnfwover_a\romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_sgnfwover_a #1#2%
{%
\XINT_sgnfwover_b #2\Z {#1}%
}%
\def\XINT_sgnfwover_b #1%
{%
\xint_UDsignfork
#1\XINT_sgnfwover_N
-{\XINT_sgnfwover_P #1}%
\krof
}%
\def\XINT_sgnfwover_P #1\Z #2%
{%
\XINT_fwover_A {#2}{#1}%
}%
\def\XINT_sgnfwover_N
{%
\expandafter-\romannumeral0\XINT_sgnfwover_P
}%
% \end{macrocode}
% \subsection{\csh{xintREZ}}
% \lverb|Removes trailing zeros from A and B and adjust the N in A/B[N].|
% \begin{macrocode}
\def\xintREZ {\romannumeral0\xintrez }%
\def\xintrez
{%
\expandafter\XINT_rez_A\romannumeral0\XINT_infrac
}%
\def\XINT_rez_A #1#2%
{%
\XINT_rez_AB #2\Z {#1}%
}%
\def\XINT_rez_AB #1%
{%
\xint_UDzerominusfork
#1-\XINT_rez_zero
0#1\XINT_rez_neg
0-{\XINT_rez_B #1}%
\krof
}%
\def\XINT_rez_zero #1\Z #2#3{ 0/1[0]}%
\def\XINT_rez_neg {\expandafter-\romannumeral0\XINT_rez_B }%
\def\XINT_rez_B #1\Z
{%
\expandafter\XINT_rez_C\romannumeral0\XINT_factortens {#1}%
}%
\def\XINT_rez_C #1#2#3#4%
{%
\expandafter\XINT_rez_D\romannumeral0\XINT_factortens {#4}{#3}{#2}{#1}%
}%
\def\XINT_rez_D #1#2#3#4#5%
{%
\expandafter\XINT_rez_E\expandafter
{\the\numexpr #3+#4-#2}{#1}{#5}%
}%
\def\XINT_rez_E #1#2#3{ #3/#2[#1]}%
% \end{macrocode}
% \subsection{\csh{xintE}}
% \lverb|1.07: The fraction is the first argument contrarily to \xintTrunc and
% \xintRound.
%
% 1.1 modifies and moves \xintiiE to xint.sty.|
% \begin{macrocode}
\def\xintE {\romannumeral0\xinte }%
\def\xinte #1%
{%
\expandafter\XINT_e \romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_e #1#2#3#4%
{%
\expandafter\XINT_e_end\the\numexpr #1+#4.{#2}{#3}%
}%
\def\XINT_e_end #1.#2#3{ #2/#3[#1]}%
% \end{macrocode}
% \subsection{\csh{xintIrr}}
% \begin{macrocode}
\def\xintIrr {\romannumeral0\xintirr }%
\def\xintirr #1%
{%
\expandafter\XINT_irr_start\romannumeral0\xintrawwithzeros {#1}\Z
}%
\def\XINT_irr_start #1#2/#3\Z
{%
\if0\XINT_isOne {#3}%
\xint_afterfi
{\xint_UDsignfork
#1\XINT_irr_negative
-{\XINT_irr_nonneg #1}%
\krof}%
\else
\xint_afterfi{\XINT_irr_denomisone #1}%
\fi
#2\Z {#3}%
}%
\def\XINT_irr_denomisone #1\Z #2{ #1/1}% changed in 1.08
\def\XINT_irr_negative #1\Z #2{\XINT_irr_D #1\Z #2\Z -}%
\def\XINT_irr_nonneg #1\Z #2{\XINT_irr_D #1\Z #2\Z \space}%
\def\XINT_irr_D #1#2\Z #3#4\Z
{%
\xint_UDzerosfork
#3#1\XINT_irr_indeterminate
#30\XINT_irr_divisionbyzero
#10\XINT_irr_zero
00\XINT_irr_loop_a
\krof
{#3#4}{#1#2}{#3#4}{#1#2}%
}%
\def\XINT_irr_indeterminate #1#2#3#4#5{\xintError:NaN\space 0/0}%
\def\XINT_irr_divisionbyzero #1#2#3#4#5{\xintError:DivisionByZero #5#2/0}%
\def\XINT_irr_zero #1#2#3#4#5{ 0/1}% changed in 1.08
\def\XINT_irr_loop_a #1#2%
{%
\expandafter\XINT_irr_loop_d
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}%
}%
\def\XINT_irr_loop_d #1#2%
{%
\XINT_irr_loop_e #2\Z
}%
\def\XINT_irr_loop_e #1#2\Z
{%
\xint_gob_til_zero #1\XINT_irr_loop_exit0\XINT_irr_loop_a {#1#2}%
}%
\def\XINT_irr_loop_exit0\XINT_irr_loop_a #1#2#3#4%
{%
\expandafter\XINT_irr_loop_exitb\expandafter
{\romannumeral0\xintiiquo {#3}{#2}}%
{\romannumeral0\xintiiquo {#4}{#2}}%
}%
\def\XINT_irr_loop_exitb #1#2%
{%
\expandafter\XINT_irr_finish\expandafter {#2}{#1}%
}%
\def\XINT_irr_finish #1#2#3{#3#1/#2}% changed in 1.08
% \end{macrocode}
% \subsection{\csh{xintifInt}}
% \begin{macrocode}
\def\xintifInt {\romannumeral0\xintifint }%
\def\xintifint #1{\expandafter\XINT_ifint\romannumeral0\xintrawwithzeros {#1}.}%
\def\XINT_ifint #1/#2.%
{%
\if 0\xintiiRem {#1}{#2}%
\expandafter\xint_firstoftwo_thenstop
\else
\expandafter\xint_secondoftwo_thenstop
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintJrr}}
% \begin{macrocode}
\def\xintJrr {\romannumeral0\xintjrr }%
\def\xintjrr #1%
{%
\expandafter\XINT_jrr_start\romannumeral0\xintrawwithzeros {#1}\Z
}%
\def\XINT_jrr_start #1#2/#3\Z
{%
\if0\XINT_isOne {#3}\xint_afterfi
{\xint_UDsignfork
#1\XINT_jrr_negative
-{\XINT_jrr_nonneg #1}%
\krof}%
\else
\xint_afterfi{\XINT_jrr_denomisone #1}%
\fi
#2\Z {#3}%
}%
\def\XINT_jrr_denomisone #1\Z #2{ #1/1}% changed in 1.08
\def\XINT_jrr_negative #1\Z #2{\XINT_jrr_D #1\Z #2\Z -}%
\def\XINT_jrr_nonneg #1\Z #2{\XINT_jrr_D #1\Z #2\Z \space}%
\def\XINT_jrr_D #1#2\Z #3#4\Z
{%
\xint_UDzerosfork
#3#1\XINT_jrr_indeterminate
#30\XINT_jrr_divisionbyzero
#10\XINT_jrr_zero
00\XINT_jrr_loop_a
\krof
{#3#4}{#1#2}1001%
}%
\def\XINT_jrr_indeterminate #1#2#3#4#5#6#7{\xintError:NaN\space 0/0}%
\def\XINT_jrr_divisionbyzero #1#2#3#4#5#6#7{\xintError:DivisionByZero #7#2/0}%
\def\XINT_jrr_zero #1#2#3#4#5#6#7{ 0/1}% changed in 1.08
\def\XINT_jrr_loop_a #1#2%
{%
\expandafter\XINT_jrr_loop_b
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}%
}%
\def\XINT_jrr_loop_b #1#2#3#4#5#6#7%
{%
\expandafter \XINT_jrr_loop_c \expandafter
{\romannumeral0\xintiiadd{\XINT_mul_fork #4\Z #1\Z}{#6}}%
{\romannumeral0\xintiiadd{\XINT_mul_fork #5\Z #1\Z}{#7}}%
{#2}{#3}{#4}{#5}%
}%
\def\XINT_jrr_loop_c #1#2%
{%
\expandafter \XINT_jrr_loop_d \expandafter{#2}{#1}%
}%
\def\XINT_jrr_loop_d #1#2#3#4%
{%
\XINT_jrr_loop_e #3\Z {#4}{#2}{#1}%
}%
\def\XINT_jrr_loop_e #1#2\Z
{%
\xint_gob_til_zero #1\XINT_jrr_loop_exit0\XINT_jrr_loop_a {#1#2}%
}%
\def\XINT_jrr_loop_exit0\XINT_jrr_loop_a #1#2#3#4#5#6%
{%
\XINT_irr_finish {#3}{#4}%
}%
% \end{macrocode}
% \subsection{\csh{xintTFrac}}
% \lverb|1.09i, for frac in \xintexpr. And \xintFrac is already assigned. T for
% truncation. However, potentially not very efficient with numbers in scientific
% notations, with big exponents. Will have to think it again some day. I
% hesitated how to call the macro. Same convention as in maple, but some people
% reserve fractional part to x - floor(x). Also, not clear if I had to make it
% negative (or zero) if x < 0, or rather always positive. There should be in
% fact such a thing for each rounding function, trunc, round, floor, ceil. |
% \begin{macrocode}
\def\xintTFrac {\romannumeral0\xinttfrac }%
\def\xinttfrac #1{\expandafter\XINT_tfrac_fork\romannumeral0\xintrawwithzeros {#1}\Z }%
\def\XINT_tfrac_fork #1%
{%
\xint_UDzerominusfork
#1-\XINT_tfrac_zero
0#1{\xintiiopp\XINT_tfrac_P }%
0-{\XINT_tfrac_P #1}%
\krof
}%
\def\XINT_tfrac_zero #1\Z { 0/1[0]}%
\def\XINT_tfrac_P #1/#2\Z {\expandafter\XINT_rez_AB
\romannumeral0\xintiirem{#1}{#2}\Z {0}{#2}}%
% \end{macrocode}
% \subsection{\csh{xintTrunc}, \csh{xintiTrunc}}
% \begin{macrocode}
\def\xintTrunc {\romannumeral0\xinttrunc }%
\def\xintiTrunc {\romannumeral0\xintitrunc }%
\def\xinttrunc #1%
{%
\expandafter\XINT_trunc\expandafter {\the\numexpr #1}%
}%
\def\XINT_trunc #1#2%
{%
\expandafter\XINT_trunc_G
\romannumeral0\expandafter\XINT_trunc_A
\romannumeral0\XINT_infrac {#2}{#1}{#1}%
}%
\def\xintitrunc #1%
{%
\expandafter\XINT_itrunc\expandafter {\the\numexpr #1}%
}%
\def\XINT_itrunc #1#2%
{%
\expandafter\XINT_itrunc_G
\romannumeral0\expandafter\XINT_trunc_A
\romannumeral0\XINT_infrac {#2}{#1}{#1}%
}%
\def\XINT_trunc_A #1#2#3#4%
{%
\expandafter\XINT_trunc_checkifzero
\expandafter{\the\numexpr #1+#4}#2\Z {#3}%
}%
\def\XINT_trunc_checkifzero #1#2#3\Z
{%
\xint_gob_til_zero #2\XINT_trunc_iszero0\XINT_trunc_B {#1}{#2#3}%
}%
\def\XINT_trunc_iszero0\XINT_trunc_B #1#2#3{ 0\Z 0}%
\def\XINT_trunc_B #1%
{%
\ifcase\XINT_cntSgn #1\Z
\expandafter\XINT_trunc_D
\or
\expandafter\XINT_trunc_D
\else
\expandafter\XINT_trunc_C
\fi
{#1}%
}%
\def\XINT_trunc_C #1#2#3%
{%
\expandafter\XINT_trunc_CE\expandafter
{\romannumeral0\XINT_dsx_zeroloop -#1.{}\Z {#3}}{#2}%
}%
\def\XINT_trunc_CE #1#2{\XINT_trunc_E #2.{#1}}%
\def\XINT_trunc_D #1#2%
{%
\expandafter\XINT_trunc_E
\romannumeral0\XINT_dsx_zeroloop #1.{}\Z {#2}.%
}%
\def\XINT_trunc_E #1%
{%
\xint_UDsignfork
#1\XINT_trunc_Fneg
-{\XINT_trunc_Fpos #1}%
\krof
}%
\def\XINT_trunc_Fneg #1.#2{\expandafter\xint_firstoftwo_thenstop
\romannumeral0\XINT_div_prepare {#2}{#1}\Z -}%
\def\XINT_trunc_Fpos #1.#2{\expandafter\xint_firstoftwo_thenstop
\romannumeral0\XINT_div_prepare {#2}{#1}\Z \space }%
\def\XINT_itrunc_G #1#2\Z #3#4%
{%
\xint_gob_til_zero #1\XINT_trunc_zero 0#3#1#2%
}%
\def\XINT_trunc_zero 0#1#20{ 0}%
\def\XINT_trunc_G #1\Z #2#3%
{%
\xint_gob_til_zero #2\XINT_trunc_zero 0%
\expandafter\XINT_trunc_H\expandafter
{\the\numexpr\romannumeral0\xintlength {#1}-#3}{#3}{#1}#2%
}%
\def\XINT_trunc_H #1#2%
{%
\ifnum #1 > \xint_c_
\xint_afterfi {\XINT_trunc_Ha {#2}}%
\else
\xint_afterfi {\XINT_trunc_Hb {-#1}}% -0,--1,--2, ....
\fi
}%
\def\XINT_trunc_Ha
{%
\expandafter\XINT_trunc_Haa\romannumeral0\xintdecsplit
}%
\def\XINT_trunc_Haa #1#2#3%
{%
#3#1.#2%
}%
\def\XINT_trunc_Hb #1#2#3%
{%
\expandafter #3\expandafter0\expandafter.%
\romannumeral0\XINT_dsx_zeroloop #1.{}\Z {}#2% #1=-0 autoris\'e !
}%
% \end{macrocode}
% \subsection{\csh{xintTTrunc}}
% \lverb|1.1, a tiny bit more efficient than doing \xintiTrunc0. I map \xintNum
% to it, and I use it in \xintexpr for various things. Faster I guess than the
% \xintiFloor.|
% \begin{macrocode}
\def\xintTTrunc {\romannumeral0\xintttrunc }%
\def\xintttrunc #1%
{%
\expandafter\XINT_itrunc_G
\romannumeral0\expandafter\XINT_ttrunc_A
\romannumeral0\XINT_infrac {#1}0% this last 0 to let \XINT_itrunc_G be happy
}%
\def\XINT_ttrunc_A #1#2#3{\XINT_trunc_checkifzero {#1}#2\Z {#3}}%
% \end{macrocode}
% \subsection{\csh{xintNum}}
% \begin{macrocode}
\let\xintNum \xintTTrunc
\let\xintnum \xintttrunc
% \end{macrocode}
% \subsection{\csh{xintRound}, \csh{xintiRound}}
% \begin{macrocode}
\def\xintRound {\romannumeral0\xintround }%
\def\xintiRound {\romannumeral0\xintiround }%
\def\xintround #1%
{%
\expandafter\XINT_round\expandafter {\the\numexpr #1}%
}%
\def\XINT_round
{%
\expandafter\XINT_trunc_G\romannumeral0\XINT_round_A
}%
\def\xintiround #1%
{%
\expandafter\XINT_iround\expandafter {\the\numexpr #1}%
}%
\def\XINT_iround
{%
\expandafter\XINT_itrunc_G\romannumeral0\XINT_round_A
}%
\def\XINT_round_A #1#2%
{%
\expandafter\XINT_round_B
\romannumeral0\expandafter\XINT_trunc_A
\romannumeral0\XINT_infrac {#2}{#1+\xint_c_i}{#1}%
}%
\def\XINT_round_B #1\Z
{%
\expandafter\XINT_round_C
\romannumeral0\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax
\Z
}%
\def\XINT_round_C #1%
{%
\ifnum #1<\xint_c_v
\expandafter\XINT_round_Daa
\else
\expandafter\XINT_round_Dba
\fi
}%
\def\XINT_round_Daa #1%
{%
\xint_gob_til_Z #1\XINT_round_Daz\Z \XINT_round_Da #1%
}%
\def\XINT_round_Daz\Z \XINT_round_Da \Z { 0\Z }%
\def\XINT_round_Da #1\Z
{%
\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax \Z
}%
\def\XINT_round_Dba #1%
{%
\xint_gob_til_Z #1\XINT_round_Dbz\Z \XINT_round_Db #1%
}%
\def\XINT_round_Dbz\Z \XINT_round_Db \Z { 1\Z }%
\def\XINT_round_Db #1\Z
{%
\XINT_addm_A 0{}1000\W\X\Y\Z #1000\W\X\Y\Z \Z
}%
% \end{macrocode}
% \subsection{\csh{xintXTrunc}}
% \lverb@1.09j [2014/01/06] This is completely expandable but not f-expandable.
% Designed be used inside an \edef or a \write, if one is interested in getting
% tens of thousands of digits from the decimal expansion of some fraction... it
% is not worth using it rather than \xintTrunc if for less than *hundreds* of
% digits. For efficiency it clones part of the preparatory division macros, as
% the same denominator will be used again and again. The D parameter which says
% how many digits to keep after decimal mark must be at least 1 (and it is
% forcefully set to such a value if found negative or zero, to avoid an eternal
% loop).
%
% For reasons of efficiency I try to use the shortest possible denominator, so
% if the fraction is A/B[N], I want to use B. For N at least zero, just
% immediately replace A by A.10^N. The first division then may be a little
% longish but the next ones will be fast (if B is not too big). For N<0, this is
% a bit more complicated. I thought somewhat about this, and I would need a
% rather complicated approach going through a long division algorithm, forcing
% me to essentially clone the actual division with some differences; a side
% thing is that as this would use blocks of four digits I would have a hard time
% allowing a non-multiple of four number of post decimal mark digits.
%
% Thus, for N<0, another method is followed. First the euclidean division
% A/B=Q+R/B is done. The number of digits of Q is M. If |N|\leq D, we launch
% inside a \csname the routine for obtaining D-|N| next digits (this may impact
% TeX's memory if D is very big), call them T. We then need to position the
% decimal mark D slots from the right of QT, which has length M+D-|N|, hence |N|
% slots from the right of Q. We thus avoid having to work will the T, as D may
% be very very big (\xintXTrunc's only goal is to make it possible to learn by
% hearts decimal expansions with thousands of digits). We can use the
% \xintDecSplit for that on Q . Computing the length M of Q was a more or less
% unavoidable step. If |N|>D, the \csname step is skipped we need to remove the
% D-|N| last digits from Q, etc.. we compare D-|N| with the length M of Q etc...
% (well in this last, very uncommon, branch, I stopped trying to optimize things
% and I even do an \xintnum to ensure a 0 if something comes out empty from
% \xintDecSplit).
%
% [2015/10/04] Although the explanations above are extremely clear, there are
% just too complicated for me to be now able to understand them fully. I
% miraculously managed to do the minimal changes (all happens between
% \XINT_xtrunc_Q and \XINT_xtrunc_Pa) in order for \xintXTrunc to use the 1.2
% division routine. Seems to work. But some thought should be given to how to
% adapt \xintXTrunc for it to better use the abilities and characteristics of
% the new division routines in xincore.@
% \begin{macrocode}
\def\xintXTrunc #1#2%
{%
\expandafter\XINT_xtrunc_a\expandafter
{\the\numexpr #1\expandafter}\romannumeral0\xintraw {#2}%
}%
\def\XINT_xtrunc_a #1%
{%
\expandafter\XINT_xtrunc_b\expandafter
{\the\numexpr\ifnum#1<\xint_c_i \xint_c_i-\fi #1}%
}%
\def\XINT_xtrunc_b #1%
{%
\expandafter\XINT_xtrunc_c\expandafter
{\the\numexpr (#1+\xint_c_ii^v)/\xint_c_ii^vi-\xint_c_i}{#1}%
}%
\def\XINT_xtrunc_c #1#2%
{%
\expandafter\XINT_xtrunc_d\expandafter
{\the\numexpr #2-\xint_c_ii^vi*#1}{#1}{#2}%
}%
\def\XINT_xtrunc_d #1#2#3#4/#5[#6]%
{%
\XINT_xtrunc_e #4.{#6}{#5}{#3}{#2}{#1}%
}%
% \end{macrocode}
% \lverb+#1=numerator.#2=N,#3=B,#4=D,#5=Blocs,#6=extra+
% \begin{macrocode}
\def\XINT_xtrunc_e #1%
{%
\xint_UDzerominusfork
#1-\XINT_xtrunc_zero
0#1\XINT_xtrunc_N
0-{\XINT_xtrunc_P #1}%
\krof
}%
\def\XINT_xtrunc_zero .#1#2#3#4#5%
{%
0.\romannumeral0\expandafter\XINT_dsx_zeroloop
\the\numexpr #5.{}\Z {}%
\xintiloop [#4+-1]
\ifnum \xintiloopindex>\xint_c_
0000000000000000000000000000000000000000000000000000000000000000%
\repeat
}%
\def\XINT_xtrunc_N {-\XINT_xtrunc_P }%
\def\XINT_xtrunc_P #1.#2%
{%
\ifnum #2<\xint_c_
\expandafter\XINT_xtrunc_negN_Q
\else
\expandafter\XINT_xtrunc_Q
\fi {#2}{#1}.%
}%
\def\XINT_xtrunc_negN_Q #1#2.#3#4#5#6%
{%
\expandafter\XINT_xtrunc_negN_R
\romannumeral0\XINT_div_prepare {#3}{#2}{#3}{#1}{#4}%
}%
% \end{macrocode}
% \lverb+#1=Q, #2=R, #3=B, #4=N<0, #5=D+
% \begin{macrocode}
\def\XINT_xtrunc_negN_R #1#2#3#4#5%
{%
\expandafter\XINT_xtrunc_negN_S\expandafter
{\the\numexpr -#4}{#5}{#2}{#3}{#1}%
}%
\def\XINT_xtrunc_negN_S #1#2%
{%
\expandafter\XINT_xtrunc_negN_T\expandafter
{\the\numexpr #2-#1}{#1}{#2}%
}%
\def\XINT_xtrunc_negN_T #1%
{%
\ifnum \xint_c_<#1
\expandafter\XINT_xtrunc_negNA
\else
\expandafter\XINT_xtrunc_negNW
\fi {#1}%
}%
% \end{macrocode}
% \lverb+#1=D-|N|>0, #2=|N|, #3=D, #4=R, #5=B, #6=Q+
% \begin{macrocode}
\def\XINT_xtrunc_unlock #10.{ }%
\def\XINT_xtrunc_negNA #1#2#3#4#5#6%
{%
\expandafter\XINT_xtrunc_negNB\expandafter
{\romannumeral0\expandafter\expandafter\expandafter
\XINT_xtrunc_unlock\expandafter\string
\csname\XINT_xtrunc_b {#1}#4/#5[0]\expandafter\endcsname
\expandafter}\expandafter
{\the\numexpr\xintLength{#6}-#2}{#6}%
}%
\def\XINT_xtrunc_negNB #1#2#3{\XINT_xtrunc_negNC {#2}{#3}#1}%
\def\XINT_xtrunc_negNC #1%
{%
\ifnum \xint_c_ < #1
\expandafter\XINT_xtrunc_negNDa
\else
\expandafter\XINT_xtrunc_negNE
\fi {#1}%
}%
\def\XINT_xtrunc_negNDa #1#2%
{%
\expandafter\XINT_xtrunc_negNDb%
\romannumeral0\XINT_split_fromleft_loop #1.{}#2\W\W\W\W\W\W\W\W\Z
}%
\def\XINT_xtrunc_negNDb #1.#2.{#1.#2}%
\def\XINT_xtrunc_negNE #1#2%
{%
0.\romannumeral0\XINT_dsx_zeroloop -#1.{}\Z {}#2%
}%
% \end{macrocode}
% \lverb+#1=D-|N|<=0, #2=|N|, #3=D, #4=R, #5=B, #6=Q+
% \begin{macrocode}
\def\XINT_xtrunc_negNW #1#2#3#4#5#6%
{%
\expandafter\XINT_xtrunc_negNX\expandafter
{\romannumeral0\xintnum{\xintDecSplitL {-#1}{#6}}}{#3}%
}%
\def\XINT_xtrunc_negNX #1#2%
{%
\expandafter\XINT_xtrunc_negNC\expandafter
{\the\numexpr\xintLength {#1}-#2}{#1}%
}%
\def\XINT_xtrunc_BisOne #1#2#3#4#5#6#7%
{%
#5.\romannumeral0\expandafter\XINT_dsx_zeroloop
\the\numexpr #7.{}\Z {}%
\xintiloop [#6+-1]
\ifnum \xintiloopindex>\xint_c_
0000000000000000000000000000000000000000000000000000000000000000%
\repeat
}%
\def\XINT_xtrunc_BisTwo #1#2#3#4#5#6#7%
{%
\xintHalf {#5}.\ifodd\xintiiLDg{#5} 5\else 0\fi
\romannumeral0\expandafter\XINT_dsx_zeroloop
\the\numexpr #7-\xint_c_i.{}\Z {}%
\xintiloop [#6+-1]
\ifnum \xintiloopindex>\xint_c_
0000000000000000000000000000000000000000000000000000000000000000%
\repeat
}%
\def\XINT_xtrunc_Q #1%
{%
\expandafter\XINT_xtrunc_prepare
\romannumeral0\XINT_dsx_zeroloop #1.{}\Z
}%
\def\XINT_xtrunc_prepare #1.#2#3%
{%
\expandafter\XINT_xtrunc_Pa\expandafter
{\romannumeral0%
\XINT_xtrunc_prepare_a #2\R\R\R\R\R\R\R\R {10}0000001\W !{#2}}{#1}%
}%
\def\XINT_xtrunc_prepare_a #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_xtrunc_prepare_small\R
\XINT_xtrunc_prepare_b #9%
}%
\def\XINT_xtrunc_prepare_small\R #1!#2%
{%
\ifcase #2
\or\xint_afterfi{ \XINT_div_BisOne}%
\or\xint_afterfi{ \XINT_div_BisTwo}%
\else\expandafter\XINT_xtrunc_small_aa
\fi {#2}%
}%
\def\XINT_xtrunc_small_aa #1%
{%
\expandafter\space\expandafter\XINT_xtrunc_small_a
\the\numexpr #1/\xint_c_ii\expandafter
.\the\numexpr \xint_c_x^viii+#1!%
}%
\def\XINT_xtrunc_small_a #1.#2!#3%
{%
\expandafter\XINT_div_small_b\the\numexpr #1\expandafter
.\the\numexpr #2\expandafter!%
\romannumeral0\XINT_div_small_ba #3\R\R\R\R\R\R\R\R{10}0000001\W
#3\XINT_sepbyviii_Z_end 2345678\relax
}%
\def\XINT_xtrunc_prepare_b
{\expandafter\XINT_xtrunc_prepare_c\romannumeral0\XINT_zeroes_forviii }%
\def\XINT_xtrunc_prepare_c #1!%
{%
\XINT_xtrunc_prepare_d #1.00000000!{#1}%
}%
\def\XINT_xtrunc_prepare_d #1#2#3#4#5#6#7#8#9%
{%
\expandafter\XINT_xtrunc_prepare_e\xint_gob_til_dot #1#2#3#4#5#6#7#8#9!%
}%
\def\XINT_xtrunc_prepare_e #1!#2!#3#4%
{%
\XINT_xtrunc_prepare_f #4#3\X {#1}{#3}%
}%
\def\XINT_xtrunc_prepare_f #1#2#3#4#5#6#7#8#9\X
{%
\expandafter\space\expandafter\XINT_div_prepare_g
\the\numexpr #1#2#3#4#5#6#7#8+\xint_c_i\expandafter
.\the\numexpr (#1#2#3#4#5#6#7#8+\xint_c_i)/\xint_c_ii\expandafter
.\the\numexpr #1#2#3#4#5#6#7#8\expandafter
.\romannumeral0\XINT_sepandrev_andcount
#1#2#3#4#5#6#7#8#9\XINT_rsepbyviii_end_A 2345678%
\XINT_rsepbyviii_end_B 2345678%
\relax\xint_c_ii\xint_c_iii
\R.\xint_c_vi\R.\xint_c_v\R.\xint_c_iv\R.\xint_c_iii
\R.\xint_c_ii\R.\xint_c_i\R.\xint_c_\W
\X
}%
\def\XINT_xtrunc_Pa #1#2%
{%
\expandafter\XINT_xtrunc_Pb\romannumeral0#1{#2}{#1}%
}%
\def\XINT_xtrunc_Pb #1#2#3#4{#1.\XINT_xtrunc_A {#4}{#2}{#3}}%
\def\XINT_xtrunc_A #1%
{%
\unless\ifnum #1>\xint_c_ \XINT_xtrunc_transition\fi
\expandafter\XINT_xtrunc_B\expandafter{\the\numexpr #1-\xint_c_i}%
}%
\def\XINT_xtrunc_B #1#2#3%
{%
\expandafter\XINT_xtrunc_D\romannumeral0#3%
{#20000000000000000000000000000000000000000000000000000000000000000}%
{#1}{#3}%
}%
\def\XINT_xtrunc_D #1#2#3%
{%
\romannumeral0\expandafter\XINT_dsx_zeroloop
\the\numexpr \xint_c_ii^vi-\xintLength{#1}.{}\Z {}#1%
\XINT_xtrunc_A {#3}{#2}%
}%
\def\XINT_xtrunc_transition\fi
\expandafter\XINT_xtrunc_B\expandafter #1#2#3#4%
{%
\fi
\ifnum #4=\xint_c_ \XINT_xtrunc_abort\fi
\expandafter\XINT_xtrunc_x\expandafter
{\romannumeral0\XINT_dsx_zeroloop #4.{}\Z {#2}}{#3}{#4}%
}%
\def\XINT_xtrunc_x #1#2%
{%
\expandafter\XINT_xtrunc_y\romannumeral0#2{#1}%
}%
\def\XINT_xtrunc_y #1#2#3%
{%
\romannumeral0\expandafter\XINT_dsx_zeroloop
\the\numexpr #3-\xintLength{#1}.{}\Z {}#1%
}%
\def\XINT_xtrunc_abort\fi\expandafter\XINT_xtrunc_x\expandafter #1#2#3{\fi}%
% \end{macrocode}
% \subsection{\csh{xintDigits}}
% \lverb|The mathchardef used to be called \XINT_digits, but for reasons
% originating in \xintNewExpr (and now obsolete), release 1.09a uses
% \XINTdigits without underscore.|
% \begin{macrocode}
\mathchardef\XINTdigits 16
\def\xintDigits #1#2%
{\afterassignment \xint_gobble_i \mathchardef\XINTdigits=}%
\def\xinttheDigits {\number\XINTdigits }%
% \end{macrocode}
% \subsection{\csh{xintAdd}}
% \begin{macrocode}
\def\xintAdd {\romannumeral0\xintadd }%
\def\xintadd #1{\expandafter\XINT_fadd\romannumeral0\xintraw {#1}}%
\def\XINT_fadd #1{\xint_gob_til_zero #1\XINT_fadd_Azero 0\XINT_fadd_a #1}%
\def\XINT_fadd_Azero #1]{\xintraw }%
\def\XINT_fadd_a #1/#2[#3]#4%
{\expandafter\XINT_fadd_b\romannumeral0\xintraw {#4}{#3}{#1}{#2}}%
\def\XINT_fadd_b #1{\xint_gob_til_zero #1\XINT_fadd_Bzero 0\XINT_fadd_c #1}%
\def\XINT_fadd_Bzero #1]#2#3#4{ #3/#4[#2]}%
\def\XINT_fadd_c #1/#2[#3]#4%
{%
\expandafter\XINT_fadd_Aa\expandafter{\the\numexpr #4-#3}{#3}{#4}{#1}{#2}%
}%
\def\XINT_fadd_Aa #1%
{%
\ifcase\XINT_cntSgn #1\Z
\expandafter\XINT_fadd_B
\or
\expandafter \XINT_fadd_Ba
\else
\expandafter \XINT_fadd_Bb
\fi {#1}%
}%
\def\XINT_fadd_B #1#2#3#4#5#6#7{\XINT_fadd_C {#4}{#5}{#7}{#6}[#3]}%
\def\XINT_fadd_Ba #1#2#3#4#5#6#7%
{%
\expandafter\XINT_fadd_C\expandafter
{\romannumeral0\XINT_dsx_zeroloop #1.{}\Z {#6}}%
{#7}{#5}{#4}[#2]%
}%
\def\XINT_fadd_Bb #1#2#3#4#5#6#7%
{%
\expandafter\XINT_fadd_C\expandafter
{\romannumeral0\XINT_dsx_zeroloop -#1.{}\Z {#4}}%
{#5}{#7}{#6}[#3]%
}%
\def\XINT_fadd_C #1#2#3%
{%
\ifcase\romannumeral0\xintiicmp {#2}{#3} %<- intentional space here.
\expandafter\XINT_fadd_eq
\or\expandafter\XINT_fadd_D
\else\expandafter\XINT_fadd_Da
\fi {#2}{#3}{#1}%
}%
\def\XINT_fadd_eq #1#2#3#4%#5%
{%
\expandafter\XINT_fadd_G
\romannumeral0\xintiiadd {#3}{#4}/#1%[#5]%
}%
\def\XINT_fadd_D #1#2%
{%
\expandafter\XINT_fadd_E\romannumeral0\XINT_div_prepare {#2}{#1}{#1}{#2}%
}%
\def\XINT_fadd_E #1#2%
{%
\if0\XINT_Sgn #2\Z
\expandafter\XINT_fadd_F
\else\expandafter\XINT_fadd_K
\fi {#1}%
}%
\def\XINT_fadd_F #1#2#3#4#5%#6%
{%
\expandafter\XINT_fadd_G
\romannumeral0\xintiiadd {\xintiiMul {#5}{#1}}{#4}/#2%[#6]%
}%
\def\XINT_fadd_Da #1#2%
{%
\expandafter\XINT_fadd_Ea\romannumeral0\XINT_div_prepare {#1}{#2}{#1}{#2}%
}%
\def\XINT_fadd_Ea #1#2%
{%
\if0\XINT_Sgn #2\Z
\expandafter\XINT_fadd_Fa
\else\expandafter\XINT_fadd_K
\fi {#1}%
}%
\def\XINT_fadd_Fa #1#2#3#4#5%#6%
{%
\expandafter\XINT_fadd_G
\romannumeral0\xintiiadd {\xintiiMul {#4}{#1}}{#5}/#3%[#6]%
}%
\def\XINT_fadd_G #1{\if0#1\XINT_fadd_iszero\fi\space #1}%
\def\XINT_fadd_K #1#2#3#4#5%
{%
\expandafter\XINT_fadd_L
\romannumeral0\xintiiadd {\xintiiMul {#2}{#5}}{\xintiiMul {#3}{#4}}.%
{{#2}{#3}}%
}%
\def\XINT_fadd_L #1{\if0#1\XINT_fadd_iszero\fi \XINT_fadd_M #1}%
\def\XINT_fadd_M #1.#2{\expandafter\XINT_fadd_N \expandafter
{\romannumeral0\xintiimul #2}{#1}}%
\def\XINT_fadd_N #1#2{ #2/#1}%
\edef\XINT_fadd_iszero\fi #1[#2]{\noexpand\fi\space 0/1[0]}% ou [#2] originel?
% \end{macrocode}
% \subsection{\csh{xintSub}}
% \begin{macrocode}
\def\xintSub {\romannumeral0\xintsub }%
\def\xintsub #1{\expandafter\XINT_fsub\romannumeral0\xintraw {#1}}%
\def\XINT_fsub #1{\xint_gob_til_zero #1\XINT_fsub_Azero 0\XINT_fsub_a #1}%
\def\XINT_fsub_Azero #1]{\xintopp }%
\def\XINT_fsub_a #1/#2[#3]#4%
{\expandafter\XINT_fsub_b\romannumeral0\xintraw {#4}{#3}{#1}{#2}}%
\def\XINT_fsub_b #1{\xint_UDzerominusfork
#1-\XINT_fadd_Bzero
0#1\XINT_fadd_c
0-{\XINT_fadd_c -#1}%
\krof }%
% \end{macrocode}
% \subsection{\csh{xintSum}}
% \begin{macrocode}
\def\xintSum {\romannumeral0\xintsum }%
\def\xintsum #1{\xintsumexpr #1\relax }%
\def\xintSumExpr {\romannumeral0\xintsumexpr }%
\def\xintsumexpr {\expandafter\XINT_fsumexpr\romannumeral`&&@}%
\def\XINT_fsumexpr {\XINT_fsum_loop_a {0/1[0]}}%
\def\XINT_fsum_loop_a #1#2%
{%
\expandafter\XINT_fsum_loop_b \romannumeral`&&@#2\Z {#1}%
}%
\def\XINT_fsum_loop_b #1%
{%
\xint_gob_til_relax #1\XINT_fsum_finished\relax
\XINT_fsum_loop_c #1%
}%
\def\XINT_fsum_loop_c #1\Z #2%
{%
\expandafter\XINT_fsum_loop_a\expandafter{\romannumeral0\xintadd {#2}{#1}}%
}%
\def\XINT_fsum_finished #1\Z #2{ #2}%
% \end{macrocode}
% \subsection{\csh{xintMul}}
% \begin{macrocode}
\def\xintMul {\romannumeral0\xintmul }%
\def\xintmul #1{\expandafter\XINT_fmul\romannumeral0\xintraw {#1}.}%
\def\XINT_fmul #1{\xint_gob_til_zero #1\XINT_fmul_zero 0\XINT_fmul_a #1}%
\def\XINT_fmul_a #1[#2].#3%
{\expandafter\XINT_fmul_b\romannumeral0\xintraw {#3}#1[#2.]}%
\def\XINT_fmul_b #1{\xint_gob_til_zero #1\XINT_fmul_zero 0\XINT_fmul_c #1}%
\def\XINT_fmul_c #1/#2[#3]#4/#5[#6.]%
{%
\expandafter\XINT_fmul_d
\expandafter{\the\numexpr #3+#6\expandafter}%
\expandafter{\romannumeral0\xintiimul {#5}{#2}}%
{\romannumeral0\xintiimul {#4}{#1}}%
}%
\def\XINT_fmul_d #1#2#3%
{%
\expandafter \XINT_fmul_e \expandafter{#3}{#1}{#2}%
}%
\def\XINT_fmul_e #1#2{\XINT_outfrac {#2}{#1}}%
\def\XINT_fmul_zero #1.#2{ 0/1[0]}%
% \end{macrocode}
% \subsection{\csh{xintSqr}}
% \lverb|1.1 modifs comme xintMul.
%
% ARRRRRGGGGGGH! I realize only on 2016/02/29 that this was broken since
% 1.1 of 2014/10/28 due to a typo in \XINT_fsqr_a, which was written
% \xint_fsqr_a :((((((((. My test files are highly deficient... (they test
% only the xint/xintcore version).|
% \begin{macrocode}
\def\xintSqr {\romannumeral0\xintsqr }%
\def\xintsqr #1{\expandafter\XINT_fsqr\romannumeral0\xintraw {#1}}%
\def\XINT_fsqr #1{\xint_gob_til_zero #1\XINT_fsqr_zero 0\XINT_fsqr_a #1}%
\def\XINT_fsqr_a #1/#2[#3]%
{%
\expandafter\XINT_fsqr_b
\expandafter{\the\numexpr #3+#3\expandafter}%
\expandafter{\romannumeral0\xintiisqr {#2}}%
{\romannumeral0\xintiisqr {#1}}%
}%
\def\XINT_fsqr_b #1#2#3{\expandafter \XINT_fmul_e \expandafter{#3}{#1}{#2}}%
\def\XINT_fsqr_zero #1]{ 0/1[0]}%
% \end{macrocode}
% \subsection{\csh{xintPow}}
% \lverb|&
% 1.2f: to be coherent with the "i" convention \xintiPow should parse also its
% exponent via \xintNum when xintfrac.sty is loaded. This was not the case so
% far. Cependant le problème est que le fait d'appliquer \xintNum rend
% impossible certains inputs qui auraient pu être gérès par \numexpr. Le
% \numexpr externe est ici pour intercepter trop grand input.
% |
% \begin{macrocode}
\def\xintipow #1#2%
{%
\expandafter\xint_pow\the\numexpr \xintNum{#2}\expandafter.\romannumeral0\xintnum{#1}\Z%
}%
\def\xintPow {\romannumeral0\xintpow }%
\def\xintpow #1%
{%
\expandafter\XINT_fpow\expandafter {\romannumeral0\XINT_infrac {#1}}%
}%
\def\XINT_fpow #1#2%
{%
\expandafter\XINT_fpow_fork\the\numexpr \xintNum{#2}\relax\Z #1%
}%
\def\XINT_fpow_fork #1#2\Z
{%
\xint_UDzerominusfork
#1-\XINT_fpow_zero
0#1\XINT_fpow_neg
0-{\XINT_fpow_pos #1}%
\krof
{#2}%
}%
\def\XINT_fpow_zero #1#2#3#4{ 1/1[0]}%
\def\XINT_fpow_pos #1#2#3#4#5%
{%
\expandafter\XINT_fpow_pos_A\expandafter
{\the\numexpr #1#2*#3\expandafter}\expandafter
{\romannumeral0\xintiipow {#5}{#1#2}}%
{\romannumeral0\xintiipow {#4}{#1#2}}%
}%
\def\XINT_fpow_neg #1#2#3#4%
{%
\expandafter\XINT_fpow_pos_A\expandafter
{\the\numexpr -#1*#2\expandafter}\expandafter
{\romannumeral0\xintiipow {#3}{#1}}%
{\romannumeral0\xintiipow {#4}{#1}}%
}%
\def\XINT_fpow_pos_A #1#2#3%
{%
\expandafter\XINT_fpow_pos_B\expandafter {#3}{#1}{#2}%
}%
\def\XINT_fpow_pos_B #1#2{\XINT_outfrac {#2}{#1}}%
% \end{macrocode}
% \subsection{\csh{xintiFac}}
% \lverb|&
%
% Note pour 1.2f: il y avait un peu de confusion avec \xintFac, \xintiFac,
% \xintiiFac, car \xintiFac aurait dû aussi utiliser \xintNum une fois
% xintfrac.sty chargé ce qu'elle ne faisait pas. \xintNum est nécessaire pour
% gérer des inputs fractionnaires ou avec [N], car il les transforme en entiers
% stricts, et la doc dit que les macros avec "i" l'utilise. Maintenant
% \xintiFac fait la chose correcte. \xintFac est synonyme.
%
% 2015/11/29: NO MORE a \xintFac, only \xintiFac/\xintiiFac.|
% \begin{macrocode}
\def\xintifac #1{\expandafter\XINT_fac_fork\the\numexpr \xintNum{#1}.}%
% \end{macrocode}
% \subsection{\csh{xintiBinomial}}
% \lverb|1.2f. Binomial coefficients.|
% \begin{macrocode}
\def\xintibinomial #1#2%
{%
\expandafter\XINT_binom_pre
\the\numexpr\xintNum{#1}\expandafter.\the\numexpr\xintNum{#2}.%
}%
% \end{macrocode}
% \subsection{\csh{xintiPFactorial}}
% \lverb|1.2f. Partial factorial.|
% \begin{macrocode}
\def\xintipfactorial #1#2%
{%
\expandafter\XINT_pfac_fork
\the\numexpr\xintNum{#1}\expandafter.\the\numexpr\xintNum{#2}.%
}%
% \end{macrocode}
% \subsection{\csh{xintPrd}}
% \begin{macrocode}
\def\xintPrd {\romannumeral0\xintprd }%
\def\xintprd #1{\xintprdexpr #1\relax }%
\def\xintPrdExpr {\romannumeral0\xintprdexpr }%
\def\xintprdexpr {\expandafter\XINT_fprdexpr \romannumeral`&&@}%
\def\XINT_fprdexpr {\XINT_fprod_loop_a {1/1[0]}}%
\def\XINT_fprod_loop_a #1#2%
{%
\expandafter\XINT_fprod_loop_b \romannumeral`&&@#2\Z {#1}%
}%
\def\XINT_fprod_loop_b #1%
{%
\xint_gob_til_relax #1\XINT_fprod_finished\relax
\XINT_fprod_loop_c #1%
}%
\def\XINT_fprod_loop_c #1\Z #2%
{%
\expandafter\XINT_fprod_loop_a\expandafter{\romannumeral0\xintmul {#1}{#2}}%
}%
\def\XINT_fprod_finished #1\Z #2{ #2}%
% \end{macrocode}
% \subsection{\csh{xintDiv}}
% \begin{macrocode}
\def\xintDiv {\romannumeral0\xintdiv }%
\def\xintdiv #1%
{%
\expandafter\XINT_fdiv\expandafter {\romannumeral0\XINT_infrac {#1}}%
}%
\def\XINT_fdiv #1#2%
{\expandafter\XINT_fdiv_A\romannumeral0\XINT_infrac {#2}#1}%
\def\XINT_fdiv_A #1#2#3#4#5#6%
{%
\expandafter\XINT_fdiv_B
\expandafter{\the\numexpr #4-#1\expandafter}%
\expandafter{\romannumeral0\xintiimul {#2}{#6}}%
{\romannumeral0\xintiimul {#3}{#5}}%
}%
\def\XINT_fdiv_B #1#2#3%
{%
\expandafter\XINT_fdiv_C
\expandafter{#3}{#1}{#2}%
}%
\def\XINT_fdiv_C #1#2{\XINT_outfrac {#2}{#1}}%
% \end{macrocode}
% \subsection{\csh{xintDivFloor}}
% \lverb|1.1|
% \begin{macrocode}
\def\xintDivFloor {\romannumeral0\xintdivfloor }%
\def\xintdivfloor #1#2{\xintfloor{\xintDiv {#1}{#2}}}%
% \end{macrocode}
% \subsection{\csh{xintDivTrunc}}
% \lverb|1.1. \xintttrunc rather than \xintitrunc0 in 1.1a|
% \begin{macrocode}
\def\xintDivTrunc {\romannumeral0\xintdivtrunc }%
\def\xintdivtrunc #1#2{\xintttrunc {\xintDiv {#1}{#2}}}%
% \end{macrocode}
% \subsection{\csh{xintDivRound}}
% \lverb|1.1|
% \begin{macrocode}
\def\xintDivRound {\romannumeral0\xintdivround }%
\def\xintdivround #1#2{\xintiround 0{\xintDiv {#1}{#2}}}%
% \end{macrocode}
% \subsection{\csh{xintMod}}
% \lverb|1.1. \xintMod {q1}{q2} computes q2*t(q1/q2) with t(q1/q2) equal to
% the truncated division of two arbitrary fractions q1 and q2. We put some
% efforts into minimizing the amount of computations. Oui, et bien cela aurait
% été bien si j'avais aussi daigné commenté ce que je faisais.|
% \begin{macrocode}
\def\xintMod {\romannumeral0\xintmod }%
\def\xintmod #1{\expandafter\XINT_mod_a\romannumeral0\xintraw{#1}.}%
\def\XINT_mod_a #1#2.#3%
{\expandafter\XINT_mod_b\expandafter #1\romannumeral0\xintraw{#3}#2.}%
\def\XINT_mod_b #1#2% #1 de A, #2 de B.
{%
\if0#2\xint_dothis\XINT_mod_divbyzero\fi
\if0#1\xint_dothis\XINT_mod_aiszero\fi
\if-#2\xint_dothis{\XINT_mod_bneg #1}\fi
\xint_orthat{\XINT_mod_bpos #1#2}%
}%
\def\XINT_mod_bpos #1%
{%
\xint_UDsignfork
#1{\xintiiopp\XINT_mod_pos {}}%
-{\XINT_mod_pos #1}%
\krof
}%
\def\XINT_mod_bneg #1%
{%
\xint_UDsignfork
#1{\xintiiopp\XINT_mod_pos {}}%
-{\XINT_mod_pos #1}%
\krof
}%
\def\XINT_mod_divbyzero #1.{\xintError:DivisionByZero\space 0/1[0]}%
\def\XINT_mod_aiszero #1.{ 0/1[0]}%
\def\XINT_mod_pos #1#2/#3[#4]#5/#6[#7].%
{%
\expandafter\XINT_mod_pos_a
\the\numexpr\ifnum#7>#4 #4\else #7\fi\expandafter.\expandafter
{\romannumeral0\xintiimul {#6}{#3}}% n fois u
{\xintiiE{\xintiiMul {#1#5}{#3}}{#7-#4}}% m fois u
{\xintiiE{\xintiiMul {#2}{#6}}{#4-#7}}% t fois n
}%
\def\XINT_mod_pos_a #1.#2#3#4{\xintiirem {#3}{#4}/#2[#1]}%
% \end{macrocode}
% \subsection{\csh{xintIsOne}}
% \lverb|New with 1.09a. Could be more efficient. For fractions with big
% powers of tens, it is better to use \xintCmp{f}{1}. Restyled in 1.09i.|
% \begin{macrocode}
\def\xintIsOne {\romannumeral0\xintisone }%
\def\xintisone #1{\expandafter\XINT_fracisone
\romannumeral0\xintrawwithzeros{#1}\Z }%
\def\XINT_fracisone #1/#2\Z
{\if0\XINT_Cmp {#1}{#2}\xint_afterfi{ 1}\else\xint_afterfi{ 0}\fi}%
% \end{macrocode}
% \subsection{\csh{xintGeq}}
% \begin{macrocode}
\def\xintGeq {\romannumeral0\xintgeq }%
\def\xintgeq #1%
{%
\expandafter\XINT_fgeq\expandafter {\romannumeral0\xintabs {#1}}%
}%
\def\XINT_fgeq #1#2%
{%
\expandafter\XINT_fgeq_A \romannumeral0\xintabs {#2}#1%
}%
\def\XINT_fgeq_A #1%
{%
\xint_gob_til_zero #1\XINT_fgeq_Zii 0%
\XINT_fgeq_B #1%
}%
\def\XINT_fgeq_Zii 0\XINT_fgeq_B #1[#2]#3[#4]{ 1}%
\def\XINT_fgeq_B #1/#2[#3]#4#5/#6[#7]%
{%
\xint_gob_til_zero #4\XINT_fgeq_Zi 0%
\expandafter\XINT_fgeq_C\expandafter
{\the\numexpr #7-#3\expandafter}\expandafter
{\romannumeral0\xintiimul {#4#5}{#2}}%
{\romannumeral0\xintiimul {#6}{#1}}%
}%
\def\XINT_fgeq_Zi 0#1#2#3#4#5#6#7{ 0}%
\def\XINT_fgeq_C #1#2#3%
{%
\expandafter\XINT_fgeq_D\expandafter
{#3}{#1}{#2}%
}%
\def\XINT_fgeq_D #1#2#3%
{%
\expandafter\XINT_cntSgnFork\romannumeral`&&@\expandafter\XINT_cntSgn
\the\numexpr #2+\xintLength{#3}-\xintLength{#1}\relax\Z
{ 0}{\XINT_fgeq_E #2\Z {#3}{#1}}{ 1}%
}%
\def\XINT_fgeq_E #1%
{%
\xint_UDsignfork
#1\XINT_fgeq_Fd
-{\XINT_fgeq_Fn #1}%
\krof
}%
\def\XINT_fgeq_Fd #1\Z #2#3%
{%
\expandafter\XINT_fgeq_Fe\expandafter
{\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#3}}{#2}%
}%
\def\XINT_fgeq_Fe #1#2{\XINT_geq_pre {#2}{#1}}%
\def\XINT_fgeq_Fn #1\Z #2#3%
{%
\expandafter\XINT_geq_pre\expandafter
{\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#2}}{#3}%
}%
% \end{macrocode}
% \subsection{\csh{xintMax}}
% \begin{macrocode}
\def\xintMax {\romannumeral0\xintmax }%
\def\xintmax #1%
{%
\expandafter\XINT_fmax\expandafter {\romannumeral0\xintraw {#1}}%
}%
\def\XINT_fmax #1#2%
{%
\expandafter\XINT_fmax_A\romannumeral0\xintraw {#2}#1%
}%
\def\XINT_fmax_A #1#2/#3[#4]#5#6/#7[#8]%
{%
\xint_UDsignsfork
#1#5\XINT_fmax_minusminus
-#5\XINT_fmax_firstneg
#1-\XINT_fmax_secondneg
--\XINT_fmax_nonneg_a
\krof
#1#5{#2/#3[#4]}{#6/#7[#8]}%
}%
\def\XINT_fmax_minusminus --%
{\expandafter-\romannumeral0\XINT_fmin_nonneg_b }%
\def\XINT_fmax_firstneg #1-#2#3{ #1#2}%
\def\XINT_fmax_secondneg -#1#2#3{ #1#3}%
\def\XINT_fmax_nonneg_a #1#2#3#4%
{%
\XINT_fmax_nonneg_b {#1#3}{#2#4}%
}%
\def\XINT_fmax_nonneg_b #1#2%
{%
\if0\romannumeral0\XINT_fgeq_A #1#2%
\xint_afterfi{ #1}%
\else \xint_afterfi{ #2}%
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintMaxof}}
% \begin{macrocode}
\def\xintMaxof {\romannumeral0\xintmaxof }%
\def\xintmaxof #1{\expandafter\XINT_maxof_a\romannumeral`&&@#1\relax }%
\def\XINT_maxof_a #1{\expandafter\XINT_maxof_b\romannumeral0\xintraw{#1}\Z }%
\def\XINT_maxof_b #1\Z #2%
{\expandafter\XINT_maxof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_maxof_c #1%
{\xint_gob_til_relax #1\XINT_maxof_e\relax\XINT_maxof_d #1}%
\def\XINT_maxof_d #1\Z
{\expandafter\XINT_maxof_b\romannumeral0\xintmax {#1}}%
\def\XINT_maxof_e #1\Z #2\Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintMin}}
% \begin{macrocode}
\def\xintMin {\romannumeral0\xintmin }%
\def\xintmin #1%
{%
\expandafter\XINT_fmin\expandafter {\romannumeral0\xintraw {#1}}%
}%
\def\XINT_fmin #1#2%
{%
\expandafter\XINT_fmin_A\romannumeral0\xintraw {#2}#1%
}%
\def\XINT_fmin_A #1#2/#3[#4]#5#6/#7[#8]%
{%
\xint_UDsignsfork
#1#5\XINT_fmin_minusminus
-#5\XINT_fmin_firstneg
#1-\XINT_fmin_secondneg
--\XINT_fmin_nonneg_a
\krof
#1#5{#2/#3[#4]}{#6/#7[#8]}%
}%
\def\XINT_fmin_minusminus --%
{\expandafter-\romannumeral0\XINT_fmax_nonneg_b }%
\def\XINT_fmin_firstneg #1-#2#3{ -#3}%
\def\XINT_fmin_secondneg -#1#2#3{ -#2}%
\def\XINT_fmin_nonneg_a #1#2#3#4%
{%
\XINT_fmin_nonneg_b {#1#3}{#2#4}%
}%
\def\XINT_fmin_nonneg_b #1#2%
{%
\if0\romannumeral0\XINT_fgeq_A #1#2%
\xint_afterfi{ #2}%
\else \xint_afterfi{ #1}%
\fi
}%
% \end{macrocode}
% \subsection{\csh{xintMinof}}
% \begin{macrocode}
\def\xintMinof {\romannumeral0\xintminof }%
\def\xintminof #1{\expandafter\XINT_minof_a\romannumeral`&&@#1\relax }%
\def\XINT_minof_a #1{\expandafter\XINT_minof_b\romannumeral0\xintraw{#1}\Z }%
\def\XINT_minof_b #1\Z #2%
{\expandafter\XINT_minof_c\romannumeral`&&@#2\Z {#1}\Z}%
\def\XINT_minof_c #1%
{\xint_gob_til_relax #1\XINT_minof_e\relax\XINT_minof_d #1}%
\def\XINT_minof_d #1\Z
{\expandafter\XINT_minof_b\romannumeral0\xintmin {#1}}%
\def\XINT_minof_e #1\Z #2\Z { #2}%
% \end{macrocode}
% \subsection{\csh{xintCmp}}
% \begin{macrocode}
%\def\xintCmp {\romannumeral0\xintcmp }%
\def\xintcmp #1%
{%
\expandafter\XINT_fcmp\expandafter {\romannumeral0\xintraw {#1}}%
}%
\def\XINT_fcmp #1#2%
{%
\expandafter\XINT_fcmp_A\romannumeral0\xintraw {#2}#1%
}%
\def\XINT_fcmp_A #1#2/#3[#4]#5#6/#7[#8]%
{%
\xint_UDsignsfork
#1#5\XINT_fcmp_minusminus
-#5\XINT_fcmp_firstneg
#1-\XINT_fcmp_secondneg
--\XINT_fcmp_nonneg_a
\krof
#1#5{#2/#3[#4]}{#6/#7[#8]}%
}%
\def\XINT_fcmp_minusminus --#1#2{\XINT_fcmp_B #2#1}%
\def\XINT_fcmp_firstneg #1-#2#3{ -1}%
\def\XINT_fcmp_secondneg -#1#2#3{ 1}%
\def\XINT_fcmp_nonneg_a #1#2%
{%
\xint_UDzerosfork
#1#2\XINT_fcmp_zerozero
0#2\XINT_fcmp_firstzero
#10\XINT_fcmp_secondzero
00\XINT_fcmp_pos
\krof
#1#2%
}%
\def\XINT_fcmp_zerozero #1#2#3#4{ 0}% 1.08b had some [ and ] here!!!
\def\XINT_fcmp_firstzero #1#2#3#4{ -1}% incredibly I never saw that until
\def\XINT_fcmp_secondzero #1#2#3#4{ 1}% preparing 1.09a.
\def\XINT_fcmp_pos #1#2#3#4%
{%
\XINT_fcmp_B #1#3#2#4%
}%
\def\XINT_fcmp_B #1/#2[#3]#4/#5[#6]%
{%
\expandafter\XINT_fcmp_C\expandafter
{\the\numexpr #6-#3\expandafter}\expandafter
{\romannumeral0\xintiimul {#4}{#2}}%
{\romannumeral0\xintiimul {#5}{#1}}%
}%
\def\XINT_fcmp_C #1#2#3%
{%
\expandafter\XINT_fcmp_D\expandafter
{#3}{#1}{#2}%
}%
\def\XINT_fcmp_D #1#2#3%
{%
\expandafter\XINT_cntSgnFork\romannumeral`&&@\expandafter\XINT_cntSgn
\the\numexpr #2+\xintLength{#3}-\xintLength{#1}\relax\Z
{ -1}{\XINT_fcmp_E #2\Z {#3}{#1}}{ 1}%
}%
\def\XINT_fcmp_E #1%
{%
\xint_UDsignfork
#1\XINT_fcmp_Fd
-{\XINT_fcmp_Fn #1}%
\krof
}%
\def\XINT_fcmp_Fd #1\Z #2#3%
{%
\expandafter\XINT_fcmp_Fe\expandafter
{\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#3}}{#2}%
}%
\def\XINT_fcmp_Fe #1#2{\xintiicmp {#2}{#1}}%
\def\XINT_fcmp_Fn #1\Z #2#3%
{%
\expandafter\xintiicmp\expandafter
{\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#2}}{#3}%
}%
% \end{macrocode}
% \subsection{\csh{xintAbs}}
% \begin{macrocode}
\def\xintAbs {\romannumeral0\xintabs }%
\def\xintabs #1{\expandafter\XINT_abs\romannumeral0\xintraw {#1}}%
% \end{macrocode}
% \subsection{\csh{xintOpp}}
% \begin{macrocode}
\def\xintOpp {\romannumeral0\xintopp }%
\def\xintopp #1{\expandafter\XINT_opp\romannumeral0\xintraw {#1}}%
% \end{macrocode}
% \subsection{\csh{xintSgn}}
% \begin{macrocode}
\def\xintSgn {\romannumeral0\xintsgn }%
\def\xintsgn #1{\expandafter\XINT_sgn\romannumeral0\xintraw {#1}\Z }%
% \end{macrocode}
% \subsection{Floating point macros}
% For a long time the float routines from releases |1.07/1.08a| (May-June
% 2013) were not modified.
%
% |1.2| release did not touch either the floating point routines apart from
% adding the new \csh{xintFloatFac}.
%
%
% |1.2f| added \csh{xintFloatPFactorial} and \csh{xintFloatBinomial} and
% improved the speed of |\xintFloatPow| and |\xintFloatPower|. And its
% |\xintFloat| tries to be more efficient in handling inputs which are not
% fractions to start with. (this has been improved again in |1.2g|)
%
% But some parts of the code in |\xintFloat| are still in the pre-|1.2| style
% and could be improved, anyhow in the future quite probably \xintfracnameimp
% will have to adopt an inner format for floats with for example their
% precision P as a visible data first in front and things will have to be
% modified again.
%
% Next major release will have made fondamental decisions regarding the
% handling of inputs having originally more than the target precision, or even
% worse are expressed as fractions.
%
% Currently |\xintFloat| still handles fractional input |A/B| via an initial
% replacement to |A'/B'| (up to powers of ten) with |A'| and |B'| the |A| and
% |B| truncated to P+2 digits. In the future |\xintFloat| will produce the
% correctly rounded value with P digits of precision independently of the
% fraction representative |A/B|, which is not the case with the current
% procedure.
%
% But already |1.2f| has changed an important aspect: the four operations
% first round their arguments to P-floats, not (P+2)-floats as earlier.
%
% \subsection{\csh{xintFloat}}
% \lverb|1.07. May 2013. The original macro did the exact rounding of the input
% fraction to P digits of float precision.
%
% It was completely re-written in 1.08a (June 2013), with "spectacular speed
% gains", so said my comment back then and further: "The earlier version was
% seriously silly when dealing with inputs having a big power of ten. Again
% some modifications in 1.08b for a better treatment of cases with long
% explicit numerators or denominators."
%
% 2015/12. I finally add more comments two years later (for 1.2f).
%
% The important thing I had forgotten to document was that the initial 1.07
% version did the *exact* rounding of fractional inputs A/B whereas the 1.08
% version **first truncated A and B to P+2 digits**: to round A/B 10^n to P
% digits of precision the routine first truncates A and B to P+2 digits and
% after that does the exact rounding of A/B. Naturally this means that it may
% then not necessarily compute the correct rounding of A/B.
%
% Example : \xintFloat {1/17597472569900621233}$newline
% with xintfrac 1.07: 5.682634230727187e-20$newline
% with xintfrac 1.08b or later: 5.682634230727188e-20$newline
% and the exact value is 5.682634230727187499924124...e-20.
%
% 1.07 computed the exact rounding for all inputs but as explained from 1.08
% on, \xintFloat first truncates the denominator to 16+2=18 digits, and here
% this increases 1/x enough to make the final rounding produce a result 1ulp
% higher.
%
% In fact already dropping the last digit is enough to make the quotient cross
% the border:$newline
% 1/17597472569900621233=5.682634230727187499924124...e-20$newline
% 1/1759747256990062123 =56.82634230727187500892894...e-20
%
% 1.2f did some minor improvements to the code, there was in particular a
% never-used branch. And it tries to handle more swiftly the case of inputs
% which are not fractions. (improved again in 1.2g)
%
% This routine uses old macros \XINT_addm_a and \XINT_lenrord_loop. This could
% now be penalizing for P exceeding a few dozens, compared to doing it the 1.2
% way.
%
% I have always hesitated about the policy of printing 10.00...0 in case of
% rounding upwards towards next power of ten. It does make sense because it
% tells the (higher) precision of the rounding and moreover it is not too hard
% to test on output, although it is a bit cumbersome not to be certain to have
% exactly P digits.
%
% Since 1.2f only \xintFloat but not \XINTinFloat may have P+1 digits in the
% mantissa on output. \XINTinFloat is the inner macro used for example by all
% operations in float expression to output their result, hence most of the
% time receive it in A[N] shape also, which is quicly parsed --- apart of
% course that each time length of A is computed again.
%
% 1.2g adds \XINTinFloatS which may output A[N] with A having <P digits. This
% is for situations with large P's (say in the hundreds) and has a dramatic
% speed-up effect on things like 2x or x/3. Addition and subtraction will
% still use \XINTinFloat on inputs; anyway this will have to be changed again
% when inner structure will carry up front at least the length of mantissa as
% a data not to recompute.
%
% 1.2g has also re-written both \xintFloat and \XINTinFloat start code to
% intercept more quickly and more satisfactorily B=1 case.
%
% |
% \begin{macrocode}
\def\xintFloat {\romannumeral0\xintfloat }%
\def\xintfloat #1{\XINT_float_chkopt #1\xint_relax }%
\def\XINT_float_chkopt #1%
{%
\ifx [#1\expandafter\XINT_float_opt
\else\expandafter\XINT_float_noopt
\fi #1%
}%
\def\XINT_float_noopt #1\xint_relax
{%
\expandafter\XINT_float_a\expandafter\XINTdigits\expandafter.%
\romannumeral0\XINT_infrac {#1}\XINT_float_Q
}%
\def\XINT_float_opt [\xint_relax #1]#2%
{%
\expandafter\XINT_float_a\the\numexpr #1\expandafter.%
\romannumeral0\XINT_infrac {#2}\XINT_float_Q
}%
% \end{macrocode}
% \lverb|Note 2015/12/02. Le but de ce code de 1.08 (2013), jusqu'à
% l'exécution de \XINT_float_Q, est simplement de tronquer numérateur et
% dénominateur à au plus P+2 chiffres en ajustant la partie décimale "n".
%
% 2016/03/19. First thing to do is to intercept denominator=1 case.
%
% |
% \begin{macrocode}
\def\XINT_float_a #1.#2#3#4%
{%
\if\romannumeral0\XINT_isone#4XY1\expandafter\XINT_float_sp
\else\expandafter\XINT_float_fork\fi #3.{#1}{#2}{#4}%
}%
% \end{macrocode}
% \lverb|Special quick treatment of B=1 case. The \XINTinFloat variant has
% also optionally the non-addition of zeroes to short inputs. Not for
% \xintFloat. The other difference is that \xintFloat may output 10.0...0eN|
% \begin{macrocode}
\def\XINT_float_sp #1%
{%
\xint_UDzerominusfork
#1-\XINT_float_spzero
0#1\XINT_float_spneg
0-{\XINT_float_sppos #1}%
\krof
}%
\def\XINT_float_spzero .#1#2#3#4{ 0.e0}%
\def\XINT_float_spneg {\expandafter-\romannumeral0\XINT_float_sppos}%
\def\XINT_float_sppos #1.#2#3#4#5%
{%
\expandafter\XINT_float_sp_b\the\numexpr#2-\xintLength{#1}.#1.#2.#3.%
}%
\def\XINT_float_sp_b #1%
{%
\xint_UDzerominusfork
#1-\XINT_float_sp_quick
0#1\XINT_float_sp_c
0-{\XINT_float_sp_addzeros #1}%
\krof
}%
\def\XINT_float_sp_quick .#1.#2.#3.%
{%
\expandafter\XINT_float_sp_done\the\numexpr #3+#2-\xint_c_i.#1;%
}%
\def\XINT_float_sp_addzeros #1.#2.#3.#4.%
{%
\expandafter\XINT_float_sp_done
\the\numexpr #4-#1+#3-\xint_c_i\expandafter.%
\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#2};%
}%
\def\XINT_float_sp_done #1.#2#3;{ #2.#3e#1}%
\def\XINT_float_sp_c #1.#2%
{%
\if #29\xint_dothis {\XINT_float_sp_d\XINT_float_Wb }\fi
\xint_orthat {\XINT_float_sp_d\XINT_float_sp_Wa }#1.#2%
}%
\def\XINT_float_sp_d #1#2.#3.#4.#5.%
{%
\expandafter\XINT_float_sp_e
\the\numexpr #5+#2+#4-\xint_c_i\expandafter.%
\romannumeral0\expandafter\XINT_split_fromleft_loop
\the\numexpr #4+\xint_c_i.{}#3\W\W\W\W\W\W\W\W\Z #1%
}%
% \end{macrocode}
% \lverb|Still using old Reverse routine because presumably we are handling
% numbers up to a few dozens digits. But a faster \xintReverseDigits is
% available. No time now.
% #1=exposant final.#2=P+1chiffres de A.#3=junk.#4=\XINT_float_Wb ou
% \XINT_float_sp_Wa
% |
% \begin{macrocode}
\def\XINT_float_sp_e #1.#2.#3.%
{%
\expandafter\XINT_float_sp_f
\romannumeral0\XINT_rord_main {}#2%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax ;#1.%
}%
\def\XINT_float_sp_f #1%
{%
\ifnum #1<\xint_c_v
\expandafter\XINT_float_sp_ga\else\expandafter\XINT_float_sp_h\fi
}%
\def\XINT_float_sp_ga #1;#2.#3%
{%
\expandafter\XINT_float_sp_Wa
\romannumeral0\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax e#2%
}%
\def\XINT_float_sp_h #1;#2.#3%
{%
\expandafter#3%
\romannumeral0\XINT_addm_A 0{}1000\W\X\Y\Z #1000\W\X\Y\Z e#2%
}%
\def\XINT_float_sp_Wa #1{ #1.}%
% \end{macrocode}
%\lverb?A.{P}{n}{B}\XINT_float_Q avec B qui est >1, donc A=0 exclu.
% ?
% \begin{macrocode}
\def\XINT_float_fork #1%
{%
\xint_UDsignfork
#1\XINT_float_J
-{\XINT_float_K #1}%
\krof
}%
\def\XINT_float_J {\expandafter-\romannumeral0\XINT_float_K }%
\def\XINT_float_K #1.#2%
{%
\expandafter\XINT_float_L
\the\numexpr\xintLength{#1}\expandafter.\the\numexpr #2+\xint_c_ii.{#1}{#2}%
}%
% \end{macrocode}
% \lverb?|A|.P+2.{A}{P}{n}{B}\XINT_float_Q. We check if A already has length
% <= P+2.?
% \begin{macrocode}
\def\XINT_float_L #1.#2.%
{%
\ifnum #1>#2
\expandafter\XINT_float_Ma
\else
\expandafter\XINT_float_Mb
\fi #1.#2.%
}%
% \end{macrocode}
% \lverb?|A|.P+2.{A}{P}{n}{B}\XINT_float_Q. We will keep only the first P+2
% digits of A. We use A' for notation.?
% \begin{macrocode}
\def\XINT_float_Ma #1.#2.#3%
{%
\expandafter\XINT_float_MatoN
\the\numexpr #1-#2\expandafter.%
\romannumeral0\XINT_split_fromleft_loop #2.{}#3\W\W\W\W\W\W\W\W\Z
{#2}%
}%
% \end{macrocode}
% \lverb?|A|-(P+2).{A'=P+2 premiers chiffres de
% A}.{junk}.{P+2}{P}{n}{B}\XINT_float_Q devient
% |B|.n'=n+|A|-(P+2).P+2.{B}{P+2}{A'}{P}. Car ici P+2=|A'|.?
% \begin{macrocode}
\def\XINT_float_MatoN #1.#2.#3.#4#5#6#7%
{%
\expandafter\XINT_float_N
\the\numexpr\xintLength{#7}\expandafter.\the\numexpr #1+#6.#4.%
{#7}{#4}{#2}{#5}%
}%
% \end{macrocode}
% \lverb?Dans cette branche A'=A. En entrée |A|.P+2.{A}{P}{n}{B}, en sortie
% |B|.n.P+2.{B}{|A|}{A}{P}?
% \begin{macrocode}
\def\XINT_float_Mb #1.#2.#3#4#5#6%
{%
\expandafter\XINT_float_N
\romannumeral0\xintlength{#6}.#5.#2.{#6}{#1}{#3}{#4}%
}%
% \end{macrocode}
% \lverb?Ce qu'on a fait avec A on le fait maintenant avec B. Mais on va
% repérer B=1 avant de faire une division.$newline
% En entrée: |B|.n'.P+2.{B}{|A'|}{A'}{P}\XINT_float_Q
%
% 1.2g has already filtered out the case B=1.?
% \begin{macrocode}
\def\XINT_float_N #1.#2.#3.%
{%
\ifnum #1>#3
\expandafter\XINT_float_N_Blong
\else\expandafter\XINT_float_P\fi
#1.#2.#3.%
}%
% \end{macrocode}
% \lverb?Ici B est de longueur > P+2. On va le tronquer. En entrée #1=|B|,
% #2=n', #3=P+2, #4=B. En sortie:
% n''=n'-(|B|-(P+2)).{B'}{junk}{P+2}?
% \begin{macrocode}
\def\XINT_float_N_Blong #1.#2.#3.#4%
{%
\expandafter\XINT_float_NaP
\the\numexpr #2-#1+#3\expandafter.%
\romannumeral0\XINT_split_fromleft_loop #3.{}#4\W\W\W\W\W\W\W\W\Z {#3}%
}%
% \end{macrocode}
% \lverb?n''=n'-(|B|-(P+2)).{B'}.{junk}.{P+2}->0.P+2.n''.P+2.{B'}?
% \begin{macrocode}
\def\XINT_float_NaP #1.#2.#3.#4{\XINT_float_P #4.#1.#4.{#2}}%
% \end{macrocode}
% \lverb?Si B est de longueur <= P+2 on arrive ici avec en entrée
% |B|.n'.P+2.{B}, sinon avec P+2.n''.P+2.{B'}, suivi dans les deux cas par
% {|A'|}{A'}{P} et #8=\XINT_float_Q. On va invoquer \XINT_float_Q, on
% aura donc \XINT_float_Q |B|-|A|+P+1.{A}{B}{P}{n} avec les nouveaux A, B, n.
% Ici on a doit passer au-dessus de A et |A| pour aller chercher #8. à revoir
% car pas satisfaisant.?
% \begin{macrocode}
\def\XINT_float_P #1.#2.#3.#4#5#6#7#8%
{%
\expandafter #8\the\numexpr #1-#5+#3-\xint_c_i.{#6}{#4}{#7}{#2}%
}%
% \end{macrocode}
% \lverb?On arrive ici avec |B|-|A|+P+1.{A}{B}{P}{n}, les A et B étant ceux
% d'origine tronqués à au plus P+2 chiffres, le n a été ajusté si besoin.
%
% On calcule maintenant le quotient euclidien de A 10^{|B|-|A|+P+1} (qui a P+1
% chiffres de plus que B) par B. Ce quotient Q aura P+1 ou P+2 chiffres.
%
% ?
% \begin{macrocode}
\def\XINT_float_Q #1.#2#3%
{%
\expandafter\XINT_float_Sa
\romannumeral0\xintiiquo{\XINT_dsx_addzerosnofuss {#1}{#2}}{#3}\Z {#1}%
}%
% \end{macrocode}
% \lverb?On a Q\Z {|B|-|A|+P+1}{P}{n}. Comme Q = trunc (A/B 1O^x),
% x=|B|-|A|+P+1, Q peut avoir P+1 ou P+2 chiffres. Ce qui compte c'est qu'il a
% au moins P+1 chiffres. On va examiner si le (P+1)e chiffre est 5. Mais on
% fait une sous-branche pour les cas exceptionnels qui donnent un arrondi est
% vers le haut vers la prochaine puissance de 10. Ceci ne pourra se produire
% que si le premier chiffre significatif de Q est un 9.?
% \begin{macrocode}
\def\XINT_float_Sa #1%
{%
\if #19\xint_dothis {\XINT_float_Sb\XINT_float_Wb }\fi
\xint_orthat {\XINT_float_Sb\XINT_float_Wa }#1%
}%
% \end{macrocode}
% \lverb?En entrée \XINT_float_W(a ou b) Q\Z {|B|-|A|+P+1}{P}{n}. On va
% renverser Q en comptant sa longueur L = P+1 ou P+2 au passage. Pour le
% moment avec la vieille routine \XINT_lenrord_loop mais il faudra voir si je
% modifie cela.?
% \begin{macrocode}
\def\XINT_float_Sb #1#2\Z #3#4%
{%
\expandafter\XINT_float_T
\the\numexpr #4+\xint_c_i\expandafter.%
\romannumeral`&&@\XINT_lenrord_loop 0.{}#2\Z\W\W\W\W\W\W\W\Z #1{#3}{#4}%
}%
% \end{macrocode}
% \lverb?Si L>P+1, c'est que L=P+2, on laisse tomber le chiffre le moins
% significatif de Q. En sortie on a \token Q à l'envers\Z \token
% {|B|-|A|+P+1}{P}{n}?
% \begin{macrocode}
\def\XINT_float_T #1.#2.#3%
{%
\ifnum #2>#1 \xint_dothis{\XINT_float_U\XINT_float_Xb}\fi
\xint_orthat{\XINT_float_U\XINT_float_Xa #3}%
}%
\def\XINT_float_U #1#2%
{%
\ifnum #2<\xint_c_v
\expandafter\XINT_float_Va
\else
\expandafter\XINT_float_Vb
\fi #1%
}%
% \end{macrocode}
% \lverb?Chiffre moins significatif de Q est <5. Suffit de tronquer. On va
% ensuite embrayer soit sur \XINT_float_Xa si on avait P+1 chiffres, soit sur
% \XINT_float_Xb si on en avait P+2. Dans ce cas de troncation, on n'a pas à
% se préoccuper d'un arrondi éventuel vers le haut vers une puissance de dix,
% donc le #3 est ici remplacé par \XINT_float_Wa.?
% \begin{macrocode}
\def\XINT_float_Va #1#2\Z #3%
{%
\expandafter#1%
\romannumeral0\expandafter\XINT_float_Wa
\romannumeral0\XINT_rord_main {}#2%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax \Z
}%
% \end{macrocode}
% \lverb?Chiffre moins significatif de Q est au moins 5. Faut aussi ajouter 1.
% On utilise la vieille routine d'addition spéciale \XINT_addm_A qui renvoie
% son résultat à l'endroit. De plus on doit ensuite vérifier si l'arrondi
% s'est fait vers la puissance de 10 supérieure. Cela ne peut se produire que
% si le premier chiffre était 9, donc dans ce cas on a #3=\XINT_float_Wb,
% sinon on a #3=\XINT_float_Wa.?
% \begin{macrocode}
\def\XINT_float_Vb #1#2\Z #3%
{%
\expandafter #1%
\romannumeral0\expandafter #3%
\romannumeral0\XINT_addm_A 0{}1000\W\X\Y\Z #2000\W\X\Y\Z \Z
}%
% \end{macrocode}
% \lverb|Wa insère la virgule. Wb regarde si on a arrondi vers le haut vers
% une puissance de 10. Il n'est exécuté que si le premier chiffre était un 9,
% donc il regarde si maintenant le premier chiffre est devenu un 1. Est-il sûr
% que Wb trouve deux chiffres si P=1? Pour n'en avoir qu'un, il faudrait que
% le quotient Q aie eu seulement deux chiffres. Mais si on arrive en Wb le
% premier chiffre était 9 et si Q avait eu seulement deux chiffres il aurait
% été 95 au plus, et ici on serait avec 10 qui ne pose pas de problème.|
% \begin{macrocode}
\def\XINT_float_Wa #1{ #1.}%
\def\XINT_float_Wb #1#2{\if #11\xint_dothis{ 10.}\fi\xint_orthat{ #1.#2}}%
% \end{macrocode}
% \lverb?Il faut faire l'ajustement final de n. On doit regrabber notre
% mantisse, maintenant avec sa virgule. On a {|B|-|A|+P+1}{P}{n} après le \Z.
% On exécute _Xb si le quotient produit avait P+2 chifffres. On n'a pas à
% faire d'ajustement en cas d'arrondi vers un 10.00...0.?
% \begin{macrocode}
\def\XINT_float_Xa #1\Z #2#3#4%
{%
\expandafter\XINT_float_Y\the\numexpr #3+#4-#2.{#1}%
}%
\def\XINT_float_Xb #1\Z #2#3#4%
{%
\expandafter\XINT_float_Y\the\numexpr #3+#4+\xint_c_i-#2.{#1}%
}%
\def\XINT_float_Y #1.#2{ #2e#1}%
% \end{macrocode}
% \subsection{\csh{XINTinFloat}}
% \lverb|1.07.
%
% This routine is like \xintFloat but produces an output of the shape A[N]
% which is then parsed faster on input to other float macros.
%
% For 1.2f I modify it : contrarily to current \xintFloat, in the exceptional
% case of rounding up to a power of ten, it does not produce anymore a
% mantissa 10^P with P+1 digits, but 10^{P-1}. Indeed not knowing for sure the
% number of digits of the mantissa caused various complications in other
% routines, and I really got tired of this. This means however that it is a
% tiny bit slower than earlier.
%
% 2016/03/11.
% 1.2f \XINTinFloat clones somes of the \XINT_infrac start code to handle more
% swiftly inputs of the shape A[N] (still allowing N to be an <expression> for
% \numexpr). This is done without yet introducting a private format for
% floats, as I want to conclude now and doing this would need some extra time.
%
% As this is surgery on pre-existing code where a more complete rewrite would
% be needed it is a bit ugly though. 1.2g has redone it and does not anymore
% tap into \XINT_infrac.
%
% Each time \XINTinFloat is called it at least computes a length.
% Naturally if we had some format for floats that would be dispensed of...
%
% Something like <letterP><length of mantissa>.mantissa.exponent, etc...
%
% Not yet. But obviously we can not go one re-parsing each input that way,
% although the situation is better with 1.2f.
%
%
% 2016/03/18.
% 1.2g adds a variant \XINTinFloatS which allows its output to be shorter than
% the current precision. Indeed \XINTinFloat is used everywhere but for example
% it is silly to convert 2 into 2<499zeroes>[-499] if we need to do some
% multiplication or division...
%
% 2016/03/19.
% 1.2g uses non-patched \XINT_infrac but then immediately filters out
% all denominator=1 cases (only the A[N] cases were identified by 1.2f).
%|
% \begin{macrocode}
\def\XINTinFloat {\romannumeral0\XINTinfloat }%
\def\XINTinfloat
{\expandafter\XINT_infloat_clean\romannumeral0\XINT_infloat}%
\def\XINT_infloat_clean #1%
{\if #1!\xint_dothis\XINT_infloat_clean_a\fi\xint_orthat{ }#1}%
\def\XINT_infloat_clean_a !#1.#2[#3]%
{%
\expandafter\XINT_infloat_sp_done
\the\numexpr #3-#1\expandafter.%
\romannumeral0\XINT_dsx_addzerosnofuss {#1}{#2};%
}%
\def\XINT_infloat_sp_done #1.#2;{ #2[#1]}%
\def\XINTinFloatS {\romannumeral0\XINTinfloatS}%
\def\XINTinfloatS
{\expandafter\XINT_infloatS_clean\romannumeral0\XINT_infloat}%
\def\XINT_infloatS_clean #1%
{\if #1!\xint_dothis\XINT_infloatS_clean_a\fi\xint_orthat{ }#1}%
\def\XINT_infloatS_clean_a !#1.{ }%
\def\XINT_infloat [#1]#2%
{%
\expandafter\XINT_infloat_a\the\numexpr #1\expandafter.%
\romannumeral0\XINT_infrac {#2}\XINT_infloat_Q
}%
\def\XINT_infloat_a #1.#2#3#4%
{%
\if\romannumeral0\XINT_isone#4XY1\expandafter\XINT_infloat_sp
\else\expandafter\XINT_float_fork\fi #3.{#1}{#2}{#4}%
}%
% \end{macrocode}
% \lverb|Special quick treatment of B=1 case (1.2f then redone 1.2g).|
% \begin{macrocode}
\def\XINT_infloat_sp #1%
{%
\xint_UDzerominusfork
#1-\XINT_infloat_spzero
0#1\XINT_infloat_spneg
0-{\XINT_infloat_sppos #1}%
\krof
}%
\def\XINT_infloat_spzero .#1#2#3#4{ 0[0]}%
\def\XINT_infloat_spneg
{\expandafter\XINT_infloat_spnegend\romannumeral0\XINT_infloat_sppos}%
\def\XINT_infloat_spnegend #1%
{\if#1!\expandafter\XINT_infloat_spneg_needzeros\fi -#1}%
\def\XINT_infloat_spneg_needzeros -!#1.{!#1.-}%
\def\XINT_infloat_sppos #1.#2#3#4#5%
{%
\expandafter\XINT_infloat_sp_b\the\numexpr#2-\xintLength{#1}.#1.#2.#3.%
}%
\def\XINT_infloat_sp_b #1%
{%
\xint_UDzerominusfork
#1-\XINT_infloat_sp_quick
0#1\XINT_infloat_sp_c
0-{\XINT_infloat_sp_needzeros #1}%
\krof
}%
\def\XINT_infloat_sp_quick .#1.#2.#3.{ #1[#3]}%
\def\XINT_infloat_sp_needzeros #1.#2.#3.#4.{!#1.#2[#4]}%
% \end{macrocode}
% \lverb|I should re-use truncating/rounding routines but I wrote them too
% much time ago. Faster to do it again.|
% \begin{macrocode}
\def\XINT_infloat_sp_c #1.#2%
{%
\if #29\xint_dothis {\XINT_infloat_sp_d\XINT_infloat_Wb }\fi
\xint_orthat {\XINT_infloat_sp_d\xint_c_ }#1.#2%
}%
\def\XINT_infloat_sp_d #1#2.#3.#4.%#5.%
{%
\expandafter\XINT_infloat_sp_e
\romannumeral0\expandafter\XINT_split_fromleft_loop
\the\numexpr #4+\xint_c_i.{}#3\W\W\W\W\W\W\W\W\Z #1#2.%
}%
% \end{macrocode}
% \lverb|Still using old Reverse routine because presumably we are handling
% numbers up to a few dozens digits. But a faster \xintReverseDigits is
% available. No time now.
%
% #1=first P+1 digits of A, #2=junk|
% \begin{macrocode}
\def\XINT_infloat_sp_e #1.#2.%
{%
\expandafter\XINT_infloat_sp_f
\romannumeral0\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax ;%
}%
\def\XINT_infloat_sp_f #1%
{%
\ifnum #1<\xint_c_v
\expandafter\XINT_infloat_sp_ga\else\expandafter\XINT_infloat_sp_h\fi
}%
\def\XINT_infloat_sp_ga #1;#2#3.#4.%
{%
\expandafter\XINT_infloat_sp_done\the\numexpr #3+#4\expandafter.%
\romannumeral0\XINT_rord_main {}#1%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax ;%
}%
\def\XINT_infloat_sp_h #1;#2%
{%
\expandafter\XINT_infloat_sp_i
\romannumeral0\expandafter#2%
\romannumeral0\XINT_addm_A 0{}1000\W\X\Y\Z #1000\W\X\Y\Z;%
}%
\def\XINT_infloat_sp_i #1#2;#3.#4.%
{%
\expandafter\XINT_infloat_sp_done\the\numexpr #1+#3+#4.#2;%
}%
% \end{macrocode}
% \lverb|General branch handling A/B possibly with [N] or scientific notation
% inputs.
%
% Since 1.2g this is always with B>1. And A is not zero.|
% \begin{macrocode}
\def\XINT_infloat_Q #1.#2#3%
{%
\expandafter\XINT_infloat_Sa
\romannumeral0\xintiiquo{\XINT_dsx_addzerosnofuss {#1}{#2}}{#3}\Z {#1}%
}%
\def\XINT_infloat_Sa #1%
{%
\if #19\xint_dothis {\XINT_infloat_Sb\XINT_infloat_Wb }\fi
\xint_orthat {\XINT_infloat_Sb\xint_c_ }#1%
}%
\def\XINT_infloat_Sb #1#2\Z #3#4%
{%
\expandafter\XINT_infloat_T
\the\numexpr #4+\xint_c_i\expandafter.%
\romannumeral`&&@\XINT_lenrord_loop 0.{}#2\Z\W\W\W\W\W\W\W\Z #1{#3}%
}%
\def\XINT_infloat_T #1.#2.#3%
{%
\ifnum #2>#1 \xint_dothis{\XINT_infloat_U\XINT_infloat_Xb}\fi
\xint_orthat{\XINT_infloat_U\XINT_infloat_Xa #3}%
}%
\def\XINT_infloat_U #1#2%
{%
\ifnum #2<\xint_c_v
\expandafter\XINT_infloat_Va
\else
\expandafter\XINT_infloat_Vb
\fi #1%
}%
\def\XINT_infloat_Va #1#2\Z #3%
{%
\expandafter#1%
\romannumeral0\expandafter\xint_c_
\romannumeral0\XINT_rord_main {}#2%
\xint_relax
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_bye\xint_bye\xint_bye\xint_bye
\xint_relax \Z
}%
\def\XINT_infloat_Vb #1#2\Z #3%
{%
\expandafter #1%
\romannumeral0\expandafter #3%
\romannumeral0\XINT_addm_A 0{}1000\W\X\Y\Z #2000\W\X\Y\Z \Z
}%
\def\XINT_infloat_Wb #1#2%
{\if #11\xint_dothis{\xint_c_i1}\fi\xint_orthat{\xint_c_#1#2}}%
\def\XINT_infloat_Xa #1#2\Z #3#4%
{%
\expandafter\XINT_infloat_Y\the\numexpr #1+\xint_c_i+#4-#3.{#2}%
}%
\def\XINT_infloat_Xb #1#2\Z #3#4%
{%
\expandafter\XINT_infloat_Y\the\numexpr #1+\xint_c_ii+#4-#3.{#2}%
}%
\def\XINT_infloat_Y #1.#2{ #2[#1]}%
% \end{macrocode}
% \subsection{\csh{xintPFloat}}
% \lverb|1.1. This is a prettifying printing macro for floats.
%
% 2016/03/07.
%
% 1.2f modifies the macro: among the now obsoleted rules there was one which
% told it to employ decimal notation as soon as possible without extra zeroes,
% for example a...z<decimal mark>A...Z if the total length is at most the
% precision, but obviously for large precisions the human eye has difficulties
% with that, this was not a good choice.
%
%
% The new rule is simply that x.yz...eN will drop scientific notation in
% favor of pure decimal notation if -5<=N<=5. This is the default behaviour of
% Maple. The N here is as produced on output by \xintFloat. There is the
% exceptional cases where x=10, and yz..=0000.... from rounding up to the next
% power of ten.
%
% |
% \begin{macrocode}
\def\xintPFloat {\romannumeral0\xintpfloat }%
\def\xintpfloat #1{\XINT_pfloat_chkopt #1\xint_relax }%
\def\XINT_pfloat_chkopt #1%
{%
\ifx [#1\expandafter\XINT_pfloat_opt
\else\expandafter\XINT_pfloat_noopt
\fi #1%
}%
\def\XINT_pfloat_noopt #1\xint_relax
{%
\expandafter\XINT_pfloat_a
\romannumeral0\xintfloat [\XINTdigits]{#1};\XINTdigits.%
}%
\def\XINT_pfloat_opt [\xint_relax #1]%#2%
{%
\expandafter\XINT_pfloat_opt_a \the\numexpr #1.%
}%
\def\XINT_pfloat_opt_a #1.#2%
{%
\expandafter\XINT_pfloat_a\romannumeral0\xintfloat [#1]{#2};#1.%
}%
\def\XINT_pfloat_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_pfloat_zero
0#1\XINT_pfloat_neg
0-{\XINT_pfloat_pos #1}%
\krof
}%
\def\XINT_pfloat_zero #1;#2.{ 0.}%
\def\XINT_pfloat_neg {\expandafter-\romannumeral0\XINT_pfloat_pos }%
\def\XINT_pfloat_pos #1e#2;#3.%
{%
\ifnum #2>\xint_c_v \xint_dothis\XINT_pfloat_no\fi
\ifnum #2<-\xint_c_v \xint_dothis\XINT_pfloat_no\fi
\ifnum #2<\xint_c_ \xint_dothis\XINT_pfloat_N\fi
\ifnum #2>\numexpr #3-\xint_c_i\relax \xint_dothis\XINT_pfloat_Ps\fi
\xint_orthat\XINT_pfloat_P #1e#2;%
}%
\def\XINT_pfloat_no #1;{ #1}%
\def\XINT_pfloat_N #1#2.#3e#4;%
{%
\csname XINT_pfloat_N\romannumeral-#4\endcsname #2#10.#3;%
}%
\def\XINT_pfloat_Ni #1#2#3.#4;{ #2.#1#4}%
\def\XINT_pfloat_Nii #1#2#3.#4;{ 0.#2#1#4}%
\def\XINT_pfloat_Niii#1#2#3.#4;{ 0.0#2#1#4}%
\def\XINT_pfloat_Niv #1#2#3.#4;{ 0.00#2#1#4}%
\def\XINT_pfloat_Nv #1#2#3.#4;{ 0.000#2#1#4}%
\def\XINT_pfloat_P #1#2.#3e#4;%
{%
\csname XINT_pfloat_P_\romannumeral#4\endcsname #3.#1#2;%
}%
\def\XINT_pfloat_P_ #1.#2;{ #2.#1}%
\def\XINT_pfloat_P_i #1#2.#3;{ #3#1.#2}%
\def\XINT_pfloat_P_ii #1#2#3.#4;{ #4#1#2.#3}%
\def\XINT_pfloat_P_iii#1#2#3#4.#5;{ #5#1#2#3.#4}%
\def\XINT_pfloat_P_iv #1#2#3#4#5.#6;{ #6#1#2#3#4.#5}%
\def\XINT_pfloat_P_v #1#2#3#4#5#6.#7;{ #7#1#2#3#4#5.#6}%
\def\XINT_pfloat_Ps #1#2.#3e#4;%
{%
\csname XINT_pfloat_Ps\romannumeral#4\endcsname #300000.#1#2;%
}%
\def\XINT_pfloat_Psi #1#2.#3;{ #3#1.}%
\def\XINT_pfloat_Psii #1#2#3.#4;{ #4#1#2.}%
\def\XINT_pfloat_Psiii#1#2#3#4.#5;{ #5#1#2#3.}%
\def\XINT_pfloat_Psiv #1#2#3#4#5.#6;{ #6#1#2#3#4.}%
\def\XINT_pfloat_Psv #1#2#3#4#5#6.#7;{ #7#1#2#3#4#5.}%
% \end{macrocode}
% \subsection{\csh{XINTinFloatFracdigits}}
% \lverb|1.09i, for frac function in \xintfloatexpr. This version computes
% exactly from the input the fractional part and then only converts it
% into a float with the asked-for number of digits. I will have to think
% it again some day, certainly.
%
% 1.1 removes optional argument for which there was anyhow no interface, for
% technical reasons having to do with \xintNewExpr.
%
% 1.1a renames the macro as \XINTinFloatFracdigits (from \XINTinFloatFrac) to
% be synchronous with the \XINTinFloatSqrt and \XINTinFloat habits related to
% \xintNewExpr problems.
%
% Note to myself: I still have to rethink the whole thing about what is the best
% to do, the initial way of going through \xinttfrac was just a first
% implementation.|
% \begin{macrocode}
\def\XINTinFloatFracdigits {\romannumeral0\XINTinfloatfracdigits }%
\def\XINTinfloatfracdigits #1%
{%
\expandafter\XINT_infloatfracdg_a\expandafter {\romannumeral0\xinttfrac{#1}}%
}%
\def\XINT_infloatfracdg_a {\XINTinfloat [\XINTdigits]}%
% \end{macrocode}
% \subsection{\csh{xintFloatAdd}, \csh{XINTinFloatAdd}}
% \lverb|First included in release 1.07.
%
% 1.09ka improved a bit the efficiency. However the add, sub, mul, div
% routines were provisory and supposed to be revised soon.
%
% Which didn't happen until 1.2f. Now, the inputs are first rounded to P
% digits, not P+2 as earlier.
%
%
%|
% \begin{macrocode}
\def\xintFloatAdd {\romannumeral0\xintfloatadd }%
\def\xintfloatadd #1{\XINT_fladd_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatAdd {\romannumeral0\XINTinfloatadd }%
\def\XINTinfloatadd #1{\XINT_fladd_chkopt \XINTinfloatS #1\xint_relax }%
\def\XINT_fladd_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_fladd_opt
\else\expandafter\XINT_fladd_noopt
\fi #1#2%
}%
\def\XINT_fladd_noopt #1#2\xint_relax #3%
{%
#1[\XINTdigits]%
{\expandafter\XINT_FL_add_a
\romannumeral0\XINTinfloat[\XINTdigits]{#2}\XINTdigits.{#3}}%
}%
\def\XINT_fladd_opt #1[\xint_relax #2]%#3#4%
{%
\expandafter\XINT_fladd_opt_a\the\numexpr #2.#1%
}%
\def\XINT_fladd_opt_a #1.#2#3#4%
{%
#2[#1]{\expandafter\XINT_FL_add_a\romannumeral0\XINTinfloat[#1]{#3}#1.{#4}}%
}%
\def\XINT_FL_add_a #1%
{%
\xint_gob_til_zero #1\XINT_FL_add_zero 0\XINT_FL_add_b #1%
}%
\def\XINT_FL_add_zero #1.#2{#2}%
\def\XINT_FL_add_b #1]#2.#3%
{%
\expandafter\XINT_FL_add_c\romannumeral0\XINTinfloat[#2]{#3}#2.#1]%
}%
\def\XINT_FL_add_c #1%
{%
\xint_gob_til_zero #1\XINT_FL_add_zero 0\XINT_FL_add_d #1%
}%
\def\XINT_FL_add_d #1[#2]#3.#4[#5]%
{%
\ifnum\numexpr #2-#3-#5>\xint_c_\xint_dothis\xint_firstoftwo\fi
\ifnum\numexpr #5-#3-#2>\xint_c_\xint_dothis\xint_secondoftwo\fi
\xint_orthat\xintAdd {#1[#2]}{#4[#5]}%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatSub}, \csh{XINTinFloatSub}}
% \lverb|First done 1.07.
%
% 1.2f does not use two extra rounding digits on inputs.|
% \begin{macrocode}
\def\xintFloatSub {\romannumeral0\xintfloatsub }%
\def\xintfloatsub #1{\XINT_flsub_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatSub {\romannumeral0\XINTinfloatsub }%
\def\XINTinfloatsub #1{\XINT_flsub_chkopt \XINTinfloatS #1\xint_relax }%
\def\XINT_flsub_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flsub_opt
\else\expandafter\XINT_flsub_noopt
\fi #1#2%
}%
\def\XINT_flsub_noopt #1#2\xint_relax #3%
{%
#1[\XINTdigits]%
{\expandafter\XINT_FL_add_a
\romannumeral0\XINTinfloat[\XINTdigits]{#2}\XINTdigits.{\xintOpp{#3}}}%
}%
\def\XINT_flsub_opt #1[\xint_relax #2]%#3#4%
{%
\expandafter\XINT_flsub_opt_a\the\numexpr #2.#1%
}%
\def\XINT_flsub_opt_a #1.#2#3#4%
{%
#2[#1]{\expandafter\XINT_FL_add_a\romannumeral0\XINTinfloat[#1]{#3}#1.{\xintOpp{#4}}}%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatMul}, \csh{XINTinFloatMul}}
% \begin{framed}
% It is a long-standing issue here that I must at some point revise the code
% and avoid compute with 2P digits the exact intermediate result.
% \end{framed}
% \lverb|1.07.
%
% 1.2f does not use two extra rounding digits on inputs.
%
% 1.2g handles the inputs via \XINTinFloatS which will be more efficient when
% the precision is large and the input is for example a small constant like 2.|
% \begin{macrocode}
\def\xintFloatMul {\romannumeral0\xintfloatmul }%
\def\xintfloatmul #1{\XINT_flmul_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatMul {\romannumeral0\XINTinfloatmul }%
\def\XINTinfloatmul #1{\XINT_flmul_chkopt \XINTinfloatS #1\xint_relax }%
\def\XINT_flmul_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flmul_opt
\else\expandafter\XINT_flmul_noopt
\fi #1#2%
}%
\def\XINT_flmul_noopt #1#2\xint_relax #3%
{%
#1[\XINTdigits]%
{\expandafter\XINT_FL_mul_a
\romannumeral0\XINTinfloatS[\XINTdigits]{#2}\XINTdigits.{#3}}%
}%
\def\XINT_flmul_opt #1[\xint_relax #2]%#3#4%
{%
\expandafter\XINT_flmul_opt_a\the\numexpr #2.#1%
}%
\def\XINT_flmul_opt_a #1.#2#3#4%
{%
#2[#1]{\expandafter\XINT_FL_mul_a\romannumeral0\XINTinfloatS[#1]{#3}#1.{#4}}%
}%
\def\XINT_FL_mul_a #1[#2]#3.#4%
{%
\expandafter\XINT_FL_mul_b\romannumeral0\XINTinfloatS[#3]{#4}#1[#2]%
}%
\def\XINT_FL_mul_b #1[#2]#3[#4]{\xintE{\xintiiMul {#3}{#1}}{#4+#2}}%
% \end{macrocode}
% \subsection{\csh{xintFloatDiv}, \csh{XINTinFloatDiv}}
% \lverb|1.07.
%
% 1.2f does not use two extra rounding digits on inputs.
%
% 1.2g handles the inputs via \XINTinFloatS which will be more efficient when
% the precision is large and the input is for example a small constant like 2.|
% \begin{macrocode}
\def\xintFloatDiv {\romannumeral0\xintfloatdiv }%
\def\xintfloatdiv #1{\XINT_fldiv_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatDiv {\romannumeral0\XINTinfloatdiv }%
\def\XINTinfloatdiv #1{\XINT_fldiv_chkopt \XINTinfloatS #1\xint_relax }%
\def\XINT_fldiv_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_fldiv_opt
\else\expandafter\XINT_fldiv_noopt
\fi #1#2%
}%
\def\XINT_fldiv_noopt #1#2\xint_relax #3%
{%
#1[\XINTdigits]%
{\expandafter\XINT_FL_div_a
\romannumeral0\XINTinfloatS[\XINTdigits]{#2}\XINTdigits.{#3}}%
}%
\def\XINT_fldiv_opt #1[\xint_relax #2]%#3#4%
{%
\expandafter\XINT_fldiv_opt_a\the\numexpr #2.#1%
}%
\def\XINT_fldiv_opt_a #1.#2#3#4%
{%
#2[#1]{\expandafter\XINT_FL_div_a\romannumeral0\XINTinfloatS[#1]{#3}#1.{#4}}%
}%
\def\XINT_FL_div_a #1[#2]#3.#4%
{%
\expandafter\XINT_FL_div_b\romannumeral0\XINTinfloatS[#3]{#4}#1[#2]%
}%
\def\XINT_FL_div_b #1[#2]#3[#4]{\xintE{#3/#1}{#4-#2}}%
% \end{macrocode}
% \subsection{\csh{xintFloatPow}, \csh{XINTinFloatPow}}
% \lverb|1.07: initial version. 1.09j has re-organized the core loop.
%
% 2015/12/07. I have hesitated to maintain the mapping of ^ in expressions to
% \xintFloatPow rather than \xintFloatPower. But for 1.234567890123456 to the
% power 2145678912 with P=16, using Pow rather than Power seems to bring only
% about 5$char37 $space gain.
%
% This routine requires the exponent x to be compatible with \numexpr parsing.
%
% 1.2f has rewritten the code for better efficiency. Also, now the argument A
% for A^x is first rounded to P digits before switching to the increased
% working precision (which depends upon x).
%
% |
% \begin{macrocode}
\def\xintFloatPow {\romannumeral0\xintfloatpow}%
\def\xintfloatpow #1{\XINT_flpow_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatPow {\romannumeral0\XINTinfloatpow }%
\def\XINTinfloatpow #1{\XINT_flpow_chkopt \XINTinfloatS #1\xint_relax }%
\def\XINT_flpow_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flpow_opt
\else\expandafter\XINT_flpow_noopt
\fi
#1#2%
}%
\def\XINT_flpow_noopt #1#2\xint_relax #3%
{%
\expandafter\XINT_flpow_checkB_a
\the\numexpr #3.\XINTdigits.{#2}{#1[\XINTdigits]}%
}%
\def\XINT_flpow_opt #1[\xint_relax #2]%
{%
\expandafter\XINT_flpow_opt_a\the\numexpr #2.#1%
}%
\def\XINT_flpow_opt_a #1.#2#3#4%
{%
\expandafter\XINT_flpow_checkB_a\the\numexpr #4.#1.{#3}{#2[#1]}%
}%
\def\XINT_flpow_checkB_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_flpow_BisZero
0#1{\XINT_flpow_checkB_b -}%
0-{\XINT_flpow_checkB_b {}#1}%
\krof
}%
\def\XINT_flpow_BisZero .#1.#2#3{#3{1[0]}}%
\def\XINT_flpow_checkB_b #1#2.#3.%
{%
\expandafter\XINT_flpow_checkB_c
\the\numexpr\xintLength{#2}+\xint_c_iii.#3.#2.{#1}%
}%
\def\XINT_flpow_checkB_c #1.#2.%
{%
\expandafter\XINT_flpow_checkB_d\the\numexpr#1+#2.#1.#2.%
}%
% \end{macrocode}
%\lverb|1.2f rounds input to P digits, first.|
% \begin{macrocode}
\def\XINT_flpow_checkB_d #1.#2.#3.#4.#5#6%
{%
\expandafter \XINT_flpow_aa
\romannumeral0\XINTinfloat [#3]{#6}{#2}{#1}{#4}{#5}%
}%
\def\XINT_flpow_aa #1[#2]#3%
{%
\expandafter\XINT_flpow_ab\the\numexpr #2-#3\expandafter.%
\romannumeral0\XINT_dsx_addzerosnofuss {#3}{}.#1.%
}%
\def\XINT_flpow_ab #1.#2.#3.{\XINT_flpow_a #3#2[#1]}%
\def\XINT_flpow_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_flpow_zero
0#1{\XINT_flpow_b \iftrue}%
0-{\XINT_flpow_b \iffalse#1}%
\krof
}%
\def\XINT_flpow_zero #1[#2]#3#4#5#6%
{%
\if 1#51\xint_afterfi {#6{0[0]}}\else
\xint_afterfi {\xintError:DivisionByZero #6{1[2147483648]}}\fi
}%
\def\XINT_flpow_b #1#2[#3]#4#5%
{%
\XINT_flpow_loopI #5.#3.#2.#4.{#1\ifodd #5 \xint_c_i\fi\fi}%
}%
\def\XINT_flpow_truncate #1.#2.#3.%
{%
\expandafter\XINT_flpow_truncate_a
\romannumeral0\XINT_split_fromleft_loop #3.{}#2\W\W\W\W\W\W\W\W\Z
#1.#3.%
}%
\def\XINT_flpow_truncate_a #1.#2.#3.{#3+\xintLength{#2}.#1.}%
\def\XINT_flpow_loopI #1.%
{%
\ifnum #1=\xint_c_i\expandafter\XINT_flpow_ItoIII\fi
\ifodd #1
\expandafter\XINT_flpow_loopI_odd
\else
\expandafter\XINT_flpow_loopI_even
\fi
#1.%
}%
\def\XINT_flpow_ItoIII\ifodd #1\fi #2.#3.#4.#5.#6%
{%
\expandafter\XINT_flpow_III\the\numexpr #6+\xint_c_.#3.#4.#5.%
}%
\def\XINT_flpow_loopI_even #1.#2.#3.%#4.%
{%
\expandafter\XINT_flpow_loopI
\the\numexpr #1/\xint_c_ii\expandafter.%
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.%
}%
\def\XINT_flpow_loopI_odd #1.#2.#3.#4.%
{%
\expandafter\XINT_flpow_loopII
\the\numexpr #1/\xint_c_ii-\xint_c_i\expandafter.%
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.#2.#3.%
}%
\def\XINT_flpow_loopII #1.%
{%
\ifnum #1 = \xint_c_i\expandafter\XINT_flpow_IItoIII\fi
\ifodd #1
\expandafter\XINT_flpow_loopII_odd
\else
\expandafter\XINT_flpow_loopII_even
\fi
#1.%
}%
\def\XINT_flpow_loopII_even #1.#2.#3.%#4.%
{%
\expandafter\XINT_flpow_loopII
\the\numexpr #1/\xint_c_ii\expandafter.%
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.%
}%
\def\XINT_flpow_loopII_odd #1.#2.#3.#4.#5.#6.%
{%
\expandafter\XINT_flpow_loopII_odda
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr#2+#5\expandafter.\romannumeral0\xintiimul{#3}{#6}.#4.%
#1.#2.#3.%
}%
\def\XINT_flpow_loopII_odda #1.#2.#3.#4.#5.#6.%
{%
\expandafter\XINT_flpow_loopII
\the\numexpr #4/\xint_c_ii-\xint_c_i\expandafter.%
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#5\expandafter.\romannumeral0\xintiisqr{#6}.#3.%
#1.#2.%
}%
\def\XINT_flpow_IItoIII\ifodd #1\fi #2.#3.#4.#5.#6.#7.#8%
{%
\expandafter\XINT_flpow_III\the\numexpr #8+\xint_c_\expandafter.%
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr#3+#6\expandafter.\romannumeral0\xintiimul{#4}{#7}.#5.%
}%
% \end{macrocode}
% \lverb|This ending is common with \xintFloatPower. In the case of negative
% exponent we will inverse the Q-digits mantissa, keeping Q significant
% digits (exceptionally 10^Q) before the final rounding to P digits. Here Q
% is working precision. Releases prior to 1.2f trusted the final inverse to
% \xintFloat on output but this worked only with P+2 digits on denominator.
% Enough for 0.1 ulp extra error, but as our goal is to get <0.6ulp, and
% there is already 0.5ulp from rounding error, this was not enough. When
% \xintFloat will achieve correct rounding for arbitrary fractions, the step
% here will not be needed.|
% \begin{macrocode}
\def\XINT_flpow_III #1.#2.#3.#4.#5%
{%
\expandafter\XINT_flpow_IIIend
\xint_UDsignfork
#5{{\xintNum{1/#3[\xint_c_ii*#4-\xint_c_i]}[\xint_c_i-\xint_c_ii*#4-#2]}}%
-{{#3[#2]}}%
\krof #1%
}%
\def\XINT_flpow_IIIend #1#2#3%
{#3{\if#21\xint_afterfi{\expandafter-\romannumeral`&&@}\fi#1}}%
% \end{macrocode}
% \subsection{\csh{xintFloatPower}, \csh{XINTinFloatPower}}
% \lverb|1.07. The core loop has been re-organized in 1.09j for some slight
% efficiency gain. The exponent B is given to \xintNum. The ^ in expressions
% is mapped to this routine.
%
% Same modifications as in \xintFloatPow for 1.2f.
%
% 1.2f adds a special macro for allowing half-integral exponents for use with
% ^ within \xintfloatexpr. The exponent will be first truncated to either an
% integer or an half-integer.|
% \begin{macrocode}
\def\xintFloatPower {\romannumeral0\xintfloatpower}%
\def\xintfloatpower #1{\XINT_flpower_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatPower {\romannumeral0\XINTinfloatpower }%
\def\XINTinfloatpower #1{\XINT_flpower_chkopt \XINTinfloatS #1\xint_relax }%
\def\XINTinFloatPowerH {\romannumeral0\XINTinfloatpowerH }%
\def\XINTinfloatpowerH #1#2%
{\expandafter\XINT_flpowerh_a \romannumeral0\xinttrunc 1{#2}.0;%
\XINTdigits.{#1}{\XINTinfloatS[\XINTdigits]}}%
\def\XINT_flpowerh_a #1.#2%
{%
\ifnum#2>\xint_c_iv\xint_dothis\XINT_flpowerh_b\fi
\xint_orthat\XINT_flpowerh_i #1.#2%
}%
\def\XINT_flpowerh_i #1.#2;%
{\expandafter\XINT_flpower_checkB_a\romannumeral0\xintinum{#1}.}%
\def\XINT_flpowerh_b #1%
{%
\if#1-\xint_dothis\XINT_flpowerh_bneg\fi
\xint_orthat{\XINT_flpowerh_bpos #1}%
}%
\def\XINT_flpowerh_bpos #1.#2;\XINTdigits.#3#4%
{%
\expandafter\XINT_flpower_checkB_a
\romannumeral0\xintinc{\xintDouble{#1}}.%
\XINTdigits.{#3}{\XINTinfloatsqrt[\XINTdigits]}%
}%
\def\XINT_flpowerh_bneg #1.#2;\XINTdigits.#3#4%
{%
\expandafter\XINT_flpower_checkB_a
\expandafter-\romannumeral0\xintinc{\xintDouble{#1}}.%
\XINTdigits.{#3}{\XINTinfloatsqrt[\XINTdigits]}%
}%
\def\XINT_flpower_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flpower_opt
\else\expandafter\XINT_flpower_noopt
\fi
#1#2%
}%
\def\XINT_flpower_noopt #1#2\xint_relax #3%
{%
\expandafter\XINT_flpower_checkB_a
\romannumeral0\xintnum{#3}.\XINTdigits.{#2}{#1[\XINTdigits]}%
}%
\def\XINT_flpower_opt #1[\xint_relax #2]%
{%
\expandafter\XINT_flpower_opt_a\the\numexpr #2.#1%
}%
\def\XINT_flpower_opt_a #1.#2#3#4%
{%
\expandafter\XINT_flpower_checkB_a
\romannumeral0\xintnum{#4}.#1.{#3}{#2[#1]}%
}%
\def\XINT_flpower_checkB_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_flpower_BisZero
0#1{\XINT_flpower_checkB_b -}%
0-{\XINT_flpower_checkB_b {}#1}%
\krof
}%
\def\XINT_flpower_BisZero .#1.#2#3{#3{1[0]}}%
\def\XINT_flpower_checkB_b #1#2.#3.%
{%
\expandafter\XINT_flpower_checkB_c
\the\numexpr\xintLength{#2}+\xint_c_iii.#3.#2.{#1}%
}%
\def\XINT_flpower_checkB_c #1.#2.%
{%
\expandafter\XINT_flpower_checkB_d\the\numexpr#1+#2.#1.#2.%
}%
\def\XINT_flpower_checkB_d #1.#2.#3.#4.#5#6%
{%
\expandafter \XINT_flpower_aa
\romannumeral0\XINTinfloat [#3]{#6}{#2}{#1}{#4}{#5}%
}%
\def\XINT_flpower_aa #1[#2]#3%
{%
\expandafter\XINT_flpower_ab\the\numexpr #2-#3\expandafter.%
\romannumeral0\XINT_dsx_addzerosnofuss {#3}{}.#1.%
}%
\def\XINT_flpower_ab #1.#2.#3.{\XINT_flpower_a #3#2[#1]}%
\def\XINT_flpower_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_flpow_zero
0#1{\XINT_flpower_b \iftrue}%
0-{\XINT_flpower_b \iffalse#1}%
\krof
}%
\def\XINT_flpower_b #1#2[#3]#4#5%
{%
\XINT_flpower_loopI #5.#3.#2.#4.{#1\xintiiOdd{#5}\fi}%
}%
\def\XINT_flpower_loopI #1.%
{%
\if1\XINT_isOne {#1}\xint_dothis\XINT_flpower_ItoIII\fi
\if1\xintiiOdd {#1}\xint_dothis{\expandafter\XINT_flpower_loopI_odd}\fi
\xint_orthat{\expandafter\XINT_flpower_loopI_even}%
\romannumeral0\xinthalf{#1}.%
}%
\def\XINT_flpower_ItoIII #1.#2.#3.#4.#5%
{%
\expandafter\XINT_flpow_III\the\numexpr #5+\xint_c_.#2.#3.#4.%
}%
\def\XINT_flpower_loopI_even #1.#2.#3.#4.%
{%
\expandafter\XINT_flpower_toloopI
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.#1.%
}%
\def\XINT_flpower_toloopI #1.#2.#3.#4.{\XINT_flpower_loopI #4.#1.#2.#3.}%
\def\XINT_flpower_loopI_odd #1.#2.#3.#4.%
{%
\expandafter\XINT_flpower_toloopII
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.%
#1.#2.#3.%
}%
\def\XINT_flpower_toloopII #1.#2.#3.#4.{\XINT_flpower_loopII #4.#1.#2.#3.}%
\def\XINT_flpower_loopII #1.%
{%
\if1\XINT_isOne{#1}\xint_dothis\XINT_flpower_IItoIII\fi
\if1\xintiiOdd{#1}\xint_dothis{\expandafter\XINT_flpower_loopII_odd}\fi
\xint_orthat{\expandafter\XINT_flpower_loopII_even}%
\romannumeral0\xinthalf{#1}.%
}%
\def\XINT_flpower_loopII_even #1.#2.#3.#4.%
{%
\expandafter\XINT_flpower_toloopII
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.#1.%
}%
\def\XINT_flpower_loopII_odd #1.#2.#3.#4.#5.#6.%
{%
\expandafter\XINT_flpower_loopII_odda
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr#2+#5\expandafter.\romannumeral0\xintiimul{#3}{#6}.#4.%
#1.#2.#3.%
}%
\def\XINT_flpower_loopII_odda #1.#2.#3.#4.#5.#6.%
{%
\expandafter\XINT_flpower_toloopII
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr\xint_c_ii*#5\expandafter.\romannumeral0\xintiisqr{#6}.#3.%
#4.#1.#2.%
}%
\def\XINT_flpower_IItoIII #1.#2.#3.#4.#5.#6.#7%
{%
\expandafter\XINT_flpow_III\the\numexpr #7+\xint_c_\expandafter.%
\the\numexpr\expandafter\XINT_flpow_truncate
\the\numexpr#2+#5\expandafter.\romannumeral0\xintiimul{#3}{#6}.#4.%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatFac}, \csh{XINTFloatFac}}
% \begin{macrocode}
\def\xintFloatFac {\romannumeral0\xintfloatfac}%
\def\xintfloatfac #1{\XINT_flfac_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatFac {\romannumeral0\XINTinfloatfac }%
\def\XINTinfloatfac #1{\XINT_flfac_chkopt \XINTinfloat #1\xint_relax }%
\def\XINT_flfac_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flfac_opt
\else\expandafter\XINT_flfac_noopt
\fi
#1#2%
}%
\def\XINT_flfac_noopt #1#2\xint_relax
{%
\expandafter\XINT_FL_fac_fork_a
\the\numexpr \xintNum{#2}.\xint_c_i \XINTdigits\XINT_FL_fac_out{#1[\XINTdigits]}%
}%
\def\XINT_flfac_opt #1[\xint_relax #2]%
{%
\expandafter\XINT_flfac_opt_a\the\numexpr #2.#1%
}%
\def\XINT_flfac_opt_a #1.#2#3%
{%
\expandafter\XINT_FL_fac_fork_a\the\numexpr \xintNum{#3}.\xint_c_i {#1}\XINT_FL_fac_out{#2[#1]}%
}%
\def\XINT_FL_fac_fork_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_FL_fac_iszero
0#1\XINT_FL_fac_isneg
0-{\XINT_FL_fac_fork_b #1}%
\krof
}%
\def\XINT_FL_fac_iszero #1.#2#3#4#5{#5{1[0]}}%
% \end{macrocode}
% \lverb|1.2f XINT_FL_fac_isneg returns 0, earlier versions used 1 here.|
% \begin{macrocode}
\def\XINT_FL_fac_isneg #1.#2#3#4#5{\expandafter\xintError:FactorialOfNegative #5{0[0]}}%
\def\XINT_FL_fac_fork_b #1.%
{%
\ifnum #1>\xint_c_x^viii_mone\xint_dothis\XINT_FL_fac_toobig\fi
\ifnum #1>\xint_c_x^iv\xint_dothis\XINT_FL_fac_vbig \fi
\ifnum #1>465 \xint_dothis\XINT_FL_fac_big\fi
\ifnum #1>101 \xint_dothis\XINT_FL_fac_med\fi
\xint_orthat\XINT_FL_fac_small
#1.%
}%
\def\XINT_FL_fac_toobig #1.#2#3#4#5{\expandafter\xintError:TooBigFactorial #5{1[0]}}%
% \end{macrocode}
% \lverb?Computations are done with Q blocks of eight digits. When a
% multiplication has a carry, hence creates Q+1 blocks, the least significant
% one is dropped. The goal is to compute an approximate value X' to the exact
% value X, such that the final relative error (X-X')/X will be at most
% 10^{-P-1} with P the desired precision. Then, when we round X' to X'' with P
% significant digits, we can prove that the absolute error |X-X''| is bounded
% (strictly) by 0.6 ulp(X''). (ulp= unit in the last (significant) place). Let
% N be the number of such operations, the formula for Q deduces from the
% previous explanations is that 8Q should be at least P+9+k, with k the number
% of digits of N (in base 10). Note that 1.2 version used P+10+k, for 1.2f I
% reduced to P+9+k. Also, k should be the number of digits of the number N of
% multiplications done, hence for n<=10000 we can take N=n/2, or N/3, or N/4.
% This is rounded above by numexpr and always an overestimate of the actual
% number of approximate multiplications done (the first ones are exact).
% (vérifier ce que je raconte, j'ai la flemme là).
%
% We then want ceil((P+k+n)/8). Using \numexpr rounding division
% (ARRRRRGGGHHHH), if m is a positive integer, ceil(m/8) can be computed as
% (m+3)/8. Thus with m=P+10+k, this gives Q<-(P+13+k)/8. The routine actually
% computes 8(Q-1) for use in \XINT_FL_fac_addzeros.
%
% With 1.2f the formula is m=P+9+k, Q<-(P+12+k)/8, and we use now 4=12-8 rather
% than the earlier 5=13-8. Whatever happens, the value computed in
% \XINT_FL_fac_increaseP is at least 8. There will always be an extra block.
%
% Note: with Digits:=32; Maple gives for 200!:$bgroup$obeylines$obeyspaces$ttbfamily
% > factorial(200.);
% $indent 375
% $indent 0.78865786736479050355236321393218 10
% My 1.2f routine (and also 1.2) outputs:
% $indent 7.8865786736479050355236321393219e374
% and this is the correct rounding because for 40 digits it computes
% $indent 7.886578673647905035523632139321850622951e374
% $egroup
% Maple's result (contrarily to xint) is thus not the correct rounding but
% still it is less than 0.6 ulp wrong.
% ?
% \begin{macrocode}
\def\XINT_FL_fac_vbig
{\expandafter\XINT_FL_fac_vbigloop_a
\the\numexpr \XINT_FL_fac_increaseP \xint_c_i }%
\def\XINT_FL_fac_big
{\expandafter\XINT_FL_fac_bigloop_a
\the\numexpr \XINT_FL_fac_increaseP \xint_c_ii }%
\def\XINT_FL_fac_med
{\expandafter\XINT_FL_fac_medloop_a
\the\numexpr \XINT_FL_fac_increaseP \xint_c_iii }%
\def\XINT_FL_fac_small
{\expandafter\XINT_FL_fac_smallloop_a
\the\numexpr \XINT_FL_fac_increaseP \xint_c_iv }%
\def\XINT_FL_fac_increaseP #1#2.#3#4%
{%
#2\expandafter.\the\numexpr\xint_c_viii*%
((\xint_c_iv+#4+\expandafter\XINT_FL_fac_countdigits
\the\numexpr #2/(#1*#3)\relax 87654321\Z)/\xint_c_viii).%
}%
\def\XINT_FL_fac_countdigits #1#2#3#4#5#6#7#8{\XINT_FL_fac_countdone }%
\def\XINT_FL_fac_countdone #1#2\Z {#1}%
\def\XINT_FL_fac_out #1\Z![#2]#3{#3{\romannumeral0\XINT_mul_out
#1\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W [#2]}}%
\def\XINT_FL_fac_vbigloop_a #1.#2.%
{%
\XINT_FL_fac_bigloop_a \xint_c_x^iv.#2.%
{\expandafter\XINT_FL_fac_vbigloop_loop\the\numexpr 100010001\expandafter.%
\the\numexpr \xint_c_x^viii+#1.}%
}%
\def\XINT_FL_fac_vbigloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi
\expandafter\XINT_FL_fac_vbigloop_loop
\the\numexpr #1+\xint_c_i\expandafter.%
\the\numexpr #2\expandafter.\the\numexpr\XINT_FL_fac_mul #1!%
}%
\def\XINT_FL_fac_bigloop_a #1.%
{%
\expandafter\XINT_FL_fac_bigloop_b \the\numexpr
#1+\xint_c_i-\xint_c_ii*((#1-464)/\xint_c_ii).#1.%
}%
\def\XINT_FL_fac_bigloop_b #1.#2.#3.%
{%
\expandafter\XINT_FL_fac_medloop_a
\the\numexpr #1-\xint_c_i.#3.{\XINT_FL_fac_bigloop_loop #1.#2.}%
}%
\def\XINT_FL_fac_bigloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi
\expandafter\XINT_FL_fac_bigloop_loop
\the\numexpr #1+\xint_c_ii\expandafter.%
\the\numexpr #2\expandafter.\the\numexpr\XINT_FL_fac_bigloop_mul #1!%
}%
\def\XINT_FL_fac_bigloop_mul #1!%
{%
\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!%
}%
\def\XINT_FL_fac_medloop_a #1.%
{%
\expandafter\XINT_FL_fac_medloop_b
\the\numexpr #1+\xint_c_i-\xint_c_iii*((#1-100)/\xint_c_iii).#1.%
}%
\def\XINT_FL_fac_medloop_b #1.#2.#3.%
{%
\expandafter\XINT_FL_fac_smallloop_a
\the\numexpr #1-\xint_c_i.#3.{\XINT_FL_fac_medloop_loop #1.#2.}%
}%
\def\XINT_FL_fac_medloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi
\expandafter\XINT_FL_fac_medloop_loop
\the\numexpr #1+\xint_c_iii\expandafter.%
\the\numexpr #2\expandafter.\the\numexpr\XINT_FL_fac_medloop_mul #1!%
}%
\def\XINT_FL_fac_medloop_mul #1!%
{%
\expandafter\XINT_FL_fac_mul
\the\numexpr
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_FL_fac_smallloop_a #1.%
{%
\csname
XINT_FL_fac_smallloop_\the\numexpr #1-\xint_c_iv*(#1/\xint_c_iv)\relax
\endcsname #1.%
}%
\expandafter\def\csname XINT_FL_fac_smallloop_1\endcsname #1.#2.%
{%
\XINT_FL_fac_addzeros #2.100000001!.{2.#1.}{#2}%
}%
\expandafter\def\csname XINT_FL_fac_smallloop_-2\endcsname #1.#2.%
{%
\XINT_FL_fac_addzeros #2.100000002!.{3.#1.}{#2}%
}%
\expandafter\def\csname XINT_FL_fac_smallloop_-1\endcsname #1.#2.%
{%
\XINT_FL_fac_addzeros #2.100000006!.{4.#1.}{#2}%
}%
\expandafter\def\csname XINT_FL_fac_smallloop_0\endcsname #1.#2.%
{%
\XINT_FL_fac_addzeros #2.100000024!.{5.#1.}{#2}%
}%
\def\XINT_FL_fac_addzeros #1.%
{%
\ifnum #1=\xint_c_viii \expandafter\XINT_FL_fac_addzeros_exit\fi
\expandafter\XINT_FL_fac_addzeros\the\numexpr #1-\xint_c_viii.100000000!%
}%
% \end{macrocode}
% \lverb|We will manipulate by successive *small* multiplications Q blocks
% 1<8d>!, terminated by 1\Z!. We need a custom small multiplication which
% tells us when it has create a new block, and the least significant one
% should be dropped.|
% \begin{macrocode}
\def\XINT_FL_fac_addzeros_exit #1.#2.#3#4{\XINT_FL_fac_smallloop_loop #3#21\Z![-#4]}%
\def\XINT_FL_fac_smallloop_loop #1.#2.%
{%
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi
\expandafter\XINT_FL_fac_smallloop_loop
\the\numexpr #1+\xint_c_iv\expandafter.%
\the\numexpr #2\expandafter.\romannumeral0\XINT_FL_fac_smallloop_mul #1!%
}%
\def\XINT_FL_fac_smallloop_mul #1!%
{%
\expandafter\XINT_FL_fac_mul
\the\numexpr
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%[[
\def\XINT_FL_fac_loop_exit #1!#2]#3{#3#2]}%
\def\XINT_FL_fac_mul 1#1!%
{\expandafter\XINT_FL_fac_mul_a\the\numexpr\XINT_FL_fac_smallmul 10!{#1}}%
\def\XINT_FL_fac_mul_a #1-#2%
{%
\if#21\xint_afterfi{\expandafter\space\xint_gob_til_exclam}\else
\expandafter\space\fi #11\Z!%
}%
\def\XINT_FL_fac_minimulwc_a #1#2#3#4#5!#6#7#8#9%
{%
\XINT_FL_fac_minimulwc_b {#1#2#3#4}{#5}{#6#7#8#9}%
}%
\def\XINT_FL_fac_minimulwc_b #1#2#3#4!#5%
{%
\expandafter\XINT_FL_fac_minimulwc_c
\the\numexpr \xint_c_x^ix+#5+#2*#4.{{#1}{#2}{#3}{#4}}%
}%
\def\XINT_FL_fac_minimulwc_c 1#1#2#3#4#5#6.#7%
{%
\expandafter\XINT_FL_fac_minimulwc_d {#1#2#3#4#5}#7{#6}%
}%
\def\XINT_FL_fac_minimulwc_d #1#2#3#4#5%
{%
\expandafter\XINT_FL_fac_minimulwc_e
\the\numexpr \xint_c_x^ix+#1+#2*#5+#3*#4.{#2}{#4}%
}%
\def\XINT_FL_fac_minimulwc_e 1#1#2#3#4#5#6.#7#8#9%
{%
1#6#9\expandafter!%
\the\numexpr\expandafter\XINT_FL_fac_smallmul
\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#7*#8!%
}%
\def\XINT_FL_fac_smallmul 1#1!#21#3!%
{%
\xint_gob_til_Z #3\XINT_FL_fac_smallmul_end\Z
\XINT_FL_fac_minimulwc_a #2!#3!{#1}{#2}%
}%
% \end{macrocode}
% \lverb|This is the crucial ending. I note that I used here an \ifnum test
% rather than the gob_til_eightzeroes thing. Actually for eight digits there
% is much less difference than for only four.
%
% The "carry" situation is marked by a final !-1 rather than !-2 for no-carry.
% (a \numexpr muste be stopped, and leaving a - as delimiter is good as it
% will not arise earlier.)|
% \begin{macrocode}
\def\XINT_FL_fac_smallmul_end\Z\XINT_FL_fac_minimulwc_a #1!\Z!#2#3[#4]%
{%
\ifnum #2=\xint_c_
\expandafter\xint_firstoftwo\else
\expandafter\xint_secondoftwo
\fi
{-2\relax[#4]}%
{1#2\expandafter!\expandafter-\expandafter1\expandafter
[\the\numexpr #4+\xint_c_viii]}%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatPFactorial}, \csh{XINTinFloatPFactorial}}
% \lverb|2015/11/29 for 1.2f. Partial factorial pfactorial(a,b)=(a+1)...b,
% only for non-negative integers with a<=b<10^8.
%
% 1.2h (2016/11/20) now avoids raising \xintError:OutOfRangePFac if the
% condition 0<=a<=b<10^8 is violated. Same as for \xintiiPFactorial.|
% \begin{macrocode}
\def\xintFloatPFactorial {\romannumeral0\xintfloatpfactorial}%
\def\xintfloatpfactorial #1{\XINT_flpfac_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatPFactorial {\romannumeral0\XINTinfloatpfactorial }%
\def\XINTinfloatpfactorial #1{\XINT_flpfac_chkopt \XINTinfloat #1\xint_relax }%
\def\XINT_flpfac_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flpfac_opt
\else\expandafter\XINT_flpfac_noopt
\fi
#1#2%
}%
\def\XINT_flpfac_noopt #1#2\xint_relax #3%
{%
\expandafter\XINT_FL_pfac_fork
\the\numexpr \xintNum{#2}\expandafter.%
\the\numexpr \xintNum{#3}.\xint_c_i{\XINTdigits}{#1[\XINTdigits]}%
}%
\def\XINT_flpfac_opt #1[\xint_relax #2]%
{%
\expandafter\XINT_flpfac_opt_b\the\numexpr #2.#1%
}%
\def\XINT_flpfac_opt_b #1.#2#3#4%
{%
\expandafter\XINT_FL_pfac_fork
\the\numexpr \xintNum{#3}\expandafter.%
\the\numexpr \xintNum{#4}.\xint_c_i{#1}{#2[#1]}%
}%
\def\XINT_FL_pfac_fork #1#2.#3#4.%
{%
\unless\ifnum #1#2<#3#4 \xint_dothis\XINT_FL_pfac_one\fi
\if-#3\xint_dothis\XINT_FL_pfac_neg \fi
\if-#1\xint_dothis\XINT_FL_pfac_zero\fi
\ifnum #3#4>\xint_c_x^viii_mone\xint_dothis\XINT_FL_pfac_outofrange\fi
\xint_orthat \XINT_FL_pfac_increaseP #1#2.#3#4.%
}%
\def\XINT_FL_pfac_outofrange #1.#2.#3#4#5{\xintError:OutOfRangePFac #5{0[0]}}%
\def\XINT_FL_pfac_one #1.#2.#3#4#5{#5{1[0]}}%
\def\XINT_FL_pfac_zero #1.#2.#3#4#5{#5{0[0]}}%
\def\XINT_FL_pfac_neg -#1.-#2.%
{%
\ifnum #1>\xint_c_x^viii\xint_dothis\XINT_FL_pfac_outofrange\fi
\xint_orthat {%
\ifodd\numexpr#2-#1\relax\xint_afterfi{\expandafter-\romannumeral`&&@}\fi
\expandafter\XINT_FL_pfac_increaseP}%
\the\numexpr #2-\xint_c_i\expandafter.\the\numexpr#1-\xint_c_i.%
}%
% \end{macrocode}
% \lverb|See the comments for \XINT_FL_pfac_increaseP. Case of b=a+1 should be
% filtered out perhaps. We only needed here to copy the \xintPFactorial macros and
% re-use \XINT_FL_fac_mul/\XINT_FL_fac_out. Had to modify a bit
% \XINT_FL_pfac_addzeroes. We can enter here directly with #3 equal to specify
% the precision (the calculated value before final rounding has a relative
% error less than #3.10^{-#4-1}), and #5 would hold the macro doing the final
% rounding (or truncating, if I make a FloatTrunc available) to a given number
% of digits, possibly not #4. By default the #3 is 1, but FloatBinomial calls
% it with #3=4.|
% \begin{macrocode}
\def\XINT_FL_pfac_increaseP #1.#2.#3#4%
{%
\expandafter\XINT_FL_pfac_a
\the\numexpr \xint_c_viii*((\xint_c_iv+#4+\expandafter
\XINT_FL_fac_countdigits\the\numexpr (#2-#1-\xint_c_i)%
/\ifnum #2>\xint_c_x^iv #3\else(#3*\xint_c_ii)\fi\relax
87654321\Z)/\xint_c_viii).#1.#2.%
}%
\def\XINT_FL_pfac_a #1.#2.#3.%
{%
\expandafter\XINT_FL_pfac_b\the\numexpr \xint_c_i+#2\expandafter.%
\the\numexpr#3\expandafter.%
\romannumeral0\XINT_FL_pfac_addzeroes #1.100000001!1\Z![-#1]%
}%
\def\XINT_FL_pfac_addzeroes #1.%
{%
\ifnum #1=\xint_c_viii \expandafter\XINT_FL_pfac_addzeroes_exit\fi
\expandafter\XINT_FL_pfac_addzeroes\the\numexpr #1-\xint_c_viii.100000000!%
}%
\def\XINT_FL_pfac_addzeroes_exit #1.{ }%
\def\XINT_FL_pfac_b #1.%
{%
\ifnum #1>9999 \xint_dothis\XINT_FL_pfac_vbigloop \fi
\ifnum #1>463 \xint_dothis\XINT_FL_pfac_bigloop \fi
\ifnum #1>98 \xint_dothis\XINT_FL_pfac_medloop \fi
\xint_orthat\XINT_FL_pfac_smallloop #1.%
}%
\def\XINT_FL_pfac_smallloop #1.#2.%
{%
\ifcase\numexpr #2-#1\relax
\expandafter\XINT_FL_pfac_end_
\or \expandafter\XINT_FL_pfac_end_i
\or \expandafter\XINT_FL_pfac_end_ii
\or \expandafter\XINT_FL_pfac_end_iii
\else\expandafter\XINT_FL_pfac_smallloop_a
\fi #1.#2.%
}%
\def\XINT_FL_pfac_smallloop_a #1.#2.%
{%
\expandafter\XINT_FL_pfac_smallloop_b
\the\numexpr #1+\xint_c_iv\expandafter.%
\the\numexpr #2\expandafter.%
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_FL_pfac_smallloop_b #1.%
{%
\ifnum #1>98 \expandafter\XINT_FL_pfac_medloop \else
\expandafter\XINT_FL_pfac_smallloop \fi #1.%
}%
\def\XINT_FL_pfac_medloop #1.#2.%
{%
\ifcase\numexpr #2-#1\relax
\expandafter\XINT_FL_pfac_end_
\or \expandafter\XINT_FL_pfac_end_i
\or \expandafter\XINT_FL_pfac_end_ii
\else\expandafter\XINT_FL_pfac_medloop_a
\fi #1.#2.%
}%
\def\XINT_FL_pfac_medloop_a #1.#2.%
{%
\expandafter\XINT_FL_pfac_medloop_b
\the\numexpr #1+\xint_c_iii\expandafter.%
\the\numexpr #2\expandafter.%
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_FL_pfac_medloop_b #1.%
{%
\ifnum #1>463 \expandafter\XINT_FL_pfac_bigloop \else
\expandafter\XINT_FL_pfac_medloop \fi #1.%
}%
\def\XINT_FL_pfac_bigloop #1.#2.%
{%
\ifcase\numexpr #2-#1\relax
\expandafter\XINT_FL_pfac_end_
\or \expandafter\XINT_FL_pfac_end_i
\else\expandafter\XINT_FL_pfac_bigloop_a
\fi #1.#2.%
}%
\def\XINT_FL_pfac_bigloop_a #1.#2.%
{%
\expandafter\XINT_FL_pfac_bigloop_b
\the\numexpr #1+\xint_c_ii\expandafter.%
\the\numexpr #2\expandafter.%
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!%
}%
\def\XINT_FL_pfac_bigloop_b #1.%
{%
\ifnum #1>9999 \expandafter\XINT_FL_pfac_vbigloop \else
\expandafter\XINT_FL_pfac_bigloop \fi #1.%
}%
\def\XINT_FL_pfac_vbigloop #1.#2.%
{%
\ifnum #2=#1
\expandafter\XINT_FL_pfac_end_
\else\expandafter\XINT_FL_pfac_vbigloop_a
\fi #1.#2.%
}%
\def\XINT_FL_pfac_vbigloop_a #1.#2.%
{%
\expandafter\XINT_FL_pfac_vbigloop
\the\numexpr #1+\xint_c_i\expandafter.%
\the\numexpr #2\expandafter.%
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr\xint_c_x^viii+#1!%
}%
\def\XINT_FL_pfac_end_iii #1.#2.%
{%
\expandafter\XINT_FL_fac_out
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!%
}%
\def\XINT_FL_pfac_end_ii #1.#2.%
{%
\expandafter\XINT_FL_fac_out
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!%
}%
\def\XINT_FL_pfac_end_i #1.#2.%
{%
\expandafter\XINT_FL_fac_out
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!%
}%
\def\XINT_FL_pfac_end_ #1.#2.%
{%
\expandafter\XINT_FL_fac_out
\romannumeral0\expandafter\XINT_FL_fac_mul
\the\numexpr \xint_c_x^viii+#1!%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatBinomial}, \csh{XINTinFloatBinomial}}
% \lverb|1.2f. We compute binomial(x,y) as pfac(x-y,x)/y!, where the numerator
% and denominator are computed with a relative error at most 4.10^{-P-2}, then
% rounded (once I have a float truncation, I will use truncation rather) to
% P+3 digits, and finally the quotient is correctly rounded to P digits. This
% will guarantee that the exact value X differs from the computed one Y by at
% most 0.6 ulp(Y). (2015/12/01).
%
% 2016/11/19 for 1.2h. As for \xintiiBinomial, hard to understand why last
% year I coded this to raise an error if y<0 or y>x ! The question of the
% Gamma function is for another occasion, here x and y must be (small)
% integers.|
% \begin{macrocode}
\def\xintFloatBinomial {\romannumeral0\xintfloatbinomial}%
\def\xintfloatbinomial #1{\XINT_flbinom_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatBinomial {\romannumeral0\XINTinfloatbinomial }%
\def\XINTinfloatbinomial #1{\XINT_flbinom_chkopt \XINTinfloat #1\xint_relax }%
\def\XINT_flbinom_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flbinom_opt
\else\expandafter\XINT_flbinom_noopt
\fi #1#2%
}%
\def\XINT_flbinom_noopt #1#2\xint_relax #3%
{%
\expandafter\XINT_FL_binom_a
\the\numexpr\xintNum{#2}\expandafter.\the\numexpr\xintNum{#3}.\XINTdigits.#1%
}%
\def\XINT_flbinom_opt #1[\xint_relax #2]#3#4%
{%
\expandafter\XINT_FL_binom_a
\the\numexpr\xintNum{#3}\expandafter.\the\numexpr\xintNum{#4}\expandafter.%
\the\numexpr #2.#1%
}%
\def\XINT_FL_binom_a #1.#2.%
{%
\expandafter\XINT_FL_binom_fork \the\numexpr #1-#2.#2.#1.%
}%
\def\XINT_FL_binom_fork #1#2.#3#4.#5#6.%
{%
\if-#5\xint_dothis \XINT_FL_binom_outofrange\fi
\if-#1\xint_dothis \XINT_FL_binom_zero\fi
\if-#3\xint_dothis \XINT_FL_binom_zero\fi
\if0#1\xint_dothis \XINT_FL_binom_one\fi
\if0#3\xint_dothis \XINT_FL_binom_one\fi
\ifnum #5#6>\xint_c_x^viii_mone \xint_dothis\XINT_FL_binom_outofrange\fi
\ifnum #1#2>#3#4 \xint_dothis\XINT_FL_binom_ab \fi
\xint_orthat\XINT_FL_binom_aa
#1#2.#3#4.#5#6.%
}%
\def\XINT_FL_binom_outofrange #1.#2.#3.#4.#5%
{\xintError:OutOfRangeBinomial #5[#4]{0[0]}}%
\def\XINT_FL_binom_one #1.#2.#3.#4.#5{#5[#4]{1[0]}}%
\def\XINT_FL_binom_zero #1.#2.#3.#4.#5{#5[#4]{0[0]}}%
\def\XINT_FL_binom_aa #1.#2.#3.#4.#5%
{%
#5[#4]{\xintDiv{\XINT_FL_pfac_increaseP
#2.#3.\xint_c_iv{#4+\xint_c_i}{\XINTinfloat[#4+\xint_c_iii]}}%
{\XINT_FL_fac_fork_b
#1.\xint_c_iv{#4+\xint_c_i}\XINT_FL_fac_out{\XINTinfloat[#4+\xint_c_iii]}}}%
}%
\def\XINT_FL_binom_ab #1.#2.#3.#4.#5%
{%
#5[#4]{\xintDiv{\XINT_FL_pfac_increaseP
#1.#3.\xint_c_iv{#4+\xint_c_i}{\XINTinfloat[#4+\xint_c_iii]}}%
{\XINT_FL_fac_fork_b
#2.\xint_c_iv{#4+\xint_c_i}\XINT_FL_fac_out{\XINTinfloat[#4+\xint_c_iii]}}}%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatSqrt}, \csh{XINTinFloatSqrt}}
% \lverb|First done for 1.08.
%
% The float version was developed at the same time as the integer one and even
% a bit earlier. As a result the integer variant had some sub-optimal parts.
% Anyway, for 1.2f I have rewritten the integer variant, and the float variant
% delegates all preparatory wrok for it until the last step. In particular the
% very low precisions are not penalized anymore from doing computations for at
% least 17 or 18 digits. Both the large and small precisions give quite
% shorter computation times.
%
% Also, after examining more closely the achieved precision I decided to
% extend the float version in order for it to obtain the correct rounding (for
% inputs already of at most P digits with P the precision) of the theoretical
% exact value.
%
% Beyond about 500 digits of precision the efficiency decreases swiftly,
% as is the case generally speaking with xintcore/xint/xintfrac arithmetic
% macros.
%
% Final note: with 1.2f the input is always first rounded to P significant
% places.
%
%
% |
% \begin{macrocode}
\def\xintFloatSqrt {\romannumeral0\xintfloatsqrt }%
\def\xintfloatsqrt #1{\XINT_flsqrt_chkopt \xintfloat #1\xint_relax }%
\def\XINTinFloatSqrt {\romannumeral0\XINTinfloatsqrt }%
\def\XINTinfloatsqrt #1{\XINT_flsqrt_chkopt \XINTinfloat #1\xint_relax }%
\def\XINT_flsqrt_chkopt #1#2%
{%
\ifx [#2\expandafter\XINT_flsqrt_opt
\else\expandafter\XINT_flsqrt_noopt
\fi #1#2%
}%
\def\XINT_flsqrt_noopt #1#2\xint_relax
{%
\expandafter\XINT_FL_sqrt_a
\romannumeral0\XINTinfloat[\XINTdigits]{#2}\XINTdigits.#1%
}%
\def\XINT_flsqrt_opt #1[\xint_relax #2]%#3%
{%
\expandafter\XINT_flsqrt_opt_a\the\numexpr #2.#1%
}%
\def\XINT_flsqrt_opt_a #1.#2#3%
{%
\expandafter\XINT_FL_sqrt_a\romannumeral0\XINTinfloat[#1]{#3}#1.#2%
}%
\def\XINT_FL_sqrt_a #1%
{%
\xint_UDzerominusfork
#1-\XINT_FL_sqrt_iszero
0#1\XINT_FL_sqrt_isneg
0-{\XINT_FL_sqrt_pos #1}%
\krof
}%[
\def\XINT_FL_sqrt_iszero #1]#2.#3{#3[#2]{0[0]}}%
\def\XINT_FL_sqrt_isneg #1]#2.#3{\xintError:RootOfNegative #3[#2]{0[0]}}%
\def\XINT_FL_sqrt_pos #1[#2]#3.%
{%
\expandafter\XINT_flsqrt
\the\numexpr #3\ifodd #2 \xint_dothis {+\xint_c_iii.(#2+\xint_c_i).0}\fi
\xint_orthat {+\xint_c_ii.#2.{}}#100.#3.%
}%
\def\XINT_flsqrt #1.#2.%
{%
\expandafter\XINT_flsqrt_a
\the\numexpr #2/\xint_c_ii-(#1-\xint_c_i)/\xint_c_ii.#1.%
}%
\def\XINT_flsqrt_a #1.#2.#3#4.#5.%
{%
\expandafter\XINT_flsqrt_b
\the\numexpr (#2-\xint_c_i)/\xint_c_ii\expandafter.%
\romannumeral0\XINT_sqrt_start #2.#4#3.#5.#2.#4#3.#5.#1.%
}%
\def\XINT_flsqrt_b #1.#2#3%
{%
\expandafter\XINT_flsqrt_c
\romannumeral0\xintiisub
{\XINT_dsx_addzerosnofuss {#1}{#2}}%
{\xintiiDivRound{\XINT_dsx_addzerosnofuss {#1}{#3}}{\XINT_dbl_pos#2\Z}}.%
}%
\def\XINT_flsqrt_c #1.#2.%
{%
\expandafter\XINT_flsqrt_d
\romannumeral0\XINT_split_fromleft_loop #2.{}#1\W\W\W\W\W\W\W\W\Z
}%
\def\XINT_flsqrt_d #1.#2#3.%
{%
\ifnum #2=\xint_c_v
\expandafter\XINT_flsqrt_f\else\expandafter\XINT_flsqrt_finish\fi
#2#3.#1.%
}%
\def\XINT_flsqrt_finish #1#2.#3.#4.#5.#6.#7.#8{#8[#6]{#3#1[#7]}}%
\def\XINT_flsqrt_f 5#1.%
{\expandafter\XINT_flsqrt_g\romannumeral0\xintinum{#1}\relax.}%
\def\XINT_flsqrt_g #1#2#3.{\if\relax#2\xint_dothis{\XINT_flsqrt_h #1}\fi
\xint_orthat{\XINT_flsqrt_finish 5.}}%
\def\XINT_flsqrt_h #1{\ifnum #1<\xint_c_iii\xint_dothis{\XINT_flsqrt_again}\fi
\xint_orthat{\XINT_flsqrt_finish 5.}}%
\def\XINT_flsqrt_again #1.#2.%
{%
\expandafter\XINT_flsqrt_again_a\the\numexpr #2+\xint_c_viii.%
}%
\def\XINT_flsqrt_again_a #1.#2.#3.%
{%
\expandafter\XINT_flsqrt_b
\the\numexpr (#1-\xint_c_i)/\xint_c_ii\expandafter.%
\romannumeral0\XINT_sqrt_start #1.#200000000.#3.%
#1.#200000000.#3.%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatE}, \csh{XINTinFloatE}}
% \begin{macrocode}
\def\xintFloatE {\romannumeral0\xintfloate }%
\def\xintfloate #1{\XINT_floate_chkopt #1\xint_relax }%
\def\XINT_floate_chkopt #1%
{%
\ifx [#1\expandafter\XINT_floate_opt
\else\expandafter\XINT_floate_noopt
\fi #1%
}%
\def\XINT_floate_noopt #1\xint_relax
{%
\expandafter\XINT_floate_a\expandafter\XINTdigits
\romannumeral0\XINT_infrac {#1}%
}%
\def\XINT_floate_opt [\xint_relax #1]#2%
{%
\expandafter\XINT_floate_a\expandafter
{\the\numexpr #1\expandafter}\romannumeral0\XINT_infrac {#2}%
}%
\def\XINT_floate_a #1#2#3#4#5%
{%
\expandafter\XINT_float_a\the\numexpr#1\expandafter.%
\expandafter{\the\numexpr #2+#5}{#3}{#4}\XINT_float_Q
}%
\def\XINTinFloatE {\romannumeral0\XINTinfloate }%
\def\XINTinfloate
{\expandafter\XINT_infloate\romannumeral0\XINTinfloat [\XINTdigits]}%
\def\XINT_infloate #1[#2]#3%
{\expandafter\XINT_infloate_end\the\numexpr #3+#2.{#1}}%
\def\XINT_infloate_end #1.#2{ #2[#1]}%
% \end{macrocode}
% \subsection{\csh{XINTinFloatMod}}
% \begin{macrocode}
\def\XINTinFloatMod {\romannumeral0\XINTinfloatmod [\XINTdigits]}%
\def\XINTinfloatmod [#1]#2#3{\expandafter\XINT_infloatmod\expandafter
{\romannumeral0\XINTinfloat[#1]{#2}}%
{\romannumeral0\XINTinfloat[#1]{#3}}{#1}}%
\def\XINT_infloatmod #1#2{\expandafter\XINT_infloatmod_a\expandafter {#2}{#1}}%
\def\XINT_infloatmod_a #1#2#3{\XINTinfloat [#3]{\xintMod {#2}{#1}}}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintfrac}
%
%\gardesactifs
%\let</xintfrac>\relax
%\let<*xintseries>\gardesinactifs
%</xintfrac>^^A---------------------------------------------------
%<*xintseries>^^A-------------------------------------------------
% \clearpage
% \section{Package \xintseriesnameimp implementation}
% \label{sec:seriesimp}
%
% \localtableofcontents
%
% The commenting is currently (\xintdocdate) very sparse.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xintseries.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintfrac.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintseries}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintseries.sty
\ifx\w\relax % but xintfrac.sty not yet loaded.
\def\z{\endgroup\input xintfrac.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintfrac.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintfrac}}%
\fi
\else
\aftergroup\endinput % xintseries already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintseries}%
[2016/11/20 1.2h Expandable partial sums with xint package (JFB)]%
% \end{macrocode}
% \subsection{\csh{xintSeries}}
% \begin{macrocode}
\def\xintSeries {\romannumeral0\xintseries }%
\def\xintseries #1#2%
{%
\expandafter\XINT_series\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_series #1#2#3%
{%
\ifnum #2<#1
\xint_afterfi { 0/1[0]}%
\else
\xint_afterfi {\XINT_series_loop {#1}{0}{#2}{#3}}%
\fi
}%
\def\XINT_series_loop #1#2#3#4%
{%
\ifnum #3>#1 \else \XINT_series_exit \fi
\expandafter\XINT_series_loop\expandafter
{\the\numexpr #1+1\expandafter }\expandafter
{\romannumeral0\xintadd {#2}{#4{#1}}}%
{#3}{#4}%
}%
\def\XINT_series_exit \fi #1#2#3#4#5#6#7#8%
{%
\fi\xint_gobble_ii #6%
}%
% \end{macrocode}
% \subsection{\csh{xintiSeries}}
% \begin{macrocode}
\def\xintiSeries {\romannumeral0\xintiseries }%
\def\xintiseries #1#2%
{%
\expandafter\XINT_iseries\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_iseries #1#2#3%
{%
\ifnum #2<#1
\xint_afterfi { 0}%
\else
\xint_afterfi {\XINT_iseries_loop {#1}{0}{#2}{#3}}%
\fi
}%
\def\XINT_iseries_loop #1#2#3#4%
{%
\ifnum #3>#1 \else \XINT_iseries_exit \fi
\expandafter\XINT_iseries_loop\expandafter
{\the\numexpr #1+1\expandafter }\expandafter
{\romannumeral0\xintiiadd {#2}{#4{#1}}}%
{#3}{#4}%
}%
\def\XINT_iseries_exit \fi #1#2#3#4#5#6#7#8%
{%
\fi\xint_gobble_ii #6%
}%
% \end{macrocode}
% \subsection{\csh{xintPowerSeries}}
% \lverb|&
% The 1.03 version was very lame and created a build-up of denominators.
% (this was at a time \xintAdd always multiplied denominators, by the way)
% The Horner scheme for polynomial evaluation is used in 1.04, this
% cures the denominator problem and drastically improves the efficiency
% of the macro.
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
% 1.08a adds the forgotten optimization following that previous change.|
% \begin{macrocode}
\def\xintPowerSeries {\romannumeral0\xintpowerseries }%
\def\xintpowerseries #1#2%
{%
\expandafter\XINT_powseries\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_powseries #1#2#3#4%
{%
\ifnum #2<#1
\xint_afterfi { 0/1[0]}%
\else
\xint_afterfi
{\XINT_powseries_loop_i {#3{#2}}{#1}{#2}{#3}{#4}}%
\fi
}%
\def\XINT_powseries_loop_i #1#2#3#4#5%
{%
\ifnum #3>#2 \else\XINT_powseries_exit_i\fi
\expandafter\XINT_powseries_loop_ii\expandafter
{\the\numexpr #3-1\expandafter}\expandafter
{\romannumeral0\xintmul {#1}{#5}}{#2}{#4}{#5}%
}%
\def\XINT_powseries_loop_ii #1#2#3#4%
{%
\expandafter\XINT_powseries_loop_i\expandafter
{\romannumeral0\xintadd {#4{#1}}{#2}}{#3}{#1}{#4}%
}%
\def\XINT_powseries_exit_i\fi #1#2#3#4#5#6#7#8#9%
{%
\fi \XINT_powseries_exit_ii #6{#7}%
}%
\def\XINT_powseries_exit_ii #1#2#3#4#5#6%
{%
\xintmul{\xintPow {#5}{#6}}{#4}%
}%
% \end{macrocode}
% \subsection{\csh{xintPowerSeriesX}}
% \lverb|&
% Same as \xintPowerSeries except for the initial expansion of the x parameter.
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
% 1.08a adds the forgotten optimization following that previous change.|
% \begin{macrocode}
\def\xintPowerSeriesX {\romannumeral0\xintpowerseriesx }%
\def\xintpowerseriesx #1#2%
{%
\expandafter\XINT_powseriesx\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_powseriesx #1#2#3#4%
{%
\ifnum #2<#1
\xint_afterfi { 0/1[0]}%
\else
\xint_afterfi
{\expandafter\XINT_powseriesx_pre\expandafter
{\romannumeral`&&@#4}{#1}{#2}{#3}%
}%
\fi
}%
\def\XINT_powseriesx_pre #1#2#3#4%
{%
\XINT_powseries_loop_i {#4{#3}}{#2}{#3}{#4}{#1}%
}%
% \end{macrocode}
% \subsection{\csh{xintRationalSeries}}
% \lverb|&
% This computes F(a)+...+F(b) on the basis of the value of F(a) and the
% ratios F(n)/F(n-1). As in \xintPowerSeries we use an iterative scheme which
% has the great advantage to avoid denominator build-up. This makes exact
% computations possible with exponential type series, which would be completely
% inaccessible to \xintSeries.
% #1=a, #2=b, #3=F(a), #4=ratio function
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
% 1.08a adds the forgotten optimization following that previous change.|
% \begin{macrocode}
\def\xintRationalSeries {\romannumeral0\xintratseries }%
\def\xintratseries #1#2%
{%
\expandafter\XINT_ratseries\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_ratseries #1#2#3#4%
{%
\ifnum #2<#1
\xint_afterfi { 0/1[0]}%
\else
\xint_afterfi
{\XINT_ratseries_loop {#2}{1}{#1}{#4}{#3}}%
\fi
}%
\def\XINT_ratseries_loop #1#2#3#4%
{%
\ifnum #1>#3 \else\XINT_ratseries_exit_i\fi
\expandafter\XINT_ratseries_loop\expandafter
{\the\numexpr #1-1\expandafter}\expandafter
{\romannumeral0\xintadd {1}{\xintMul {#2}{#4{#1}}}}{#3}{#4}%
}%
\def\XINT_ratseries_exit_i\fi #1#2#3#4#5#6#7#8%
{%
\fi \XINT_ratseries_exit_ii #6%
}%
\def\XINT_ratseries_exit_ii #1#2#3#4#5%
{%
\XINT_ratseries_exit_iii #5%
}%
\def\XINT_ratseries_exit_iii #1#2#3#4%
{%
\xintmul{#2}{#4}%
}%
% \end{macrocode}
% \subsection{\csh{xintRationalSeriesX}}
% \lverb|&
% a,b,initial,ratiofunction,x$\
% This computes F(a,x)+...+F(b,x) on the basis of the value of F(a,x) and the
% ratios F(n,x)/F(n-1,x). The argument x is first expanded and it is the value
% resulting from this which is used then throughout. The initial term F(a,x)
% must be defined as one-parameter macro which will be given x.
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
% 1.08a adds the forgotten optimization following that previous change.|
% \begin{macrocode}
\def\xintRationalSeriesX {\romannumeral0\xintratseriesx }%
\def\xintratseriesx #1#2%
{%
\expandafter\XINT_ratseriesx\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_ratseriesx #1#2#3#4#5%
{%
\ifnum #2<#1
\xint_afterfi { 0/1[0]}%
\else
\xint_afterfi
{\expandafter\XINT_ratseriesx_pre\expandafter
{\romannumeral`&&@#5}{#2}{#1}{#4}{#3}%
}%
\fi
}%
\def\XINT_ratseriesx_pre #1#2#3#4#5%
{%
\XINT_ratseries_loop {#2}{1}{#3}{#4{#1}}{#5{#1}}%
}%
% \end{macrocode}
% \subsection{\csh{xintFxPtPowerSeries}}
% \lverb|&
% I am not two happy with this piece of code. Will make it more economical
% another day.
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
% 1.08a: forgot last time some optimization from the change to \numexpr.|
% \begin{macrocode}
\def\xintFxPtPowerSeries {\romannumeral0\xintfxptpowerseries }%
\def\xintfxptpowerseries #1#2%
{%
\expandafter\XINT_fppowseries\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_fppowseries #1#2#3#4#5%
{%
\ifnum #2<#1
\xint_afterfi { 0}%
\else
\xint_afterfi
{\expandafter\XINT_fppowseries_loop_pre\expandafter
{\romannumeral0\xinttrunc {#5}{\xintPow {#4}{#1}}}%
{#1}{#4}{#2}{#3}{#5}%
}%
\fi
}%
\def\XINT_fppowseries_loop_pre #1#2#3#4#5#6%
{%
\ifnum #4>#2 \else\XINT_fppowseries_dont_i \fi
\expandafter\XINT_fppowseries_loop_i\expandafter
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter
{\romannumeral0\xintitrunc {#6}{\xintMul {#5{#2}}{#1}}}%
{#1}{#3}{#4}{#5}{#6}%
}%
\def\XINT_fppowseries_dont_i \fi\expandafter\XINT_fppowseries_loop_i
{\fi \expandafter\XINT_fppowseries_dont_ii }%
\def\XINT_fppowseries_dont_ii #1#2#3#4#5#6#7{\xinttrunc {#7}{#2[-#7]}}%
\def\XINT_fppowseries_loop_i #1#2#3#4#5#6#7%
{%
\ifnum #5>#1 \else \XINT_fppowseries_exit_i \fi
\expandafter\XINT_fppowseries_loop_ii\expandafter
{\romannumeral0\xinttrunc {#7}{\xintMul {#3}{#4}}}%
{#1}{#4}{#2}{#5}{#6}{#7}%
}%
\def\XINT_fppowseries_loop_ii #1#2#3#4#5#6#7%
{%
\expandafter\XINT_fppowseries_loop_i\expandafter
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter
{\romannumeral0\xintiiadd {#4}{\xintiTrunc {#7}{\xintMul {#6{#2}}{#1}}}}%
{#1}{#3}{#5}{#6}{#7}%
}%
\def\XINT_fppowseries_exit_i\fi\expandafter\XINT_fppowseries_loop_ii
{\fi \expandafter\XINT_fppowseries_exit_ii }%
\def\XINT_fppowseries_exit_ii #1#2#3#4#5#6#7%
{%
\xinttrunc {#7}
{\xintiiadd {#4}{\xintiTrunc {#7}{\xintMul {#6{#2}}{#1}}}[-#7]}%
}%
% \end{macrocode}
% \subsection{\csh{xintFxPtPowerSeriesX}}
% \lverb|&
% a,b,coeff,x,D$\
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
% 1.08a adds the forgotten optimization following that previous change.|
% \begin{macrocode}
\def\xintFxPtPowerSeriesX {\romannumeral0\xintfxptpowerseriesx }%
\def\xintfxptpowerseriesx #1#2%
{%
\expandafter\XINT_fppowseriesx\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_fppowseriesx #1#2#3#4#5%
{%
\ifnum #2<#1
\xint_afterfi { 0}%
\else
\xint_afterfi
{\expandafter \XINT_fppowseriesx_pre \expandafter
{\romannumeral`&&@#4}{#1}{#2}{#3}{#5}%
}%
\fi
}%
\def\XINT_fppowseriesx_pre #1#2#3#4#5%
{%
\expandafter\XINT_fppowseries_loop_pre\expandafter
{\romannumeral0\xinttrunc {#5}{\xintPow {#1}{#2}}}%
{#2}{#1}{#3}{#4}{#5}%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatPowerSeries}}
% \lverb|1.08a. I still have to re-visit \xintFxPtPowerSeries; temporarily I
% just adapted the code to the case of floats.|
% \begin{macrocode}
\def\xintFloatPowerSeries {\romannumeral0\xintfloatpowerseries }%
\def\xintfloatpowerseries #1{\XINT_flpowseries_chkopt #1\xint_relax }%
\def\XINT_flpowseries_chkopt #1%
{%
\ifx [#1\expandafter\XINT_flpowseries_opt
\else\expandafter\XINT_flpowseries_noopt
\fi
#1%
}%
\def\XINT_flpowseries_noopt #1\xint_relax #2%
{%
\expandafter\XINT_flpowseries\expandafter
{\the\numexpr #1\expandafter}\expandafter
{\the\numexpr #2}\XINTdigits
}%
\def\XINT_flpowseries_opt [\xint_relax #1]#2#3%
{%
\expandafter\XINT_flpowseries\expandafter
{\the\numexpr #2\expandafter}\expandafter
{\the\numexpr #3\expandafter}{\the\numexpr #1}%
}%
\def\XINT_flpowseries #1#2#3#4#5%
{%
\ifnum #2<#1
\xint_afterfi { 0.e0}%
\else
\xint_afterfi
{\expandafter\XINT_flpowseries_loop_pre\expandafter
{\romannumeral0\XINTinfloatpow [#3]{#5}{#1}}%
{#1}{#5}{#2}{#4}{#3}%
}%
\fi
}%
\def\XINT_flpowseries_loop_pre #1#2#3#4#5#6%
{%
\ifnum #4>#2 \else\XINT_flpowseries_dont_i \fi
\expandafter\XINT_flpowseries_loop_i\expandafter
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter
{\romannumeral0\XINTinfloatmul [#6]{#5{#2}}{#1}}%
{#1}{#3}{#4}{#5}{#6}%
}%
\def\XINT_flpowseries_dont_i \fi\expandafter\XINT_flpowseries_loop_i
{\fi \expandafter\XINT_flpowseries_dont_ii }%
\def\XINT_flpowseries_dont_ii #1#2#3#4#5#6#7{\xintfloat [#7]{#2}}%
\def\XINT_flpowseries_loop_i #1#2#3#4#5#6#7%
{%
\ifnum #5>#1 \else \XINT_flpowseries_exit_i \fi
\expandafter\XINT_flpowseries_loop_ii\expandafter
{\romannumeral0\XINTinfloatmul [#7]{#3}{#4}}%
{#1}{#4}{#2}{#5}{#6}{#7}%
}%
\def\XINT_flpowseries_loop_ii #1#2#3#4#5#6#7%
{%
\expandafter\XINT_flpowseries_loop_i\expandafter
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter
{\romannumeral0\XINTinfloatadd [#7]{#4}%
{\XINTinfloatmul [#7]{#6{#2}}{#1}}}%
{#1}{#3}{#5}{#6}{#7}%
}%
\def\XINT_flpowseries_exit_i\fi\expandafter\XINT_flpowseries_loop_ii
{\fi \expandafter\XINT_flpowseries_exit_ii }%
\def\XINT_flpowseries_exit_ii #1#2#3#4#5#6#7%
{%
\xintfloatadd [#7]{#4}{\XINTinfloatmul [#7]{#6{#2}}{#1}}%
}%
% \end{macrocode}
% \subsection{\csh{xintFloatPowerSeriesX}}
% \lverb|1.08a|
% \begin{macrocode}
\def\xintFloatPowerSeriesX {\romannumeral0\xintfloatpowerseriesx }%
\def\xintfloatpowerseriesx #1{\XINT_flpowseriesx_chkopt #1\xint_relax }%
\def\XINT_flpowseriesx_chkopt #1%
{%
\ifx [#1\expandafter\XINT_flpowseriesx_opt
\else\expandafter\XINT_flpowseriesx_noopt
\fi
#1%
}%
\def\XINT_flpowseriesx_noopt #1\xint_relax #2%
{%
\expandafter\XINT_flpowseriesx\expandafter
{\the\numexpr #1\expandafter}\expandafter
{\the\numexpr #2}\XINTdigits
}%
\def\XINT_flpowseriesx_opt [\xint_relax #1]#2#3%
{%
\expandafter\XINT_flpowseriesx\expandafter
{\the\numexpr #2\expandafter}\expandafter
{\the\numexpr #3\expandafter}{\the\numexpr #1}%
}%
\def\XINT_flpowseriesx #1#2#3#4#5%
{%
\ifnum #2<#1
\xint_afterfi { 0.e0}%
\else
\xint_afterfi
{\expandafter \XINT_flpowseriesx_pre \expandafter
{\romannumeral`&&@#5}{#1}{#2}{#4}{#3}%
}%
\fi
}%
\def\XINT_flpowseriesx_pre #1#2#3#4#5%
{%
\expandafter\XINT_flpowseries_loop_pre\expandafter
{\romannumeral0\XINTinfloatpow [#5]{#1}{#2}}%
{#2}{#1}{#3}{#4}{#5}%
}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintseries}
%
%\gardesactifs
%\let</xintseries>\relax
%\let<*xintcfrac>\gardesinactifs
%</xintseries>^^A-------------------------------------------------
%<*xintcfrac>^^A--------------------------------------------------
% \clearpage
% \section{Package \xintcfracnameimp implementation}
% \label{sec:cfracimp}
%
% \localtableofcontents
%
% The commenting is currently (\xintdocdate) very sparse. Release |1.09m|
% (|2014/02/26|) has modified a few things: |\xintFtoCs| and
% |\xintCntoCs| insert spaces after the commas, |\xintCstoF| and
% |\xintCstoCv| authorize spaces in the input also before the commas,
% |\xintCntoCs| does not brace the produced coefficients, new macros
% |\xintFtoC|, |\xintCtoF|, |\xintCtoCv|, |\xintFGtoC|, and
% |\xintGGCFrac|.
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\let\z\endgroup
\expandafter\let\expandafter\x\csname ver@xintcfrac.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintfrac.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintcfrac}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintcfrac.sty
\ifx\w\relax % but xintfrac.sty not yet loaded.
\def\z{\endgroup\input xintfrac.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintfrac.sty not yet loaded.
\def\z{\endgroup\RequirePackage{xintfrac}}%
\fi
\else
\aftergroup\endinput % xintcfrac already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes% defined in xintkernel.sty
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintcfrac}%
[2016/11/20 1.2h Expandable continued fractions with xint package (JFB)]%
% \end{macrocode}
% \subsection{\csh{xintCFrac}}
% \begin{macrocode}
\def\xintCFrac {\romannumeral0\xintcfrac }%
\def\xintcfrac #1%
{%
\XINT_cfrac_opt_a #1\xint_relax
}%
\def\XINT_cfrac_opt_a #1%
{%
\ifx[#1\XINT_cfrac_opt_b\fi \XINT_cfrac_noopt #1%
}%
\def\XINT_cfrac_noopt #1\xint_relax
{%
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z
\relax\relax
}%
\def\XINT_cfrac_opt_b\fi\XINT_cfrac_noopt [\xint_relax #1]%
{%
\fi\csname XINT_cfrac_opt#1\endcsname
}%
\def\XINT_cfrac_optl #1%
{%
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z
\relax\hfill
}%
\def\XINT_cfrac_optc #1%
{%
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z
\relax\relax
}%
\def\XINT_cfrac_optr #1%
{%
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z
\hfill\relax
}%
\def\XINT_cfrac_A #1/#2\Z
{%
\expandafter\XINT_cfrac_B\romannumeral0\xintiidivision {#1}{#2}{#2}%
}%
\def\XINT_cfrac_B #1#2%
{%
\XINT_cfrac_C #2\Z {#1}%
}%
\def\XINT_cfrac_C #1%
{%
\xint_gob_til_zero #1\XINT_cfrac_integer 0\XINT_cfrac_D #1%
}%
\def\XINT_cfrac_integer 0\XINT_cfrac_D 0#1\Z #2#3#4#5{ #2}%
\def\XINT_cfrac_D #1\Z #2#3{\XINT_cfrac_loop_a {#1}{#3}{#1}{{#2}}}%
\def\XINT_cfrac_loop_a
{%
\expandafter\XINT_cfrac_loop_d\romannumeral0\XINT_div_prepare
}%
\def\XINT_cfrac_loop_d #1#2%
{%
\XINT_cfrac_loop_e #2.{#1}%
}%
\def\XINT_cfrac_loop_e #1%
{%
\xint_gob_til_zero #1\xint_cfrac_loop_exit0\XINT_cfrac_loop_f #1%
}%
\def\XINT_cfrac_loop_f #1.#2#3#4%
{%
\XINT_cfrac_loop_a {#1}{#3}{#1}{{#2}#4}%
}%
\def\xint_cfrac_loop_exit0\XINT_cfrac_loop_f #1.#2#3#4#5#6%
{\XINT_cfrac_T #5#6{#2}#4\Z }%
\def\XINT_cfrac_T #1#2#3#4%
{%
\xint_gob_til_Z #4\XINT_cfrac_end\Z\XINT_cfrac_T #1#2{#4+\cfrac{#11#2}{#3}}%
}%
\def\XINT_cfrac_end\Z\XINT_cfrac_T #1#2#3%
{%
\XINT_cfrac_end_b #3%
}%
\def\XINT_cfrac_end_b \Z+\cfrac#1#2{ #2}%
% \end{macrocode}
% \subsection{\csh{xintGCFrac}}
% \begin{macrocode}
\def\xintGCFrac {\romannumeral0\xintgcfrac }%
\def\xintgcfrac #1{\XINT_gcfrac_opt_a #1\xint_relax }%
\def\XINT_gcfrac_opt_a #1%
{%
\ifx[#1\XINT_gcfrac_opt_b\fi \XINT_gcfrac_noopt #1%
}%
\def\XINT_gcfrac_noopt #1\xint_relax
{%
\XINT_gcfrac #1+\xint_relax/\relax\relax
}%
\def\XINT_gcfrac_opt_b\fi\XINT_gcfrac_noopt [\xint_relax #1]%
{%
\fi\csname XINT_gcfrac_opt#1\endcsname
}%
\def\XINT_gcfrac_optl #1%
{%
\XINT_gcfrac #1+\xint_relax/\relax\hfill
}%
\def\XINT_gcfrac_optc #1%
{%
\XINT_gcfrac #1+\xint_relax/\relax\relax
}%
\def\XINT_gcfrac_optr #1%
{%
\XINT_gcfrac #1+\xint_relax/\hfill\relax
}%
\def\XINT_gcfrac
{%
\expandafter\XINT_gcfrac_enter\romannumeral`&&@%
}%
\def\XINT_gcfrac_enter {\XINT_gcfrac_loop {}}%
\def\XINT_gcfrac_loop #1#2+#3/%
{%
\xint_gob_til_xint_relax #3\XINT_gcfrac_endloop\xint_relax
\XINT_gcfrac_loop {{#3}{#2}#1}%
}%
\def\XINT_gcfrac_endloop\xint_relax\XINT_gcfrac_loop #1#2#3%
{%
\XINT_gcfrac_T #2#3#1\xint_relax\xint_relax
}%
\def\XINT_gcfrac_T #1#2#3#4{\XINT_gcfrac_U #1#2{\xintFrac{#4}}}%
\def\XINT_gcfrac_U #1#2#3#4#5%
{%
\xint_gob_til_xint_relax #5\XINT_gcfrac_end\xint_relax\XINT_gcfrac_U
#1#2{\xintFrac{#5}%
\ifcase\xintSgn{#4}
+\or+\else-\fi
\cfrac{#1\xintFrac{\xintAbs{#4}}#2}{#3}}%
}%
\def\XINT_gcfrac_end\xint_relax\XINT_gcfrac_U #1#2#3%
{%
\XINT_gcfrac_end_b #3%
}%
\def\XINT_gcfrac_end_b #1\cfrac#2#3{ #3}%
% \end{macrocode}
% \subsection{\csh{xintGGCFrac}}
% \lverb|New with 1.09m|
% \begin{macrocode}
\def\xintGGCFrac {\romannumeral0\xintggcfrac }%
\def\xintggcfrac #1{\XINT_ggcfrac_opt_a #1\xint_relax }%
\def\XINT_ggcfrac_opt_a #1%
{%
\ifx[#1\XINT_ggcfrac_opt_b\fi \XINT_ggcfrac_noopt #1%
}%
\def\XINT_ggcfrac_noopt #1\xint_relax
{%
\XINT_ggcfrac #1+\xint_relax/\relax\relax
}%
\def\XINT_ggcfrac_opt_b\fi\XINT_ggcfrac_noopt [\xint_relax #1]%
{%
\fi\csname XINT_ggcfrac_opt#1\endcsname
}%
\def\XINT_ggcfrac_optl #1%
{%
\XINT_ggcfrac #1+\xint_relax/\relax\hfill
}%
\def\XINT_ggcfrac_optc #1%
{%
\XINT_ggcfrac #1+\xint_relax/\relax\relax
}%
\def\XINT_ggcfrac_optr #1%
{%
\XINT_ggcfrac #1+\xint_relax/\hfill\relax
}%
\def\XINT_ggcfrac
{%
\expandafter\XINT_ggcfrac_enter\romannumeral`&&@%
}%
\def\XINT_ggcfrac_enter {\XINT_ggcfrac_loop {}}%
\def\XINT_ggcfrac_loop #1#2+#3/%
{%
\xint_gob_til_xint_relax #3\XINT_ggcfrac_endloop\xint_relax
\XINT_ggcfrac_loop {{#3}{#2}#1}%
}%
\def\XINT_ggcfrac_endloop\xint_relax\XINT_ggcfrac_loop #1#2#3%
{%
\XINT_ggcfrac_T #2#3#1\xint_relax\xint_relax
}%
\def\XINT_ggcfrac_T #1#2#3#4{\XINT_ggcfrac_U #1#2{#4}}%
\def\XINT_ggcfrac_U #1#2#3#4#5%
{%
\xint_gob_til_xint_relax #5\XINT_ggcfrac_end\xint_relax\XINT_ggcfrac_U
#1#2{#5+\cfrac{#1#4#2}{#3}}%
}%
\def\XINT_ggcfrac_end\xint_relax\XINT_ggcfrac_U #1#2#3%
{%
\XINT_ggcfrac_end_b #3%
}%
\def\XINT_ggcfrac_end_b #1\cfrac#2#3{ #3}%
% \end{macrocode}
% \subsection{\csh{xintGCtoGCx}}
% \begin{macrocode}
\def\xintGCtoGCx {\romannumeral0\xintgctogcx }%
\def\xintgctogcx #1#2#3%
{%
\expandafter\XINT_gctgcx_start\expandafter {\romannumeral`&&@#3}{#1}{#2}%
}%
\def\XINT_gctgcx_start #1#2#3{\XINT_gctgcx_loop_a {}{#2}{#3}#1+\xint_relax/}%
\def\XINT_gctgcx_loop_a #1#2#3#4+#5/%
{%
\xint_gob_til_xint_relax #5\XINT_gctgcx_end\xint_relax
\XINT_gctgcx_loop_b {#1{#4}}{#2{#5}#3}{#2}{#3}%
}%
\def\XINT_gctgcx_loop_b #1#2%
{%
\XINT_gctgcx_loop_a {#1#2}%
}%
\def\XINT_gctgcx_end\xint_relax\XINT_gctgcx_loop_b #1#2#3#4{ #1}%
% \end{macrocode}
% \subsection{\csh{xintFtoCs}}
% \lverb|Modified in 1.09m: a space is added after the inserted commas.|
% \begin{macrocode}
\def\xintFtoCs {\romannumeral0\xintftocs }%
\def\xintftocs #1%
{%
\expandafter\XINT_ftc_A\romannumeral0\xintrawwithzeros {#1}\Z
}%
\def\XINT_ftc_A #1/#2\Z
{%
\expandafter\XINT_ftc_B\romannumeral0\xintiidivision {#1}{#2}{#2}%
}%
\def\XINT_ftc_B #1#2%
{%
\XINT_ftc_C #2.{#1}%
}%
\def\XINT_ftc_C #1%
{%
\xint_gob_til_zero #1\XINT_ftc_integer 0\XINT_ftc_D #1%
}%
\def\XINT_ftc_integer 0\XINT_ftc_D 0#1.#2#3{ #2}%
\def\XINT_ftc_D #1.#2#3{\XINT_ftc_loop_a {#1}{#3}{#1}{#2, }}% 1.09m adds a space
\def\XINT_ftc_loop_a
{%
\expandafter\XINT_ftc_loop_d\romannumeral0\XINT_div_prepare
}%
\def\XINT_ftc_loop_d #1#2%
{%
\XINT_ftc_loop_e #2.{#1}%
}%
\def\XINT_ftc_loop_e #1%
{%
\xint_gob_til_zero #1\xint_ftc_loop_exit0\XINT_ftc_loop_f #1%
}%
\def\XINT_ftc_loop_f #1.#2#3#4%
{%
\XINT_ftc_loop_a {#1}{#3}{#1}{#4#2, }% 1.09m has an added space here
}%
\def\xint_ftc_loop_exit0\XINT_ftc_loop_f #1.#2#3#4{ #4#2}%
% \end{macrocode}
% \subsection{\csh{xintFtoCx}}
% \begin{macrocode}
\def\xintFtoCx {\romannumeral0\xintftocx }%
\def\xintftocx #1#2%
{%
\expandafter\XINT_ftcx_A\romannumeral0\xintrawwithzeros {#2}\Z {#1}%
}%
\def\XINT_ftcx_A #1/#2\Z
{%
\expandafter\XINT_ftcx_B\romannumeral0\xintiidivision {#1}{#2}{#2}%
}%
\def\XINT_ftcx_B #1#2%
{%
\XINT_ftcx_C #2.{#1}%
}%
\def\XINT_ftcx_C #1%
{%
\xint_gob_til_zero #1\XINT_ftcx_integer 0\XINT_ftcx_D #1%
}%
\def\XINT_ftcx_integer 0\XINT_ftcx_D 0#1.#2#3#4{ #2}%
\def\XINT_ftcx_D #1.#2#3#4{\XINT_ftcx_loop_a {#1}{#3}{#1}{{#2}#4}{#4}}%
\def\XINT_ftcx_loop_a
{%
\expandafter\XINT_ftcx_loop_d\romannumeral0\XINT_div_prepare
}%
\def\XINT_ftcx_loop_d #1#2%
{%
\XINT_ftcx_loop_e #2.{#1}%
}%
\def\XINT_ftcx_loop_e #1%
{%
\xint_gob_til_zero #1\xint_ftcx_loop_exit0\XINT_ftcx_loop_f #1%
}%
\def\XINT_ftcx_loop_f #1.#2#3#4#5%
{%
\XINT_ftcx_loop_a {#1}{#3}{#1}{#4{#2}#5}{#5}%
}%
\def\xint_ftcx_loop_exit0\XINT_ftcx_loop_f #1.#2#3#4#5{ #4{#2}}%
% \end{macrocode}
% \subsection{\csh{xintFtoC}}
% \lverb|New in 1.09m: this is the same as \xintFtoCx with empty separator. I
% had temporarily during preparation of 1.09m removed braces from \xintFtoCx,
% but I recalled later why that was useful (see doc), thus let's just here do
% \xintFtoCx {}|
% \begin{macrocode}
\def\xintFtoC {\romannumeral0\xintftoc }%
\def\xintftoc {\xintftocx {}}%
% \end{macrocode}
% \subsection{\csh{xintFtoGC}}
% \begin{macrocode}
\def\xintFtoGC {\romannumeral0\xintftogc }%
\def\xintftogc {\xintftocx {+1/}}%
% \end{macrocode}
% \subsection{\csh{xintFGtoC}}
% \lverb|New with 1.09m of 2014/02/26. Computes the common initial coefficients
% for the two fractions f and g, and outputs them as a sequence of braced
% items.|
% \begin{macrocode}
\def\xintFGtoC {\romannumeral0\xintfgtoc}%
\def\xintfgtoc#1%
{%
\expandafter\XINT_fgtc_a\romannumeral0\xintrawwithzeros {#1}\Z
}%
\def\XINT_fgtc_a #1/#2\Z #3%
{%
\expandafter\XINT_fgtc_b\romannumeral0\xintrawwithzeros {#3}\Z #1/#2\Z { }%
}%
\def\XINT_fgtc_b #1/#2\Z
{%
\expandafter\XINT_fgtc_c\romannumeral0\xintiidivision {#1}{#2}{#2}%
}%
\def\XINT_fgtc_c #1#2#3#4/#5\Z
{%
\expandafter\XINT_fgtc_d\romannumeral0\xintiidivision
{#4}{#5}{#5}{#1}{#2}{#3}%
}%
\def\XINT_fgtc_d #1#2#3#4%#5#6#7%
{%
\xintifEq {#1}{#4}{\XINT_fgtc_da {#1}{#2}{#3}{#4}}%
{\xint_thirdofthree}%
}%
\def\XINT_fgtc_da #1#2#3#4#5#6#7%
{%
\XINT_fgtc_e {#2}{#5}{#3}{#6}{#7{#1}}%
}%
\def\XINT_fgtc_e #1%
{%
\xintifZero {#1}{\expandafter\xint_firstofone\xint_gobble_iii}%
{\XINT_fgtc_f {#1}}%
}%
\def\XINT_fgtc_f #1#2%
{%
\xintifZero {#2}{\xint_thirdofthree}{\XINT_fgtc_g {#1}{#2}}%
}%
\def\XINT_fgtc_g #1#2#3%
{%
\expandafter\XINT_fgtc_h\romannumeral0\XINT_div_prepare {#1}{#3}{#1}{#2}%
}%
\def\XINT_fgtc_h #1#2#3#4#5%
{%
\expandafter\XINT_fgtc_d\romannumeral0\XINT_div_prepare
{#4}{#5}{#4}{#1}{#2}{#3}%
}%
% \end{macrocode}
% \subsection{\csh{xintFtoCC}}
% \begin{macrocode}
\def\xintFtoCC {\romannumeral0\xintftocc }%
\def\xintftocc #1%
{%
\expandafter\XINT_ftcc_A\expandafter {\romannumeral0\xintrawwithzeros {#1}}%
}%
\def\XINT_ftcc_A #1%
{%
\expandafter\XINT_ftcc_B
\romannumeral0\xintrawwithzeros {\xintAdd {1/2[0]}{#1[0]}}\Z {#1[0]}%
}%
\def\XINT_ftcc_B #1/#2\Z
{%
\expandafter\XINT_ftcc_C\expandafter {\romannumeral0\xintiiquo {#1}{#2}}%
}%
\def\XINT_ftcc_C #1#2%
{%
\expandafter\XINT_ftcc_D\romannumeral0\xintsub {#2}{#1}\Z {#1}%
}%
\def\XINT_ftcc_D #1%
{%
\xint_UDzerominusfork
#1-\XINT_ftcc_integer
0#1\XINT_ftcc_En
0-{\XINT_ftcc_Ep #1}%
\krof
}%
\def\XINT_ftcc_Ep #1\Z #2%
{%
\expandafter\XINT_ftcc_loop_a\expandafter
{\romannumeral0\xintdiv {1[0]}{#1}}{#2+1/}%
}%
\def\XINT_ftcc_En #1\Z #2%
{%
\expandafter\XINT_ftcc_loop_a\expandafter
{\romannumeral0\xintdiv {1[0]}{#1}}{#2+-1/}%
}%
\def\XINT_ftcc_integer #1\Z #2{ #2}%
\def\XINT_ftcc_loop_a #1%
{%
\expandafter\XINT_ftcc_loop_b
\romannumeral0\xintrawwithzeros {\xintAdd {1/2[0]}{#1}}\Z {#1}%
}%
\def\XINT_ftcc_loop_b #1/#2\Z
{%
\expandafter\XINT_ftcc_loop_c\expandafter
{\romannumeral0\xintiiquo {#1}{#2}}%
}%
\def\XINT_ftcc_loop_c #1#2%
{%
\expandafter\XINT_ftcc_loop_d
\romannumeral0\xintsub {#2}{#1[0]}\Z {#1}%
}%
\def\XINT_ftcc_loop_d #1%
{%
\xint_UDzerominusfork
#1-\XINT_ftcc_end
0#1\XINT_ftcc_loop_N
0-{\XINT_ftcc_loop_P #1}%
\krof
}%
\def\XINT_ftcc_end #1\Z #2#3{ #3#2}%
\def\XINT_ftcc_loop_P #1\Z #2#3%
{%
\expandafter\XINT_ftcc_loop_a\expandafter
{\romannumeral0\xintdiv {1[0]}{#1}}{#3#2+1/}%
}%
\def\XINT_ftcc_loop_N #1\Z #2#3%
{%
\expandafter\XINT_ftcc_loop_a\expandafter
{\romannumeral0\xintdiv {1[0]}{#1}}{#3#2+-1/}%
}%
% \end{macrocode}
% \subsection{\csh{xintCtoF}, \csh{xintCstoF}}
% \lverb|1.09m uses \xintCSVtoList on the argument of \xintCstoF to allow
% spaces also before the commas. And the original \xintCstoF code became the
% one of the new \xintCtoF dealing with a braced rather than comma separated
% list.|
% \begin{macrocode}
\def\xintCstoF {\romannumeral0\xintcstof }%
\def\xintcstof #1%
{%
\expandafter\XINT_ctf_prep \romannumeral0\xintcsvtolist{#1}\xint_relax
}%
\def\xintCtoF {\romannumeral0\xintctof }%
\def\xintctof #1%
{%
\expandafter\XINT_ctf_prep \romannumeral`&&@#1\xint_relax
}%
\def\XINT_ctf_prep
{%
\XINT_ctf_loop_a 1001%
}%
\def\XINT_ctf_loop_a #1#2#3#4#5%
{%
\xint_gob_til_xint_relax #5\XINT_ctf_end\xint_relax
\expandafter\XINT_ctf_loop_b
\romannumeral0\xintrawwithzeros {#5}.{#1}{#2}{#3}{#4}%
}%
\def\XINT_ctf_loop_b #1/#2.#3#4#5#6%
{%
\expandafter\XINT_ctf_loop_c\expandafter
{\romannumeral0\XINT_mul_fork #2\Z #4\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #3\Z }%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #6\Z}{\XINT_mul_fork #1\Z #4\Z}}%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #5\Z}{\XINT_mul_fork #1\Z #3\Z}}%
}%
\def\XINT_ctf_loop_c #1#2%
{%
\expandafter\XINT_ctf_loop_d\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_ctf_loop_d #1#2%
{%
\expandafter\XINT_ctf_loop_e\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_ctf_loop_e #1#2%
{%
\expandafter\XINT_ctf_loop_a\expandafter{#2}#1%
}%
\def\XINT_ctf_end #1.#2#3#4#5{\xintrawwithzeros {#2/#3}}% 1.09b removes [0]
% \end{macrocode}
% \subsection{\csh{xintiCstoF}}
% \begin{macrocode}
\def\xintiCstoF {\romannumeral0\xinticstof }%
\def\xinticstof #1%
{%
\expandafter\XINT_icstf_prep \romannumeral`&&@#1,\xint_relax,%
}%
\def\XINT_icstf_prep
{%
\XINT_icstf_loop_a 1001%
}%
\def\XINT_icstf_loop_a #1#2#3#4#5,%
{%
\xint_gob_til_xint_relax #5\XINT_icstf_end\xint_relax
\expandafter
\XINT_icstf_loop_b \romannumeral`&&@#5.{#1}{#2}{#3}{#4}%
}%
\def\XINT_icstf_loop_b #1.#2#3#4#5%
{%
\expandafter\XINT_icstf_loop_c\expandafter
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\Z #3\Z}}%
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\Z #2\Z}}%
{#2}{#3}%
}%
\def\XINT_icstf_loop_c #1#2%
{%
\expandafter\XINT_icstf_loop_a\expandafter {#2}{#1}%
}%
\def\XINT_icstf_end#1.#2#3#4#5{\xintrawwithzeros {#2/#3}}% 1.09b removes [0]
% \end{macrocode}
% \subsection{\csh{xintGCtoF}}
% \begin{macrocode}
\def\xintGCtoF {\romannumeral0\xintgctof }%
\def\xintgctof #1%
{%
\expandafter\XINT_gctf_prep \romannumeral`&&@#1+\xint_relax/%
}%
\def\XINT_gctf_prep
{%
\XINT_gctf_loop_a 1001%
}%
\def\XINT_gctf_loop_a #1#2#3#4#5+%
{%
\expandafter\XINT_gctf_loop_b
\romannumeral0\xintrawwithzeros {#5}.{#1}{#2}{#3}{#4}%
}%
\def\XINT_gctf_loop_b #1/#2.#3#4#5#6%
{%
\expandafter\XINT_gctf_loop_c\expandafter
{\romannumeral0\XINT_mul_fork #2\Z #4\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #3\Z }%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #6\Z}{\XINT_mul_fork #1\Z #4\Z}}%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #5\Z}{\XINT_mul_fork #1\Z #3\Z}}%
}%
\def\XINT_gctf_loop_c #1#2%
{%
\expandafter\XINT_gctf_loop_d\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_gctf_loop_d #1#2%
{%
\expandafter\XINT_gctf_loop_e\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_gctf_loop_e #1#2%
{%
\expandafter\XINT_gctf_loop_f\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_gctf_loop_f #1#2/%
{%
\xint_gob_til_xint_relax #2\XINT_gctf_end\xint_relax
\expandafter\XINT_gctf_loop_g
\romannumeral0\xintrawwithzeros {#2}.#1%
}%
\def\XINT_gctf_loop_g #1/#2.#3#4#5#6%
{%
\expandafter\XINT_gctf_loop_h\expandafter
{\romannumeral0\XINT_mul_fork #1\Z #6\Z }%
{\romannumeral0\XINT_mul_fork #1\Z #5\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #4\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #3\Z }%
}%
\def\XINT_gctf_loop_h #1#2%
{%
\expandafter\XINT_gctf_loop_i\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_gctf_loop_i #1#2%
{%
\expandafter\XINT_gctf_loop_j\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_gctf_loop_j #1#2%
{%
\expandafter\XINT_gctf_loop_a\expandafter {#2}#1%
}%
\def\XINT_gctf_end #1.#2#3#4#5{\xintrawwithzeros {#2/#3}}% 1.09b removes [0]
% \end{macrocode}
% \subsection{\csh{xintiGCtoF}}
% \begin{macrocode}
\def\xintiGCtoF {\romannumeral0\xintigctof }%
\def\xintigctof #1%
{%
\expandafter\XINT_igctf_prep \romannumeral`&&@#1+\xint_relax/%
}%
\def\XINT_igctf_prep
{%
\XINT_igctf_loop_a 1001%
}%
\def\XINT_igctf_loop_a #1#2#3#4#5+%
{%
\expandafter\XINT_igctf_loop_b
\romannumeral`&&@#5.{#1}{#2}{#3}{#4}%
}%
\def\XINT_igctf_loop_b #1.#2#3#4#5%
{%
\expandafter\XINT_igctf_loop_c\expandafter
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\Z #3\Z}}%
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\Z #2\Z}}%
{#2}{#3}%
}%
\def\XINT_igctf_loop_c #1#2%
{%
\expandafter\XINT_igctf_loop_f\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_igctf_loop_f #1#2#3#4/%
{%
\xint_gob_til_xint_relax #4\XINT_igctf_end\xint_relax
\expandafter\XINT_igctf_loop_g
\romannumeral`&&@#4.{#2}{#3}#1%
}%
\def\XINT_igctf_loop_g #1.#2#3%
{%
\expandafter\XINT_igctf_loop_h\expandafter
{\romannumeral0\XINT_mul_fork #1\Z #3\Z }%
{\romannumeral0\XINT_mul_fork #1\Z #2\Z }%
}%
\def\XINT_igctf_loop_h #1#2%
{%
\expandafter\XINT_igctf_loop_i\expandafter {#2}{#1}%
}%
\def\XINT_igctf_loop_i #1#2#3#4%
{%
\XINT_igctf_loop_a {#3}{#4}{#1}{#2}%
}%
\def\XINT_igctf_end #1.#2#3#4#5{\xintrawwithzeros {#4/#5}}% 1.09b removes [0]
% \end{macrocode}
% \subsection{\csh{xintCtoCv}, \csh{xintCstoCv}}
% \lverb|1.09m uses \xintCSVtoList on the argument of \xintCstoCv to allow
% spaces also before the commas. The original \xintCstoCv code became the
% one of the new \xintCtoF dealing with a braced rather than comma separated
% list.|
% \begin{macrocode}
\def\xintCstoCv {\romannumeral0\xintcstocv }%
\def\xintcstocv #1%
{%
\expandafter\XINT_ctcv_prep\romannumeral0\xintcsvtolist{#1}\xint_relax
}%
\def\xintCtoCv {\romannumeral0\xintctocv }%
\def\xintctocv #1%
{%
\expandafter\XINT_ctcv_prep\romannumeral`&&@#1\xint_relax
}%
\def\XINT_ctcv_prep
{%
\XINT_ctcv_loop_a {}1001%
}%
\def\XINT_ctcv_loop_a #1#2#3#4#5#6%
{%
\xint_gob_til_xint_relax #6\XINT_ctcv_end\xint_relax
\expandafter\XINT_ctcv_loop_b
\romannumeral0\xintrawwithzeros {#6}.{#2}{#3}{#4}{#5}{#1}%
}%
\def\XINT_ctcv_loop_b #1/#2.#3#4#5#6%
{%
\expandafter\XINT_ctcv_loop_c\expandafter
{\romannumeral0\XINT_mul_fork #2\Z #4\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #3\Z }%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #6\Z}{\XINT_mul_fork #1\Z #4\Z}}%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #5\Z}{\XINT_mul_fork #1\Z #3\Z}}%
}%
\def\XINT_ctcv_loop_c #1#2%
{%
\expandafter\XINT_ctcv_loop_d\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_ctcv_loop_d #1#2%
{%
\expandafter\XINT_ctcv_loop_e\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_ctcv_loop_e #1#2%
{%
\expandafter\XINT_ctcv_loop_f\expandafter{#2}#1%
}%
\def\XINT_ctcv_loop_f #1#2#3#4#5%
{%
\expandafter\XINT_ctcv_loop_g\expandafter
{\romannumeral0\xintrawwithzeros {#1/#2}}{#5}{#1}{#2}{#3}{#4}%
}%
\def\XINT_ctcv_loop_g #1#2{\XINT_ctcv_loop_a {#2{#1}}}% 1.09b removes [0]
\def\XINT_ctcv_end #1.#2#3#4#5#6{ #6}%
% \end{macrocode}
% \subsection{\csh{xintiCstoCv}}
% \begin{macrocode}
\def\xintiCstoCv {\romannumeral0\xinticstocv }%
\def\xinticstocv #1%
{%
\expandafter\XINT_icstcv_prep \romannumeral`&&@#1,\xint_relax,%
}%
\def\XINT_icstcv_prep
{%
\XINT_icstcv_loop_a {}1001%
}%
\def\XINT_icstcv_loop_a #1#2#3#4#5#6,%
{%
\xint_gob_til_xint_relax #6\XINT_icstcv_end\xint_relax
\expandafter
\XINT_icstcv_loop_b \romannumeral`&&@#6.{#2}{#3}{#4}{#5}{#1}%
}%
\def\XINT_icstcv_loop_b #1.#2#3#4#5%
{%
\expandafter\XINT_icstcv_loop_c\expandafter
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\Z #3\Z}}%
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\Z #2\Z}}%
{{#2}{#3}}%
}%
\def\XINT_icstcv_loop_c #1#2%
{%
\expandafter\XINT_icstcv_loop_d\expandafter {#2}{#1}%
}%
\def\XINT_icstcv_loop_d #1#2%
{%
\expandafter\XINT_icstcv_loop_e\expandafter
{\romannumeral0\xintrawwithzeros {#1/#2}}{{#1}{#2}}%
}%
\def\XINT_icstcv_loop_e #1#2#3#4{\XINT_icstcv_loop_a {#4{#1}}#2#3}%
\def\XINT_icstcv_end #1.#2#3#4#5#6{ #6}% 1.09b removes [0]
% \end{macrocode}
% \subsection{\csh{xintGCtoCv}}
% \begin{macrocode}
\def\xintGCtoCv {\romannumeral0\xintgctocv }%
\def\xintgctocv #1%
{%
\expandafter\XINT_gctcv_prep \romannumeral`&&@#1+\xint_relax/%
}%
\def\XINT_gctcv_prep
{%
\XINT_gctcv_loop_a {}1001%
}%
\def\XINT_gctcv_loop_a #1#2#3#4#5#6+%
{%
\expandafter\XINT_gctcv_loop_b
\romannumeral0\xintrawwithzeros {#6}.{#2}{#3}{#4}{#5}{#1}%
}%
\def\XINT_gctcv_loop_b #1/#2.#3#4#5#6%
{%
\expandafter\XINT_gctcv_loop_c\expandafter
{\romannumeral0\XINT_mul_fork #2\Z #4\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #3\Z }%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #6\Z}{\XINT_mul_fork #1\Z #4\Z}}%
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\Z #5\Z}{\XINT_mul_fork #1\Z #3\Z}}%
}%
\def\XINT_gctcv_loop_c #1#2%
{%
\expandafter\XINT_gctcv_loop_d\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_gctcv_loop_d #1#2%
{%
\expandafter\XINT_gctcv_loop_e\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_gctcv_loop_e #1#2%
{%
\expandafter\XINT_gctcv_loop_f\expandafter {#2}#1%
}%
\def\XINT_gctcv_loop_f #1#2%
{%
\expandafter\XINT_gctcv_loop_g\expandafter
{\romannumeral0\xintrawwithzeros {#1/#2}}{{#1}{#2}}%
}%
\def\XINT_gctcv_loop_g #1#2#3#4%
{%
\XINT_gctcv_loop_h {#4{#1}}{#2#3}% 1.09b removes [0]
}%
\def\XINT_gctcv_loop_h #1#2#3/%
{%
\xint_gob_til_xint_relax #3\XINT_gctcv_end\xint_relax
\expandafter\XINT_gctcv_loop_i
\romannumeral0\xintrawwithzeros {#3}.#2{#1}%
}%
\def\XINT_gctcv_loop_i #1/#2.#3#4#5#6%
{%
\expandafter\XINT_gctcv_loop_j\expandafter
{\romannumeral0\XINT_mul_fork #1\Z #6\Z }%
{\romannumeral0\XINT_mul_fork #1\Z #5\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #4\Z }%
{\romannumeral0\XINT_mul_fork #2\Z #3\Z }%
}%
\def\XINT_gctcv_loop_j #1#2%
{%
\expandafter\XINT_gctcv_loop_k\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_gctcv_loop_k #1#2%
{%
\expandafter\XINT_gctcv_loop_l\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_gctcv_loop_l #1#2%
{%
\expandafter\XINT_gctcv_loop_m\expandafter {\expandafter{#2}#1}%
}%
\def\XINT_gctcv_loop_m #1#2{\XINT_gctcv_loop_a {#2}#1}%
\def\XINT_gctcv_end #1.#2#3#4#5#6{ #6}%
% \end{macrocode}
% \subsection{\csh{xintiGCtoCv}}
% \begin{macrocode}
\def\xintiGCtoCv {\romannumeral0\xintigctocv }%
\def\xintigctocv #1%
{%
\expandafter\XINT_igctcv_prep \romannumeral`&&@#1+\xint_relax/%
}%
\def\XINT_igctcv_prep
{%
\XINT_igctcv_loop_a {}1001%
}%
\def\XINT_igctcv_loop_a #1#2#3#4#5#6+%
{%
\expandafter\XINT_igctcv_loop_b
\romannumeral`&&@#6.{#2}{#3}{#4}{#5}{#1}%
}%
\def\XINT_igctcv_loop_b #1.#2#3#4#5%
{%
\expandafter\XINT_igctcv_loop_c\expandafter
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\Z #3\Z}}%
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\Z #2\Z}}%
{{#2}{#3}}%
}%
\def\XINT_igctcv_loop_c #1#2%
{%
\expandafter\XINT_igctcv_loop_f\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_igctcv_loop_f #1#2#3#4/%
{%
\xint_gob_til_xint_relax #4\XINT_igctcv_end_a\xint_relax
\expandafter\XINT_igctcv_loop_g
\romannumeral`&&@#4.#1#2{#3}%
}%
\def\XINT_igctcv_loop_g #1.#2#3#4#5%
{%
\expandafter\XINT_igctcv_loop_h\expandafter
{\romannumeral0\XINT_mul_fork #1\Z #5\Z }%
{\romannumeral0\XINT_mul_fork #1\Z #4\Z }%
{{#2}{#3}}%
}%
\def\XINT_igctcv_loop_h #1#2%
{%
\expandafter\XINT_igctcv_loop_i\expandafter {\expandafter{#2}{#1}}%
}%
\def\XINT_igctcv_loop_i #1#2{\XINT_igctcv_loop_k #2{#2#1}}%
\def\XINT_igctcv_loop_k #1#2%
{%
\expandafter\XINT_igctcv_loop_l\expandafter
{\romannumeral0\xintrawwithzeros {#1/#2}}%
}%
\def\XINT_igctcv_loop_l #1#2#3{\XINT_igctcv_loop_a {#3{#1}}#2}%1.09i removes [0]
\def\XINT_igctcv_end_a #1.#2#3#4#5%
{%
\expandafter\XINT_igctcv_end_b\expandafter
{\romannumeral0\xintrawwithzeros {#2/#3}}%
}%
\def\XINT_igctcv_end_b #1#2{ #2{#1}}% 1.09b removes [0]
% \end{macrocode}
% \subsection{\csh{xintFtoCv}}
% \lverb|Still uses \xinticstocv \xintFtoCs rather than \xintctocv \xintFtoC.|
% \begin{macrocode}
\def\xintFtoCv {\romannumeral0\xintftocv }%
\def\xintftocv #1%
{%
\xinticstocv {\xintFtoCs {#1}}%
}%
% \end{macrocode}
% \subsection{\csh{xintFtoCCv}}
% \begin{macrocode}
\def\xintFtoCCv {\romannumeral0\xintftoccv }%
\def\xintftoccv #1%
{%
\xintigctocv {\xintFtoCC {#1}}%
}%
% \end{macrocode}
% \subsection{\csh{xintCntoF}}
% \lverb|&
% Modified in 1.06 to give the N first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.|
% \begin{macrocode}
\def\xintCntoF {\romannumeral0\xintcntof }%
\def\xintcntof #1%
{%
\expandafter\XINT_cntf\expandafter {\the\numexpr #1}%
}%
\def\XINT_cntf #1#2%
{%
\ifnum #1>\xint_c_
\xint_afterfi {\expandafter\XINT_cntf_loop\expandafter
{\the\numexpr #1-1\expandafter}\expandafter
{\romannumeral`&&@#2{#1}}{#2}}%
\else
\xint_afterfi
{\ifnum #1=\xint_c_
\xint_afterfi {\expandafter\space \romannumeral`&&@#2{0}}%
\else \xint_afterfi { }% 1.09m now returns nothing.
\fi}%
\fi
}%
\def\XINT_cntf_loop #1#2#3%
{%
\ifnum #1>\xint_c_ \else \XINT_cntf_exit \fi
\expandafter\XINT_cntf_loop\expandafter
{\the\numexpr #1-1\expandafter }\expandafter
{\romannumeral0\xintadd {\xintDiv {1[0]}{#2}}{#3{#1}}}%
{#3}%
}%
\def\XINT_cntf_exit \fi
\expandafter\XINT_cntf_loop\expandafter
#1\expandafter #2#3%
{%
\fi\xint_gobble_ii #2%
}%
% \end{macrocode}
% \subsection{\csh{xintGCntoF}}
% \lverb|Modified in 1.06 to give the N argument first to a \numexpr rather
% than expanding twice. I just use \the\numexpr and maintain the previous code
% after that.|
% \begin{macrocode}
\def\xintGCntoF {\romannumeral0\xintgcntof }%
\def\xintgcntof #1%
{%
\expandafter\XINT_gcntf\expandafter {\the\numexpr #1}%
}%
\def\XINT_gcntf #1#2#3%
{%
\ifnum #1>\xint_c_
\xint_afterfi {\expandafter\XINT_gcntf_loop\expandafter
{\the\numexpr #1-1\expandafter}\expandafter
{\romannumeral`&&@#2{#1}}{#2}{#3}}%
\else
\xint_afterfi
{\ifnum #1=\xint_c_
\xint_afterfi {\expandafter\space\romannumeral`&&@#2{0}}%
\else \xint_afterfi { }% 1.09m now returns nothing rather than 0/1[0]
\fi}%
\fi
}%
\def\XINT_gcntf_loop #1#2#3#4%
{%
\ifnum #1>\xint_c_ \else \XINT_gcntf_exit \fi
\expandafter\XINT_gcntf_loop\expandafter
{\the\numexpr #1-1\expandafter }\expandafter
{\romannumeral0\xintadd {\xintDiv {#4{#1}}{#2}}{#3{#1}}}%
{#3}{#4}%
}%
\def\XINT_gcntf_exit \fi
\expandafter\XINT_gcntf_loop\expandafter
#1\expandafter #2#3#4%
{%
\fi\xint_gobble_ii #2%
}%
% \end{macrocode}
% \subsection{\csh{xintCntoCs}}
% \lverb|Modified in 1.09m: added spaces after the commas in the produced list.
% Moreover the coefficients are not braced anymore. A slight induced limitation
% is that the macro argument should not contain some explicit comma (cf.
% \XINT_cntcs_exit_b), hence \xintCntoCs {\macro,} with \def\macro,#1{<stuff>}
% would crash. Not a very serious limitation, I believe. |
% \begin{macrocode}
\def\xintCntoCs {\romannumeral0\xintcntocs }%
\def\xintcntocs #1%
{%
\expandafter\XINT_cntcs\expandafter {\the\numexpr #1}%
}%
\def\XINT_cntcs #1#2%
{%
\ifnum #1<0
\xint_afterfi { }% 1.09i: a 0/1[0] was here, now the macro returns nothing
\else
\xint_afterfi {\expandafter\XINT_cntcs_loop\expandafter
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter
{\romannumeral`&&@#2{#1}}{#2}}% produced coeff not braced
\fi
}%
\def\XINT_cntcs_loop #1#2#3%
{%
\ifnum #1>-\xint_c_i \else \XINT_cntcs_exit \fi
\expandafter\XINT_cntcs_loop\expandafter
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter
{\romannumeral`&&@#3{#1}, #2}{#3}% space added, 1.09m
}%
\def\XINT_cntcs_exit \fi
\expandafter\XINT_cntcs_loop\expandafter
#1\expandafter #2#3%
{%
\fi\XINT_cntcs_exit_b #2%
}%
\def\XINT_cntcs_exit_b #1,{}% romannumeral stopping space already there
% \end{macrocode}
% \subsection{\csh{xintCntoGC}}
% \lverb|&
% Modified in 1.06 to give the N first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.
%
% 1.09m maintains the braces, as the coeff are allowed to be fraction and the
% slash can not be naked in the GC format, contrarily to what happens in
% \xintCntoCs. Also the separators given to \xintGCtoGCx may then fetch the
% coefficients as argument, as they are braced.|
% \begin{macrocode}
\def\xintCntoGC {\romannumeral0\xintcntogc }%
\def\xintcntogc #1%
{%
\expandafter\XINT_cntgc\expandafter {\the\numexpr #1}%
}%
\def\XINT_cntgc #1#2%
{%
\ifnum #1<0
\xint_afterfi { }% 1.09i there was as strange 0/1[0] here, removed
\else
\xint_afterfi {\expandafter\XINT_cntgc_loop\expandafter
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter
{\expandafter{\romannumeral`&&@#2{#1}}}{#2}}%
\fi
}%
\def\XINT_cntgc_loop #1#2#3%
{%
\ifnum #1>-\xint_c_i \else \XINT_cntgc_exit \fi
\expandafter\XINT_cntgc_loop\expandafter
{\the\numexpr #1-\xint_c_i\expandafter }\expandafter
{\expandafter{\romannumeral`&&@#3{#1}}+1/#2}{#3}%
}%
\def\XINT_cntgc_exit \fi
\expandafter\XINT_cntgc_loop\expandafter
#1\expandafter #2#3%
{%
\fi\XINT_cntgc_exit_b #2%
}%
\def\XINT_cntgc_exit_b #1+1/{ }%
% \end{macrocode}
% \subsection{\csh{xintGCntoGC}}
% \lverb|&
% Modified in 1.06 to give the N first to a \numexpr rather than expanding
% twice. I just use \the\numexpr and maintain the previous code after that.|
% \begin{macrocode}
\def\xintGCntoGC {\romannumeral0\xintgcntogc }%
\def\xintgcntogc #1%
{%
\expandafter\XINT_gcntgc\expandafter {\the\numexpr #1}%
}%
\def\XINT_gcntgc #1#2#3%
{%
\ifnum #1<0
\xint_afterfi { }% 1.09i now returns nothing
\else
\xint_afterfi {\expandafter\XINT_gcntgc_loop\expandafter
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter
{\expandafter{\romannumeral`&&@#2{#1}}}{#2}{#3}}%
\fi
}%
\def\XINT_gcntgc_loop #1#2#3#4%
{%
\ifnum #1>-\xint_c_i \else \XINT_gcntgc_exit \fi
\expandafter\XINT_gcntgc_loop_b\expandafter
{\expandafter{\romannumeral`&&@#4{#1}}/#2}{#3{#1}}{#1}{#3}{#4}%
}%
\def\XINT_gcntgc_loop_b #1#2#3%
{%
\expandafter\XINT_gcntgc_loop\expandafter
{\the\numexpr #3-\xint_c_i \expandafter}\expandafter
{\expandafter{\romannumeral`&&@#2}+#1}%
}%
\def\XINT_gcntgc_exit \fi
\expandafter\XINT_gcntgc_loop_b\expandafter #1#2#3#4#5%
{%
\fi\XINT_gcntgc_exit_b #1%
}%
\def\XINT_gcntgc_exit_b #1/{ }%
% \end{macrocode}
% \subsection{\csh{xintCstoGC}}
% \begin{macrocode}
\def\xintCstoGC {\romannumeral0\xintcstogc }%
\def\xintcstogc #1%
{%
\expandafter\XINT_cstc_prep \romannumeral`&&@#1,\xint_relax,%
}%
\def\XINT_cstc_prep #1,{\XINT_cstc_loop_a {{#1}}}%
\def\XINT_cstc_loop_a #1#2,%
{%
\xint_gob_til_xint_relax #2\XINT_cstc_end\xint_relax
\XINT_cstc_loop_b {#1}{#2}%
}%
\def\XINT_cstc_loop_b #1#2{\XINT_cstc_loop_a {#1+1/{#2}}}%
\def\XINT_cstc_end\xint_relax\XINT_cstc_loop_b #1#2{ #1}%
% \end{macrocode}
% \subsection{\csh{xintGCtoGC}}
% \begin{macrocode}
\def\xintGCtoGC {\romannumeral0\xintgctogc }%
\def\xintgctogc #1%
{%
\expandafter\XINT_gctgc_start \romannumeral`&&@#1+\xint_relax/%
}%
\def\XINT_gctgc_start {\XINT_gctgc_loop_a {}}%
\def\XINT_gctgc_loop_a #1#2+#3/%
{%
\xint_gob_til_xint_relax #3\XINT_gctgc_end\xint_relax
\expandafter\XINT_gctgc_loop_b\expandafter
{\romannumeral`&&@#2}{#3}{#1}%
}%
\def\XINT_gctgc_loop_b #1#2%
{%
\expandafter\XINT_gctgc_loop_c\expandafter
{\romannumeral`&&@#2}{#1}%
}%
\def\XINT_gctgc_loop_c #1#2#3%
{%
\XINT_gctgc_loop_a {#3{#2}+{#1}/}%
}%
\def\XINT_gctgc_end\xint_relax\expandafter\XINT_gctgc_loop_b
{%
\expandafter\XINT_gctgc_end_b
}%
\def\XINT_gctgc_end_b #1#2#3{ #3{#1}}%
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintcfrac}
%
%\gardesactifs
%\let</xintcfrac>\relax
%\let<*xintexpr>\gardesinactifs
%</xintcfrac>^^A--------------------------------------------------
%<*xintexpr>^^A---------------------------------------------------
% \clearpage
% \section{Package \xintexprnameimp implementation}
% \label{sec:exprimp}
%
% \etocstandarddisplaystyle
% \etocstandardlines
% \etocsetnexttocdepth {subsection}
%
% \localtableofcontents
% \etocsettocstyle{}{}
%
% \etocmarkbothnouc {Package \xintexprnameimp implementation}
%
% This is release \expandafter|\xintbndlversion| of
% \expandafter|\expandafter[\xintbndldate]|.
%
% \subsection{Old comments}
%
% These general comments were last updated at the end of the |1.09x| series in
% 2014. The principles remain in place to this day but refer to
% \href{http://www.ctan.org/pkg/xint/CHANGES.html}{CHANGES.html} for some
% significant evolutions since.
%
% The first version was released in June 2013. I was greatly helped in this task
% of writing an expandable parser of infix operations by the comments provided
% in |l3fp-parse.dtx| (in its version as available in April-May 2013). One will
% recognize in particular the idea of the `until' macros; I have not looked into
% the actual |l3fp| code beyond the very useful comments provided in its
% documentation.
%
% A main worry was that my data has no a priori bound on its size; to keep the
% code reasonably efficient, I experimented with a technique of storing and
% retrieving data expandably as \emph{names} of control sequences. Intermediate
% computation results are stored as control sequences |\.=a/b[n]|.
%
%
% Roughly speaking, the parser mechanism is as follows: at any given time the
% last found ``operator'' has its associated |until| macro awaiting some news
% from the token flow; first |getnext| expands forward in the hope to construct
% some number, which may come from a parenthesized sub-expression, from some
% braced material, or from a digit by digit scan. After this number has been
% formed the next operator is looked for by the |getop| macro. Once |getop| has
% finished its job, |until| is presented with three tokens: the first one is the
% precedence level of the new found operator (which may be an end of expression
% marker), the second is the operator character token (earlier versions had here
% already some macro name, but in order to keep as much common code to expr and
% floatexpr common as possible, this was modified) of the new found operator, and
% the third one is the newly found number (which was encountered just before the
% new operator).
%
% The |until| macro of the earlier operator examines the precedence level of the
% new found one, and either executes the earlier operator (in the case of a
% binary operation, with the found number and a previously stored one) or it
% delays execution, giving the hand to the |until| macro of the operator having
% been found of higher precedence.
%
% A minus sign acting as prefix gets converted into a (unary) operator
% inheriting the precedence level of the previous operator.
%
% Once the end of the expression is found (it has to be marked by a |\relax|)
% the final result is output as four tokens (five tokens since |1.09j|) the
% first one a catcode 11 exclamation mark, the second one an error generating
% macro, the third one is a protection mechanism, the fourth one a printing
% macro and the fifth is |\.=a/b[n]|. The prefix |\xintthe| makes the output
% printable by killing the first three tokens.
%
%
% \subsection{Catcodes, \protect\eTeX{} and reload detection}
%
% The code for reload detection was initially copied from \textsc{Heiko
% Oberdiek}'s packages, then modified.
%
% The method for catcodes was also initially directly inspired by these
% packages.
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\catcode35=6 % #
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\def\z {\endgroup}%
\expandafter\let\expandafter\x\csname ver@xintexpr.sty\endcsname
\expandafter\let\expandafter\w\csname ver@xintfrac.sty\endcsname
\expandafter\let\expandafter\t\csname ver@xinttools.sty\endcsname
\expandafter
\ifx\csname PackageInfo\endcsname\relax
\def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}%
\else
\def\y#1#2{\PackageInfo{#1}{#2}}%
\fi
\expandafter
\ifx\csname numexpr\endcsname\relax
\y{xintexpr}{\numexpr not available, aborting input}%
\aftergroup\endinput
\else
\ifx\x\relax % plain-TeX, first loading of xintexpr.sty
\ifx\w\relax % but xintfrac.sty not yet loaded.
\expandafter\def\expandafter\z\expandafter
{\z\input xintfrac.sty\relax}%
\fi
\ifx\t\relax % but xinttools.sty not yet loaded.
\expandafter\def\expandafter\z\expandafter
{\z\input xinttools.sty\relax}%
\fi
\else
\def\empty {}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\ifx\w\relax % xintfrac.sty not yet loaded.
\expandafter\def\expandafter\z\expandafter
{\z\RequirePackage{xintfrac}}%
\fi
\ifx\t\relax % xinttools.sty not yet loaded.
\expandafter\def\expandafter\z\expandafter
{\z\RequirePackage{xinttools}}%
\fi
\else
\aftergroup\endinput % xintexpr already loaded.
\fi
\fi
\fi
\z%
\XINTsetupcatcodes%
% \end{macrocode}
% \subsection{Package identification}
% \begin{macrocode}
\XINT_providespackage
\ProvidesPackage{xintexpr}%
[2016/11/20 1.2h Expandable expression parser (JFB)]%
\catcode`! 11
% \end{macrocode}
% \subsection{Locking and unlocking}
% \lverb|Some renaming and modifications here with release 1.2 to switch from
% using chains of \romannumeral-`0 in order to gather numbers, possibly
% hexadecimals, to using a \csname governed expansion. In this way no more
% limit at 5000 digits, and besides this is a logical move because the
% \xintexpr parser is already based on \csname...\endcsname storage of numbers
% as one token.
%
% The limitation at 5000 digits didn't worry me too much because it was not
% very realistic to launch computations with thousands of digits... such
% computations are still slow with 1.2 but less so now. Chains or
% \romannumeral are still used for the gathering of function names and other
% stuff which I have half-forgotten because the parser does many things.
%
% In the earlier versions we used the lockscan macro after a chain of
% \romannumeral-`0 had ended gathering digits; this uses has been replaced by
% direct processing inside a \csname...\endcsname and the macro is kept only
% for matters of dummy variables.
%
% Currently, the parsing of hexadecimal numbers needs two nested
% \csname...\endcsname, first to gather the letters (possibly with a hexadecimal
% fractional part), and in a second stage to apply \xintHexToDec to do the
% actual conversion. This should be faster than updating on the fly the number
% (which would be hard for the fraction part...). The macro \xintHexToDec
% could probably be made faster by using techniques similar as the ones 1.2
% uses in xintcore.sty.|
% \begin{macrocode}
\def\xint_gob_til_! #1!{}% catcode 11 ! default in xintexpr.sty code.
\edef\XINT_expr_lockscan#1!% not used for decimal numbers in xintexpr 1.2
{\noexpand\expandafter\space\noexpand\csname .=#1\endcsname }%
\edef\XINT_expr_lockit
#1{\noexpand\expandafter\space\noexpand\csname .=#1\endcsname }%
\def\XINT_expr_unlock_hex_in #1% expanded inside \csname..\endcsname
{\expandafter\XINT_expr_inhex\romannumeral`&&@\XINT_expr_unlock#1;}%
\def\XINT_expr_inhex #1.#2#3;% expanded inside \csname..\endcsname
{%
\if#2>\xintHexToDec{#1}%
\else
\xintiiMul{\xintiiPow{625}{\xintLength{#3}}}{\xintHexToDec{#1#3}}%
[\the\numexpr-4*\xintLength{#3}]%
\fi
}%
\def\XINT_expr_unlock {\expandafter\XINT_expr_unlock_a\string }%
\def\XINT_expr_unlock_a #1.={}%
\def\XINT_expr_unexpectedtoken {\xintError:ignored }%
\let\XINT_expr_done\space
% \end{macrocode}
% \subsection{\csh{XINT_expr_wrap}, \csh{XINT_iiexpr_wrap}}
% \begin{macrocode}
\def\XINT_expr_wrap { !\XINT_expr_usethe\XINT_protectii\XINT_expr_print }%
\def\XINT_iiexpr_wrap { !\XINT_expr_usethe\XINT_protectii\XINT_iiexpr_print }%
% \end{macrocode}
% \subsection{\csh{XINT_protectii}, \csh{XINT_expr_usethe}}
% \begin{macrocode}
\def\XINT_protectii #1{\noexpand\XINT_protectii\noexpand #1\noexpand }%
\protected\def\XINT_expr_usethe\XINT_protectii {\xintError:missing_xintthe!}%
% \end{macrocode}
% \subsection{\csh{XINT_expr_print}, \csh{XINT_iiexpr_print}, \csh{XINT_boolexpr_print}}
% \lverb|See also the \XINT_flexpr_print which is special, below.|
% \begin{macrocode}
\def\XINT_expr_print #1{\xintSPRaw::csv {\XINT_expr_unlock #1}}%
\def\XINT_iiexpr_print #1{\xintCSV::csv {\XINT_expr_unlock #1}}%
\def\XINT_boolexpr_print #1{\xintIsTrue::csv {\XINT_expr_unlock #1}}%
% \end{macrocode}
% \subsection{\csh{xintexpr}, \csh{xintiexpr}, \csh{xintfloatexpr},
% \csh{xintiiexpr}}
% \begin{macrocode}
\def\xintexpr {\romannumeral0\xinteval }%
\def\xintiexpr {\romannumeral0\xintieval }%
\def\xintfloatexpr {\romannumeral0\xintfloateval }%
\def\xintiiexpr {\romannumeral0\xintiieval }%
% \end{macrocode}
% \subsection{\csh{xinttheexpr}, \csh{xinttheiexpr}, \csh{xintthefloatexpr},
% \csh{xinttheiiexpr}}
% \begin{macrocode}
\def\xinttheexpr
{\romannumeral`&&@\expandafter\XINT_expr_print\romannumeral0\xintbareeval }%
\def\xinttheiexpr {\romannumeral`&&@\xintthe\xintiexpr }%
\def\xintthefloatexpr {\romannumeral`&&@\xintthe\xintfloatexpr }%
\def\xinttheiiexpr
{\romannumeral`&&@\expandafter\XINT_iiexpr_print\romannumeral0\xintbareiieval }%
% \end{macrocode}
% \subsection{\csh{xintthe}}
% \begin{macrocode}
\def\xintthe #1{\romannumeral`&&@\expandafter\xint_gobble_iii\romannumeral`&&@#1}%
% \end{macrocode}
% \subsection{\csh{thexintexpr}, \csh{thexintiexpr}, \csh{thexintfloatexpr},
% \csh{thexintiiexpr}}
% \lverb|New with 1.2h. I have been three years long very strict in terms of
% prefixing macros, but well.|
% \begin{macrocode}
\let\thexintexpr \xinttheexpr
\let\thexintiexpr \xinttheiexpr
\let\thexintfloatexpr\xintthefloatexpr
\let\thexintiiexpr \xinttheiiexpr
% \end{macrocode}
% \subsection{\csh{xintthecoords}}
% \lverb|1.1 Wraps up an even number of comma separated items into pairs of
% TikZ coordinates; for use in the following way:
%
% coordinates {\xintthecoords\xintfloatexpr ... \relax}
%
% The crazyness with the \csname and unlock is due to TikZ somewhat STRANGE
% control of the TOTAL number of expansions which should not exceed the very low
% value of 100 !! As we implemented \XINT_thecoords_b in an "inline" style for
% efficiency, we need to hide its expansions.
%
% Not to be used as \xintthecoords\xintthefloatexpr, only as
% \xintthecoords\xintfloatexpr (or \xintiexpr etc...). Perhaps \xintthecoords
% could make an extra check, but one should not accustom users to too loose
% requirements!|
% \begin{macrocode}
\def\xintthecoords #1{\romannumeral`&&@\expandafter\expandafter\expandafter
\XINT_thecoords_a
\expandafter\xint_gobble_iii\romannumeral0#1}%
\def\XINT_thecoords_a #1#2% #1=print macro, indispensible for scientific notation
{\expandafter\XINT_expr_unlock\csname.=\expandafter\XINT_thecoords_b
\romannumeral`&&@#1#2,!,!,^\endcsname }%
\def\XINT_thecoords_b #1#2,#3#4,%
{\xint_gob_til_! #3\XINT_thecoords_c ! (#1#2, #3#4)\XINT_thecoords_b }%
\def\XINT_thecoords_c #1^{}%
% \end{macrocode}
% \subsection{\csh{xintbareeval}, \csh{xintbarefloateval}, \csh{xintbareiieval}}
% \begin{macrocode}
\def\xintbareeval
{\expandafter\XINT_expr_until_end_a\romannumeral`&&@\XINT_expr_getnext }%
\def\xintbarefloateval
{\expandafter\XINT_flexpr_until_end_a\romannumeral`&&@\XINT_expr_getnext }%
\def\xintbareiieval
{\expandafter\XINT_iiexpr_until_end_a\romannumeral`&&@\XINT_expr_getnext }%
% \end{macrocode}
% \subsection{\csh{xintthebareeval}, \csh{xintthebarefloateval}, \csh{xintthebareiieval}}
% \begin{macrocode}
\def\xintthebareeval {\expandafter\XINT_expr_unlock\romannumeral0\xintbareeval}%
\def\xintthebarefloateval {\expandafter\XINT_expr_unlock\romannumeral0\xintbarefloateval}%
\def\xintthebareiieval {\expandafter\XINT_expr_unlock\romannumeral0\xintbareiieval}%
% \end{macrocode}
% \subsection{\csh{xinteval}, \csh{xintiieval}}
% \begin{macrocode}
\def\xinteval {\expandafter\XINT_expr_wrap\romannumeral0\xintbareeval }%
\def\xintiieval {\expandafter\XINT_iiexpr_wrap\romannumeral0\xintbareiieval }%
% \end{macrocode}
% \subsection{\csh{xintieval}, \csh{XINT_iexpr_wrap}}
% \lverb|Optional argument since 1.1.|
% \begin{macrocode}
\def\xintieval #1%
{\ifx [#1\expandafter\XINT_iexpr_withopt\else\expandafter\XINT_iexpr_noopt \fi #1}%
\def\XINT_iexpr_noopt
{\expandafter\XINT_iexpr_wrap \expandafter 0\romannumeral0\xintbareeval }%
\def\XINT_iexpr_withopt [#1]%
{%
\expandafter\XINT_iexpr_wrap\expandafter
{\the\numexpr \xint_zapspaces #1 \xint_gobble_i\expandafter}%
\romannumeral0\xintbareeval
}%
\def\XINT_iexpr_wrap #1#2%
{%
\expandafter\XINT_expr_wrap
\csname .=\xintRound::csv {#1}{\XINT_expr_unlock #2}\endcsname
}%
% \end{macrocode}
% \subsection{\csh{xintfloateval}, \csh{XINT_flexpr_wrap}, \csh{XINT_flexpr_print}}
% \lverb|Optional argument since 1.1|
% \begin{macrocode}
\def\xintfloateval #1%
{%
\ifx [#1\expandafter\XINT_flexpr_withopt_a\else\expandafter\XINT_flexpr_noopt
\fi #1%
}%
\def\XINT_flexpr_noopt
{%
\expandafter\XINT_flexpr_withopt_b\expandafter\xinttheDigits
\romannumeral0\xintbarefloateval
}%
\def\XINT_flexpr_withopt_a [#1]%
{%
\expandafter\XINT_flexpr_withopt_b\expandafter
{\the\numexpr\xint_zapspaces #1 \xint_gobble_i\expandafter}%
\romannumeral0\xintbarefloateval
}%
\def\XINT_flexpr_withopt_b #1#2%
{%
\expandafter\XINT_flexpr_wrap\csname .;#1.=% ; and not : as before b'cause NewExpr
\XINTinFloat::csv {#1}{\XINT_expr_unlock #2}\endcsname
}%
\def\XINT_flexpr_wrap { !\XINT_expr_usethe\XINT_protectii\XINT_flexpr_print }%
\def\XINT_flexpr_print #1%
{%
\expandafter\xintPFloat::csv
\romannumeral`&&@\expandafter\XINT_expr_unlock_sp\string #1!%
}%
\catcode`: 12
\def\XINT_expr_unlock_sp #1.;#2.=#3!{{#2}{#3}}%
\catcode`: 11
% \end{macrocode}
% \subsection{\csh{xintboolexpr}, \csh{xinttheboolexpr}, \csh{thexintboolexpr}}
% \begin{macrocode}
\def\xintboolexpr {\romannumeral0\expandafter\expandafter\expandafter
\XINT_boolexpr_done \expandafter\xint_gobble_iv\romannumeral0\xinteval }%
\def\xinttheboolexpr {\romannumeral`&&@\expandafter\expandafter\expandafter
\XINT_boolexpr_print\expandafter\xint_gobble_iv\romannumeral0\xinteval }%
\let\thexintboolexpr\xinttheboolexpr
\def\XINT_boolexpr_done { !\XINT_expr_usethe\XINT_protectii\XINT_boolexpr_print }%
% \end{macrocode}
% \subsection{\csh{xintifboolexpr}, \csh{xintifboolfloatexpr}, \csh{xintifbooliiexpr}}
% \lverb|Do not work with comma separated expressions.|
% \begin{macrocode}
\def\xintifboolexpr #1{\romannumeral0\xintifnotzero {\xinttheexpr #1\relax}}%
\def\xintifboolfloatexpr #1{\romannumeral0\xintifnotzero {\xintthefloatexpr #1\relax}}%
\def\xintifbooliiexpr #1{\romannumeral0\xintifnotzero {\xinttheiiexpr #1\relax}}%
% \end{macrocode}
% \subsection{Macros handling csv lists on output (for \csh{XINT_expr_print} et
% al. routines)}
% \localtableofcontents
% \lverb|Changed completely for 1.1, which adds the optional arguments to
% \xintiexpr and \xintfloatexpr.|
% \subsubsection{\csh{XINT_::_end}}
% \lverb|Le mécanisme est le suivant, #2 est dans des accolades et commence par
% ,<sp>. Donc le gobble se débarrasse du, et le <sp> après brace stripping
% arrête un \romannumeral0 ou \romannumeral-`0|
% \begin{macrocode}
\def\XINT_::_end #1,#2{\xint_gobble_i #2}%
% \end{macrocode}
% \subsubsection{\csh{xintCSV::csv}}
% \begin{macrocode}
\def\xintCSV::csv #1{\expandafter\XINT_csv::_a\romannumeral`&&@#1,^,}%
\def\XINT_csv::_a {\XINT_csv::_b {}}%
\def\XINT_csv::_b #1#2,{\expandafter\XINT_csv::_c \romannumeral`&&@#2,{#1}}%
\def\XINT_csv::_c #1{\if ^#1\expandafter\XINT_::_end\fi\XINT_csv::_d #1}%
\def\XINT_csv::_d #1,#2{\XINT_csv::_b {#2, #1}}% possibly, item #1 is empty.
% \end{macrocode}
% \subsubsection{\csh{xintSPRaw}, \csh{xintSPRaw::csv}}
% \begin{macrocode}
\def\xintSPRaw {\romannumeral0\xintspraw }%
\def\xintspraw #1{\expandafter\XINT_spraw\romannumeral`&&@#1[\W]}%
\def\XINT_spraw #1[#2#3]{\xint_gob_til_W #2\XINT_spraw_a\W\XINT_spraw_p #1[#2#3]}%
\def\XINT_spraw_a\W\XINT_spraw_p #1[\W]{ #1}%
\def\XINT_spraw_p #1[\W]{\xintpraw {#1}}%
\def\xintSPRaw::csv #1{\romannumeral0\expandafter\XINT_spraw::_a\romannumeral`&&@#1,^,}%
\def\XINT_spraw::_a {\XINT_spraw::_b {}}%
\def\XINT_spraw::_b #1#2,{\expandafter\XINT_spraw::_c \romannumeral`&&@#2,{#1}}%
\def\XINT_spraw::_c #1{\if ,#1\xint_dothis\XINT_spraw::_e\fi
\if ^#1\xint_dothis\XINT_::_end\fi
\xint_orthat\XINT_spraw::_d #1}%
\def\XINT_spraw::_d #1,{\expandafter\XINT_spraw::_e\romannumeral0\XINT_spraw #1[\W],}%
\def\XINT_spraw::_e #1,#2{\XINT_spraw::_b {#2, #1}}%
% \end{macrocode}
% \subsubsection{\csh{xintIsTrue::csv}}
% \begin{macrocode}
\def\xintIsTrue::csv #1{\romannumeral0\expandafter\XINT_istrue::_a\romannumeral`&&@#1,^,}%
\def\XINT_istrue::_a {\XINT_istrue::_b {}}%
\def\XINT_istrue::_b #1#2,{\expandafter\XINT_istrue::_c \romannumeral`&&@#2,{#1}}%
\def\XINT_istrue::_c #1{\if ,#1\xint_dothis\XINT_istrue::_e\fi
\if ^#1\xint_dothis\XINT_::_end\fi
\xint_orthat\XINT_istrue::_d #1}%
\def\XINT_istrue::_d #1,{\expandafter\XINT_istrue::_e\romannumeral0\xintisnotzero {#1},}%
\def\XINT_istrue::_e #1,#2{\XINT_istrue::_b {#2, #1}}%
% \end{macrocode}
% \subsubsection{\csh{xintRound::csv}}
% \begin{macrocode}
\def\XINT_:::_end #1,#2#3{\xint_gobble_i #3}%
\def\xintRound::csv #1#2{\romannumeral0\expandafter\XINT_round::_b\expandafter
{\the\numexpr#1\expandafter}\expandafter{\expandafter}\romannumeral`&&@#2,^,}%
\def\XINT_round::_b #1#2#3,{\expandafter\XINT_round::_c \romannumeral`&&@#3,{#1}{#2}}%
\def\XINT_round::_c #1{\if ,#1\xint_dothis\XINT_round::_e\fi
\if ^#1\xint_dothis\XINT_:::_end\fi
\xint_orthat\XINT_round::_d #1}%
\def\XINT_round::_d #1,#2{%
\expandafter\XINT_round::_e\romannumeral0\ifnum#2>\xint_c_
\expandafter\xintround\else\expandafter\xintiround\fi {#2}{#1},{#2}}%
\def\XINT_round::_e #1,#2#3{\XINT_round::_b {#2}{#3, #1}}%
% \end{macrocode}
% \subsubsection{\csh{XINTinFloat::csv}}
% \begin{macrocode}
\def\XINTinFloat::csv #1#2{\romannumeral0\expandafter\XINT_infloat::_b\expandafter
{\the\numexpr #1\expandafter}\expandafter{\expandafter}\romannumeral`&&@#2,^,}%
\def\XINT_infloat::_b #1#2#3,{\XINT_infloat::_c #3,{#1}{#2}}%
\def\XINT_infloat::_c #1{\if ,#1\xint_dothis\XINT_infloat::_e\fi
\if ^#1\xint_dothis\XINT_:::_end\fi
\xint_orthat\XINT_infloat::_d #1}%
\def\XINT_infloat::_d #1,#2%
{\expandafter\XINT_infloat::_e\romannumeral0\XINTinfloat [#2]{#1},{#2}}%
\def\XINT_infloat::_e #1,#2#3{\XINT_infloat::_b {#2}{#3, #1}}%
% \end{macrocode}
% \subsubsection{\csh{xintPFloat::csv}}
% \begin{macrocode}
\def\xintPFloat::csv #1#2{\romannumeral0\expandafter\XINT_pfloat::_b\expandafter
{\the\numexpr #1\expandafter}\expandafter{\expandafter}\romannumeral`&&@#2,^,}%
\def\XINT_pfloat::_b #1#2#3,{\expandafter\XINT_pfloat::_c \romannumeral`&&@#3,{#1}{#2}}%
\def\XINT_pfloat::_c #1{\if ,#1\xint_dothis\XINT_pfloat::_e\fi
\if ^#1\xint_dothis\XINT_:::_end\fi
\xint_orthat\XINT_pfloat::_d #1}%
\def\XINT_pfloat::_d #1,#2%
{\expandafter\XINT_pfloat::_e\romannumeral0\XINT_pfloat_opt [\xint_relax #2]{#1},{#2}}%
\def\XINT_pfloat::_e #1,#2#3{\XINT_pfloat::_b {#2}{#3, #1}}%
% \end{macrocode}
% \subsection{\csh{XINT_expr_getnext}: fetching some number then an operator}
% \lverb|Big change in 1.1, no attempt to detect braced stuff anymore as the
% [N] notation is implemented otherwise. Now, braces should not be used at
% all; one level removed, then \romannumeral-`0 expansion.|
% \begin{macrocode}
\def\XINT_expr_getnext #1%
{%
\expandafter\XINT_expr_getnext_a\romannumeral`&&@#1%
}%
\def\XINT_expr_getnext_a #1%
{% screens out sub-expressions and \count or \dimen registers/variables
\xint_gob_til_! #1\XINT_expr_subexpr !% recall this ! has catcode 11
\ifcat\relax#1% \count or \numexpr etc... token or count, dimen, skip cs
\expandafter\XINT_expr_countetc
\else
\expandafter\expandafter\expandafter\XINT_expr_getnextfork\expandafter\string
\fi
#1%
}%
\def\XINT_expr_subexpr !#1\fi !{\expandafter\XINT_expr_getop\xint_gobble_iii }%
% \end{macrocode}
% \lverb|1.2 adds \ht, \dp, \wd and the eTeX font things.|
% \begin{macrocode}
\def\XINT_expr_countetc #1%
{%
\ifx\count#1\else\ifx\dimen#1\else\ifx\numexpr#1\else\ifx\dimexpr#1\else
\ifx\skip#1\else\ifx\glueexpr#1\else\ifx\fontdimen#1\else\ifx\ht#1\else
\ifx\dp#1\else\ifx\wd#1\else\ifx\fontcharht#1\else\ifx\fontcharwd#1\else
\ifx\fontchardp#1\else\ifx\fontcharic#1\else
\XINT_expr_unpackvar
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\expandafter\XINT_expr_getnext\number #1%
}%
\def\XINT_expr_unpackvar\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\expandafter\XINT_expr_getnext\number #1%
{\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\expandafter\XINT_expr_getop\csname .=\number#1\endcsname }%
\begingroup
\lccode`*=`#
\lowercase{\endgroup
\def\XINT_expr_getnextfork #1{%
\if#1*\xint_dothis {\XINT_expr_scan_macropar *}\fi
\if#1[\xint_dothis {\xint_c_xviii ({}}\fi
\if#1+\xint_dothis \XINT_expr_getnext \fi
\if#1.\xint_dothis {\XINT_expr_startdec}\fi
\if#1-\xint_dothis -\fi
\if#1(\xint_dothis {\xint_c_xviii ({}}\fi
\xint_orthat {\XINT_expr_scan_nbr_or_func #1}%
}}%
\def\XINT_expr_scan_macropar #1#2{\expandafter\XINT_expr_getop\csname .=#1#2\endcsname }%
% \end{macrocode}
% \subsection{The integer or decimal number or hexa-decimal number or
% function name or variable name or special hacky things big parser}
% \localtableofcontents
% \lverb@1.2 release has replaced chains of \romannumeral-`0 by \csname
% governed expansion. Thus there is no more the limit at about 5000 digits for
% parsed numbers.
%
% In order to avoid having to lock and unlock in succession to handle the
% scientific part and adjust the exponent according to the number of digits of
% the decimal part, the parsing of this decimal part counts on the fly the
% number of digits it encounters.
%
% There is some slight annoyance with \xintiiexpr which should never be given
% a [n] inside its \csname.=<digits>\endcsname storage of numbers (because its
% arithmetic uses the ii macros which know nothing about the [N] notation).
% Hence if the parser has only seen digits when hitting something else than
% the dot or e (or E), it will not insert a [0]. Thus we very slightly
% compromise the efficiency of \xintexpr and \xintfloatexpr in order to be
% able to share the same code with \xintiiexpr.
%
% Indeed, the parser at this location is completely common to all, it does not
% know if it is working inside \xintexpr or \xintiiexpr. On the other hand if
% a dot or a e (or E) is met, then the (common) parser has no scrupules ending
% this number with a [n], this will provoke an error later if that was within
% an \xintiiexpr, as soon as an arithmetic macro is used.
%
% As the gathered numbers have no spaces, no pluses, no minuses, the only
% remaining issue is with leading zeroes, which are discarded on the fly. The
% hexadecimal numbers leading zeroes are stripped in a second stage by the
% \xintHexToDec macro.
%
% With 1.2, \xinttheexpr . \relax does not work anymore (it did in earlier
% releases). There must be digits either before or after the decimal mark. Thus
% both \xinttheexpr 1.\relax and \xinttheexpr .1\relax are legal.
%
% The ` syntax is here used for special constructs like `+`(..), `*`(..) where
% + or * will be treated as functions. Current implementation pick only one
% token (could have been braced stuff), thus here it will be + or *, and via
% \XINT_expr_op_` this into becomes a suitable
% \XINT_{expr|iiexpr|flexpr}_func_+ (or *). Documentation of 1.1 said to use
% `+`(...), but `+(...) is also valid. The opening parenthesis must be there,
% it is not allowed to come from expansion.@
% \begin{macrocode}
\catcode96 11 % `
\def\XINT_expr_scan_nbr_or_func #1% this #1 has necessarily here catcode 12
{%
\if "#1\xint_dothis \XINT_expr_scanhex_I\fi
\if `#1\xint_dothis {\XINT_expr_onlitteral_`}\fi
\ifnum \xint_c_ix<1#1 \xint_dothis \XINT_expr_startint\fi
\xint_orthat \XINT_expr_scanfunc #1%
}%
\def\XINT_expr_onlitteral_` #1#2#3({\xint_c_xviii `{#2}}%
\catcode96 12 % `
\def\XINT_expr_startint #1%
{%
\if #10\expandafter\XINT_expr_gobz_a\else\XINT_expr_scanint_a\fi #1%
}%
\def\XINT_expr_scanint_a #1#2%
{\expandafter\XINT_expr_getop\csname.=#1%
\expandafter\XINT_expr_scanint_b\romannumeral`&&@#2}%
\def\XINT_expr_gobz_a #1%
{\expandafter\XINT_expr_getop\csname.=%
\expandafter\XINT_expr_gobz_scanint_b\romannumeral`&&@#1}%
\def\XINT_expr_startdec #1%
{\expandafter\XINT_expr_getop\csname.=%
\expandafter\XINT_expr_scandec_a\romannumeral`&&@#1}%
% \end{macrocode}
% \subsubsection{Integral part (skipping zeroes)}
% \lverb|1.2 has modified the code to give highest priority to digits, the
% accelerating impact is non-negligeable. I don't think the doubled \string is
% a serious penalty.|
% \begin{macrocode}
\def\XINT_expr_scanint_b #1%
{%
\ifcat \relax #1\expandafter\XINT_expr_scanint_endbycs\expandafter #1\fi
\ifnum\xint_c_ix<1\string#1 \else\expandafter\XINT_expr_scanint_c\fi
\string#1\XINT_expr_scanint_d
}%
\def\XINT_expr_scanint_d #1%
{%
\expandafter\XINT_expr_scanint_b\romannumeral`&&@#1%
}%
\def\XINT_expr_scanint_endbycs#1#2\XINT_expr_scanint_d{\endcsname #1}%
% \end{macrocode}
% \lverb|With 1.2d the tacit multiplication in front of a variable name or
% function name is now done with a higher precedence, intermediate between the
% common one of * and / and the one of ^. Thus x/2y is like x/(2y), but x^2y
% is like x^2*y and 2y! is not (2y)! but 2*y!.
%
% Finally, 1.2d has moved away from the _scan macros all the business of the
% tacit multiplication in one unique place via \XINT_expr_getop. For this, the
% ending token is not first given to \string as was done earlier before
% handing over back control to \XINT_expr_getop. Earlier we had to identify
% the catcode 11 ! signaling a sub-expression here. With no \string applied
% we can do it in \XINT_expr_getop. As a corollary of this displacement,
% parsing of big numbers should be a tiny bit faster now.|
% \begin{macrocode}
\def\XINT_expr_scanint_c\string #1\XINT_expr_scanint_d
{%
\if e#1\xint_dothis{[\the\numexpr0\XINT_expr_scanexp_a +}\fi
\if E#1\xint_dothis{[\the\numexpr0\XINT_expr_scanexp_a +}\fi
\if .#1\xint_dothis{\XINT_expr_startdec_a .}\fi
\xint_orthat {\endcsname #1}%
}%
\def\XINT_expr_startdec_a .#1%
{%
\expandafter\XINT_expr_scandec_a\romannumeral`&&@#1%
}%
\def\XINT_expr_scandec_a #1%
{%
\if .#1\xint_dothis{\endcsname..}\fi
\xint_orthat {\XINT_expr_scandec_b 0.#1}%
}%
\def\XINT_expr_gobz_scanint_b #1%
{%
\ifcat \relax #1\expandafter\XINT_expr_gobz_scanint_endbycs\expandafter #1\fi
\ifnum\xint_c_x<1\string#1 \else\expandafter\XINT_expr_gobz_scanint_c\fi
\string#1\XINT_expr_scanint_d
}%
\def\XINT_expr_gobz_scanint_endbycs#1#2\XINT_expr_scanint_d{0\endcsname #1}%
\def\XINT_expr_gobz_scanint_c\string #1\XINT_expr_scanint_d
{%
\if e#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi
\if E#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi
\if .#1\xint_dothis{\XINT_expr_gobz_startdec_a .}\fi
\if 0#1\xint_dothis\XINT_expr_gobz_scanint_d\fi
\xint_orthat {0\endcsname #1}%
}%
\def\XINT_expr_gobz_scanint_d #1%
{%
\expandafter\XINT_expr_gobz_scanint_b\romannumeral`&&@#1%
}%
\def\XINT_expr_gobz_startdec_a .#1%
{%
\expandafter\XINT_expr_gobz_scandec_a\romannumeral`&&@#1%
}%
\def\XINT_expr_gobz_scandec_a #1%
{%
\if .#1\xint_dothis{0\endcsname..}\fi
\xint_orthat {\XINT_expr_gobz_scandec_b 0.#1}%
}%
% \end{macrocode}
% \subsubsection{Fractional part}
% \lverb|Annoying duplication of code to allow 0. as input.
%
% 1.2a corrects a very bad bug in 1.2 \XINT_expr_gobz_scandec_b which should
% have stripped leading zeroes in the fractional part but didn't; as a result
% \xinttheexpr 0.01\relax returned 0 =:-((( Thanks to Kroum Tzanev who
% reported the issue. Does it improve things if I say the bug was introduced
% in 1.2, it wasn't present before ?|
% \begin{macrocode}
\def\XINT_expr_scandec_b #1.#2%
{%
\ifcat \relax #2\expandafter\XINT_expr_scandec_endbycs\expandafter#2\fi
\ifnum\xint_c_ix<1\string#2 \else\expandafter\XINT_expr_scandec_c\fi
\string#2\expandafter\XINT_expr_scandec_d\the\numexpr #1-\xint_c_i.%
}%
\def\XINT_expr_scandec_endbycs #1#2\XINT_expr_scandec_d
\the\numexpr#3-\xint_c_i.{[#3]\endcsname #1}%
\def\XINT_expr_scandec_d #1.#2%
{%
\expandafter\XINT_expr_scandec_b
\the\numexpr #1\expandafter.\romannumeral`&&@#2%
}%
\def\XINT_expr_scandec_c\string #1#2\the\numexpr#3-\xint_c_i.%
{%
\if e#1\xint_dothis{[\the\numexpr#3\XINT_expr_scanexp_a +}\fi
\if E#1\xint_dothis{[\the\numexpr#3\XINT_expr_scanexp_a +}\fi
\xint_orthat {[#3]\endcsname #1}%
}%
\def\XINT_expr_gobz_scandec_b #1.#2%
{%
\ifcat \relax #2\expandafter\XINT_expr_gobz_scandec_endbycs\expandafter#2\fi
\ifnum\xint_c_ix<1\string#2 \else\expandafter\XINT_expr_gobz_scandec_c\fi
\if0#2\expandafter\xint_firstoftwo\else\expandafter\xint_secondoftwo\fi
{\expandafter\XINT_expr_gobz_scandec_b}%
{\string#2\expandafter\XINT_expr_scandec_d}\the\numexpr#1-\xint_c_i.%
}%
\def\XINT_expr_gobz_scandec_endbycs #1#2\xint_c_i.{0[0]\endcsname #1}%
\def\XINT_expr_gobz_scandec_c\if0#1#2\fi #3\xint_c_i.%
{%
\if e#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi
\if E#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi
\xint_orthat {0[0]\endcsname #1}%
}%
% \end{macrocode}
% \subsubsection{Scientific notation}
% \lverb|Some pluses and minuses are allowed at the start of the scientific
% part, however not later, and no parenthesis.|
% \begin{macrocode}
\def\XINT_expr_scanexp_a #1#2%
{%
#1\expandafter\XINT_expr_scanexp_b\romannumeral`&&@#2%
}%
\def\XINT_expr_scanexp_b #1%
{%
\ifcat \relax #1\expandafter\XINT_expr_scanexp_endbycs\expandafter #1\fi
\ifnum\xint_c_ix<1\string#1 \else\expandafter\XINT_expr_scanexp_c\fi
\string#1\XINT_expr_scanexp_d
}%
\def\XINT_expr_scanexpr_endbycs#1#2\XINT_expr_scanexp_d {]\endcsname #1}%
\def\XINT_expr_scanexp_d #1%
{%
\expandafter\XINT_expr_scanexp_bb\romannumeral`&&@#1%
}%
\def\XINT_expr_scanexp_c\string #1\XINT_expr_scanexp_d
{%
\if +#1\xint_dothis {\XINT_expr_scanexp_a +}\fi
\if -#1\xint_dothis {\XINT_expr_scanexp_a -}\fi
\xint_orthat {]\endcsname #1}%
}%
\def\XINT_expr_scanexp_bb #1%
{%
\ifcat \relax #1\expandafter\XINT_expr_scanexp_endbycs_b\expandafter #1\fi
\ifnum\xint_c_ix<1\string#1 \else\expandafter\XINT_expr_scanexp_cb\fi
\string#1\XINT_expr_scanexp_db
}%
\def\XINT_expr_scanexp_endbycs_b#1#2\XINT_expr_scanexp_db {]\endcsname #1}%
\def\XINT_expr_scanexp_db #1%
{%
\expandafter\XINT_expr_scanexp_bb\romannumeral`&&@#1%
}%
\def\XINT_expr_scanexp_cb\string #1\XINT_expr_scanexp_db {]\endcsname #1}%
% \end{macrocode}
% \subsubsection{Hexadecimal numbers}
% \lverb|1.2d has moved most of the handling of tacit multiplication to
% \XINT_expr_getop, but we have to do some of it here, because we apply
% \string before calling \XINT_expr_scanhexI_aa. I do not insert the *
% in \XINT_expr_scanhexI_a, because it is its higher precedence variant which
% will is expected, to do the same as when a non-hexadecimal number prefixes a
% sub-expression. Tacit multiplication in front of variable or function names
% will not work (because of this \string).|
% \begin{macrocode}
\def\XINT_expr_scanhex_I #1% #1="
{%
\expandafter\XINT_expr_getop\csname.=\expandafter
\XINT_expr_unlock_hex_in\csname.=\XINT_expr_scanhexI_a
}%
\def\XINT_expr_scanhexI_a #1%
{%
\ifcat #1\relax\xint_dothis{.>\endcsname\endcsname #1}\fi
\ifx !#1\xint_dothis{.>\endcsname\endcsname !}\fi
\xint_orthat {\expandafter\XINT_expr_scanhexI_aa\string #1}%
}%
\def\XINT_expr_scanhexI_aa #1%
{%
\if\ifnum`#1>`/
\ifnum`#1>`9
\ifnum`#1>`@
\ifnum`#1>`F
0\else1\fi\else0\fi\else1\fi\else0\fi 1%
\expandafter\XINT_expr_scanhexI_b
\else
\if .#1%
\expandafter\xint_firstoftwo
\else % gather what we got so far, leave catcode 12 #1 in stream
\expandafter\xint_secondoftwo
\fi
{\expandafter\XINT_expr_scanhex_transition}%
{\xint_afterfi {.>\endcsname\endcsname}}%
\fi
#1%
}%
\def\XINT_expr_scanhexI_b #1#2%
{%
#1\expandafter\XINT_expr_scanhexI_a\romannumeral`&&@#2%
}%
\def\XINT_expr_scanhex_transition .#1%
{%
\expandafter.\expandafter.\expandafter
\XINT_expr_scanhexII_a\romannumeral`&&@#1%
}%
\def\XINT_expr_scanhexII_a #1%
{%
\ifcat #1\relax\xint_dothis{\endcsname\endcsname#1}\fi
\ifx !#1\xint_dothis{\endcsname\endcsname !}\fi
\xint_orthat {\expandafter\XINT_expr_scanhexII_aa\string #1}%
}%
\def\XINT_expr_scanhexII_aa #1%
{%
\if\ifnum`#1>`/
\ifnum`#1>`9
\ifnum`#1>`@
\ifnum`#1>`F
0\else1\fi\else0\fi\else1\fi\else0\fi 1%
\expandafter\XINT_expr_scanhexII_b
\else
\xint_afterfi {\endcsname\endcsname}%
\fi
#1%
}%
\def\XINT_expr_scanhexII_b #1#2%
{%
#1\expandafter\XINT_expr_scanhexII_a\romannumeral`&&@#2%
}%
% \end{macrocode}
% \subsubsection{Parsing names of functions and variables}
% \begin{macrocode}
\def\XINT_expr_scanfunc
{%
\expandafter\XINT_expr_func\romannumeral`&&@\XINT_expr_scanfunc_a
}%
\def\XINT_expr_scanfunc_a #1#2%
{%
\expandafter #1\romannumeral`&&@\expandafter\XINT_expr_scanfunc_b\romannumeral`&&@#2%
}%
% \end{macrocode}
% \lverb|This handles: 1) (indirectly) tacit multiplication by a variable in
% front a of sub-expression, 2) (indirectly) tacit multiplication in front of
% a \count etc..., 3) functions which are recognized via an encountered opening
% parenthesis (but later this must be disambiguated from variables with tacit
% multiplication) 4) 5) 6) 7) acceptable components of a variable or function
% names: @, underscore, digits, letters (or chars of category code letter.)
%
% The short lived 1.2d which followed the even shorter lived 1.2c managed to
% introduce a bug here as it removed the check for catcode 11 !, which must be
% recognized if ! is not to be taken as part of a variable name. Don't know
% what I was thinking, it was the time when I was moving the handling of tacit
% mutliplication entirely to the \XINT_expr_getop side. Fixed in 1.2e.
%
% I almost decided to remove the \ifcat\relax test whose rôle is to avoid the
% \string#1 to do something bad is the escape char is a digit! Perhaps I will
% remove it at some point ! I truly almost did it, but also the case of no
% escape char is a problem (\string\0, if \0 is a count ...)
%
% The (indirectly) above means that via \XINT_expr_func then \XINT_expr_op__
% one goes back to \XINT_expr_getop then \XINT_expr_getop_b which is the
% location where tacit multiplication is now centralized. This makes the
% treatment of tacit multiplication for situations such as <variable>\count or
% <variable>\xintexpr..\relax, perhaps a bit sub-optimal, but first the
% variable name must be gathered, second the variable must expand to its
% value.|
% \begin{macrocode}
\def\XINT_expr_scanfunc_b #1%
{%
\ifx !#1\xint_dothis{(_}\fi
\ifcat \relax#1\xint_dothis{(_}\fi
\if (#1\xint_dothis{\xint_firstoftwo{(`}}\fi
\if @#1\xint_dothis \XINT_expr_scanfunc_a \fi
\if _#1\xint_dothis \XINT_expr_scanfunc_a \fi
\ifnum \xint_c_ix<1\string#1 \xint_dothis \XINT_expr_scanfunc_a \fi
\ifcat a#1\xint_dothis \XINT_expr_scanfunc_a \fi
\xint_orthat {(_}%
#1%
}%
% \end{macrocode}
% \lverb@Comments written 2015/11/12: earlier there was an \ifcsname test for
% checking if we had a variable in front of a (, for tacit multiplication for
% example in x(y+z(x+w)) to work. But after I had implemented functions (that
% was yesterday...), I had the problem if was impossible to re-declare a
% variable name such as "f" as a function name. The problem is that here we
% can not test if the function is available because we don't know if we are in
% expr, iiexpr or floatexpr. The \xint_c_xviii causes all fetching operations
% to stop and control is handed over to the routines which will be expr,
% iiexpr ou floatexpr specific, i.e. the \XINT_{expr|iiexpr|flexpr}_op_{`|_}
% which are invoked by the until_<op>_b macros earlier in the stream.
% Functions may exist for one but not the two other parsers. Variables are
% declared via one parser and usable in the others, but naturally \xintiiexpr
% has its restrictions.
%
% Thinking about this again I decided to treat a priori cases such as x(...)
% as functions, after having assigned to each variable a low-weight macro
% which will convert this into _getop\.=<value of x>*(...). To activate that
% macro at the right time I could for this exploit the "onlitteral" intercept,
% which is parser independent (1.2c).
%
% This led to me necessarily to rewrite partially the seq, add, mul, subs,
% iter ... routines as now the variables fetch only one token. I think the
% thing is more efficient.
%
% 1.2c had \def\XINT_expr_func #1(#2{\xint_c_xviii #2{#1}}
%
% In \XINT_expr_func the #2 is _ if #1 must be a variable name, or #2=` if #1
% must be either a function name or possibly a variable name which will then
% have to be followed by tacit multiplication before the opening parenthesis.
%
% The \xint_c_xviii is there because _op_` must know in which parser
% it works. Dispendious for _. Hence I modify for 1.2d. @
% \begin{macrocode}
\def\XINT_expr_func #1(#2{\if _#2\xint_dothis\XINT_expr_op__\fi
\xint_orthat{\xint_c_xviii #2}{#1}}%
% \end{macrocode}
% \subsection{\csh{XINT_expr_getop}: finding the next operator or closing
% parenthesis or end of expression}
% \lverb|Release 1.1 implements multi-character operators.
%
% 1.2d adds tacit mutiplication also in front of variable or functions names
% starting with a letter, not only a @ or a _ as was already the case. This is
% for (x+y)z situations. It also applies higher precedence in cases like x/2y
% or x/2@, or x/2max(3,5), or x/2\xintexpr 3\relax.
%
% In fact, finally I decide that all sorts of tacit multiplication will always
% use the higher precedence.
%
% Indeed I hesitated somewhat: with the current code one does not know if
% \XINT_expr_getop as invoked after a closing parenthesis or because a number
% parsing ended, and I felt distinguishing the two was unneeded extra stuff.
% This means cases like (a+b)/(c+d)(e+f) will first multiply the last two
% parenthesized terms.
%
% The ! starting a sub-expression must be distinguished from the post-fix !
% for factorial, thus we must not do a too early \string. In versions < 1.2c,
% the catcode 11 ! had to be identified in all branches of the number or
% function scans. Here it is simply treated as a special case of a letter.|
% \begin{macrocode}
\def\XINT_expr_getop #1#2% this #1 is the current locked computed value
{%
\expandafter\XINT_expr_getop_a\expandafter #1\romannumeral`&&@#2%
}%
\catcode`* 11
\def\XINT_expr_getop_a #1#2%
{%
\ifx \relax #2\xint_dothis\xint_firstofthree\fi
\ifcat \relax #2\xint_dothis\xint_secondofthree\fi
\if _#2\xint_dothis \xint_secondofthree\fi
\if @#2\xint_dothis \xint_secondofthree\fi
\if (#2\xint_dothis \xint_secondofthree\fi
\ifcat a#2\xint_dothis \xint_secondofthree\fi
\xint_orthat \xint_thirdofthree
{\XINT_expr_foundend #1}%
{\XINT_expr_precedence_*** *#1#2}% tacit multiplication with higher precedence
{\expandafter\XINT_expr_getop_b \string#2#1}%
}%
\catcode`* 12
\def\XINT_expr_foundend {\xint_c_ \relax }% \relax is a place holder here.
% \end{macrocode}
% \lverb|? is a very special operator with top precedence which will check if
% the next token is another ?, while avoiding removing a brace pair from token
% stream due to its syntax. Pre 1.1 releases used : rather than ??, but we
% need : for Python like slices of lists.|
% \begin{macrocode}
\def\XINT_expr_getop_b #1%
{%
\if '#1\xint_dothis{\XINT_expr_binopwrd }\fi
\if ?#1\xint_dothis{\XINT_expr_precedence_? ?}\fi
\xint_orthat {\XINT_expr_scanop_a #1}%
}%
\def\XINT_expr_binopwrd #1#2'{\expandafter\XINT_expr_foundop_a
\csname XINT_expr_itself_\xint_zapspaces #2 \xint_gobble_i\endcsname #1}%
\def\XINT_expr_scanop_a #1#2#3%
{\expandafter\XINT_expr_scanop_b\expandafter #1\expandafter #2\romannumeral`&&@#3}%
\def\XINT_expr_scanop_b #1#2#3%
{%
\ifcat#3\relax\xint_dothis{\XINT_expr_foundop_a #1#2#3}\fi
\ifcsname XINT_expr_itself_#1#3\endcsname
\xint_dothis
{\expandafter\XINT_expr_scanop_c\csname XINT_expr_itself_#1#3\endcsname #2}\fi
\xint_orthat {\XINT_expr_foundop_a #1#2#3}%
}%
\def\XINT_expr_scanop_c #1#2#3%
{%
\expandafter\XINT_expr_scanop_d\expandafter #1\expandafter #2\romannumeral`&&@#3%
}%
\def\XINT_expr_scanop_d #1#2#3%
{%
\ifcat#3\relax \xint_dothis{\XINT_expr_foundop #1#2#3}\fi
\ifcsname XINT_expr_itself_#1#3\endcsname
\xint_dothis
{\expandafter\XINT_expr_scanop_c\csname XINT_expr_itself_#1#3\endcsname #2}\fi
\xint_orthat {\csname XINT_expr_precedence_#1\endcsname #1#2#3}%
}%
\def\XINT_expr_foundop_a #1%
{%
\ifcsname XINT_expr_precedence_#1\endcsname
\csname XINT_expr_precedence_#1\expandafter\endcsname
\expandafter #1%
\else
\xint_afterfi{\XINT_expr_unknown_operator {#1}\XINT_expr_getop}%
\fi
}%
\def\XINT_expr_unknown_operator #1{\xintError:removed \xint_gobble_i {#1}}%
\def\XINT_expr_foundop #1{\csname XINT_expr_precedence_#1\endcsname #1}%
% \end{macrocode}
% \subsection{Expansion spanning; opening and closing parentheses}
% \lverb|Version 1.1 had a hack inside the until macros for handling the omit
% and abort in iterations over dummy variables. This has been removed by
% 1.2c, see the subsection where omit and abort are discussed.|
% \begin{macrocode}
\catcode`) 11
\def\XINT_tmpa #1#2#3#4%
{%
\def#1##1%
{%
\xint_UDsignfork
##1{\expandafter#1\romannumeral`&&@#3}%
-{#2##1}%
\krof
}%
\def#2##1##2%
{%
\ifcase ##1\expandafter\XINT_expr_done
\or\xint_afterfi{\XINT_expr_extra_)
\expandafter #1\romannumeral`&&@\XINT_expr_getop }%
\else
\xint_afterfi{\expandafter#1\romannumeral`&&@\csname XINT_#4_op_##2\endcsname }%
\fi
}%
}%
\def\XINT_expr_extra_) {\xintError:removed }%
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\XINT_tmpa
\csname XINT_#1_until_end_a\expandafter\endcsname
\csname XINT_#1_until_end_b\expandafter\endcsname
\csname XINT_#1_op_-vi\endcsname
{#1}%
}%
\def\XINT_tmpa #1#2#3#4#5#6%
{%
\def #1##1{\expandafter #3\romannumeral`&&@\XINT_expr_getnext }%
\def #2{\expandafter #3\romannumeral`&&@\XINT_expr_getnext }%
\def #3##1{\xint_UDsignfork
##1{\expandafter #3\romannumeral`&&@#5}%
-{#4##1}%
\krof }%
\def #4##1##2{\ifcase ##1\expandafter\XINT_expr_missing_)
\or \csname XINT_#6_op_##2\expandafter\endcsname
\else
\xint_afterfi{\expandafter #3\romannumeral`&&@\csname XINT_#6_op_##2\endcsname }%
\fi
}%
}%
\def\XINT_expr_missing_) {\xintError:inserted \xint_c_ \XINT_expr_done }%
% \end{macrocode}
% \lverb|We should be using until_( notation to stay synchronous with until_+,
% until_* etc..., but I found that until_) was more telling.|
% \begin{macrocode}
\catcode`) 12
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\XINT_tmpa
\csname XINT_#1_op_(\expandafter\endcsname
\csname XINT_#1_oparen\expandafter\endcsname
\csname XINT_#1_until_)_a\expandafter\endcsname
\csname XINT_#1_until_)_b\expandafter\endcsname
\csname XINT_#1_op_-vi\endcsname
{#1}%
}%
\expandafter\let\csname XINT_expr_precedence_)\endcsname\xint_c_i
% \end{macrocode}
% \subsection{\textbar, \textbar\textbar, \&,
% \&\&, <, >, =, ==, <=, >=, !=, +, \textendash,
% \texorpdfstring{\protect\lowast}{*}, /, \textasciicircum,
% \texorpdfstring{\protect\lowast\protect\lowast}{**}, //, /:, .., ..[, ]..,
% ][, ][:, :], and ++ operators}
% \localtableofcontents
% \subsubsection{Square brackets for lists, the
% !? for omit and abort, and the ++ postfix construct}
% \lverb|This is all very clever and only need setting some suitable precedence
% levels, if only I could understand what I did in 2014... just joking. Notice
% that op_) macros are defined here in the \xintFor loop.
%
% There is some clever business going on here with the letter a for handling
% constructs such as [3..5]*2 (I think...).
%
% 1.2c has replaced 1.1's private dealings with "^C" (which was done before
% dummy variables got implemented) by use of "!?". See discussion of omit and
% abort.
% |
% \begin{macrocode}
\expandafter\let\csname XINT_expr_precedence_]\endcsname\xint_c_i
\expandafter\let\csname XINT_expr_precedence_;\endcsname\xint_c_i
\let\XINT_expr_precedence_a \xint_c_xviii
\let\XINT_expr_precedence_!? \xint_c_ii
\expandafter\let\csname XINT_expr_precedence_++)\endcsname \xint_c_i
% \end{macrocode}
% \lverb|Comments added 2015/11/13 Here we have in particular the mechanism
% for post action on lists via op_] The precedence_] is the one of a closing
% parenthesis. We need the closing parenthesis to do its job, hence we can not
% define a op_]+ operator for example, as we want to assign it the precedence
% of addition not the one of closing parenthesis. The trick I used in 1.1 was
% to let the op_] insert the letter a, this letter exceptionnally also being a
% legitimate operator, launch the _getop and let it find a a*, a+, a/, a-, a^,
% a** operator standing for ]*, ]+, ]/, ]^, ]** postfix item by item list
% operator. I thought I had in mind an example to show that having defined
% op_a and precedence_a for the letter a caused a reduction in syntax for this
% letter, but it seems I am lacking now an example.
%
% 2015/11/18: for 1.2d I accelerate \XINT_expr_op_] to jump over the
% \XINT_expr_getop_a which now does tacit multiplications also in front of
% letters, for reasons of things like, (x+y)z, hence it must not see the "a".
% I could have used a catcode12 a possibly, but anyhow jumping straight to
% \XINT_expr_scanop_a skips a few expansion steps (up to the potential price
% of less conceptual programming if I change things in the future.)|
% \begin{macrocode}
\catcode`. 11 \catcode`= 11 \catcode`+ 11
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\let\csname XINT_#1_op_)\endcsname \XINT_expr_getop
\expandafter\let\csname XINT_#1_op_;\endcsname \space
\expandafter\def\csname XINT_#1_op_]\endcsname ##1{\XINT_expr_scanop_a a##1}%
\expandafter\let\csname XINT_#1_op_a\endcsname \XINT_expr_getop
% \end{macrocode}
% \lverb|1.1 2014/10/29 did \expandafter\.=+\xintiCeil which transformed it into
% \romannumeral0\xinticeil, which seems a bit weird. This exploited the fact
% that dummy variables macros could back then pick braced material (which in the
% case at hand here ended being {\romannumeral0\xinticeil...} and were submitted
% to two expansions. The result of this was to provide a not value which got
% expanded only in the first loop of the :_A and following macros of seq,
% iter, rseq, etc...
%
% Anyhow with 1.2c I have changed the implementation of dummy variables which
% now need to fetch a single locked token, which they do not expand.
%
% The \xintiCeil appears a bit dispendious, but I need the starting value in a
% \numexpr compatible form in the iteration loops.|
% \begin{macrocode}
\expandafter\def\csname XINT_#1_op_++)\endcsname ##1##2\relax
{\expandafter\XINT_expr_foundend \expandafter
{\expandafter\.=+\csname .=\xintiCeil{\XINT_expr_unlock ##1}\endcsname }}%
}%
\catcode`. 12 \catcode`= 12 \catcode`+ 12
% \end{macrocode}
% \lverb|1.2d adds the *** for tying via tacit multiplication, for example
% x/2y. Actually I don't need the _itself mechanism for ***, only a precedence.|
% \begin{macrocode}
\catcode`& 12
\xintFor* #1 in {{==}{<=}{>=}{!=}{&&}{||}{**}{//}{/:}{..}{..[}{].}{]..}%
{+[}{-[}{*[}{/[}{**[}{^[}{a+}{a-}{a*}{a/}{a**}{a^}%
{][}{][:}{:]}{!?}{++}{++)}}%{***}}
\do {\expandafter\def\csname XINT_expr_itself_#1\endcsname {#1}}%
\catcode`& 7
\expandafter\let\csname XINT_expr_precedence_***\endcsname \xint_c_viii
% \end{macrocode}
% \subsubsection{The \textbar, \&, xor, <, >, =, <=, >=, !=, //, /:, .., +,
% \textendash, \texorpdfstring{\protect\lowast}{*}, /, \textasciicircum, ..[,
% and ].. operators for expr, floatexpr and iiexpr operators}
% \lverb|1.2d needed some room between /, * and ^. Hence precedence for ^
% is now at 9|
% \begin{macrocode}
\def\XINT_expr_defbin_c #1#2#3#4#5#6#7#8%
{%
\def #1##1% \XINT_expr_op_<op> ou flexpr ou iiexpr
{% keep value, get next number and operator, then do until
\expandafter #2\expandafter ##1%
\romannumeral`&&@\expandafter\XINT_expr_getnext }%
\def #2##1##2% \XINT_expr_until_<op>_a ou flexpr ou iiexpr
{\xint_UDsignfork ##2{\expandafter #2\expandafter ##1\romannumeral`&&@#4}%
-{#3##1##2}%
\krof }%
\def #3##1##2##3##4% \XINT_expr_until_<op>_b ou flexpr ou iiexpr
{% either execute next operation now, or first do next (possibly unary)
\ifnum ##2>#7%
\xint_afterfi {\expandafter #2\expandafter ##1\romannumeral`&&@%
\csname XINT_#8_op_##3\endcsname {##4}}%
\else \xint_afterfi {\expandafter ##2\expandafter ##3%
\csname .=#6{\XINT_expr_unlock ##1}{\XINT_expr_unlock ##4}\endcsname }%
\fi }%
\let #7#5%
}%
\def\XINT_expr_defbin_b #1#2#3#4#5%
{%
\expandafter\XINT_expr_defbin_c
\csname XINT_#1_op_#2\expandafter\endcsname
\csname XINT_#1_until_#2_a\expandafter\endcsname
\csname XINT_#1_until_#2_b\expandafter\endcsname
\csname XINT_#1_op_-#4\expandafter\endcsname
\csname xint_c_#3\expandafter\endcsname
\csname #5\expandafter\endcsname
\csname XINT_expr_precedence_#2\endcsname {#1}%
}%
\XINT_expr_defbin_b {expr} | {iii}{vi} {xintOR}%
\XINT_expr_defbin_b {flexpr} | {iii}{vi} {xintOR}%
\XINT_expr_defbin_b {iiexpr} | {iii}{vi} {xintOR}%
\XINT_expr_defbin_b {expr} & {iv}{vi} {xintAND}%
\XINT_expr_defbin_b {flexpr} & {iv}{vi} {xintAND}%
\XINT_expr_defbin_b {iiexpr} & {iv}{vi} {xintAND}%
\XINT_expr_defbin_b {expr} {xor}{iii}{vi} {xintXOR}%
\XINT_expr_defbin_b {flexpr}{xor}{iii}{vi} {xintXOR}%
\XINT_expr_defbin_b {iiexpr}{xor}{iii}{vi} {xintXOR}%
\XINT_expr_defbin_b {expr} < {v}{vi} {xintLt}%
\XINT_expr_defbin_b {flexpr} < {v}{vi} {xintLt}%
\XINT_expr_defbin_b {iiexpr} < {v}{vi} {xintiiLt}%
\XINT_expr_defbin_b {expr} > {v}{vi} {xintGt}%
\XINT_expr_defbin_b {flexpr} > {v}{vi} {xintGt}%
\XINT_expr_defbin_b {iiexpr} > {v}{vi} {xintiiGt}%
\XINT_expr_defbin_b {expr} = {v}{vi} {xintEq}%
\XINT_expr_defbin_b {flexpr} = {v}{vi} {xintEq}%
\XINT_expr_defbin_b {iiexpr} = {v}{vi} {xintiiEq}%
\XINT_expr_defbin_b {expr} {<=} {v}{vi} {xintLtorEq}%
\XINT_expr_defbin_b {flexpr}{<=} {v}{vi} {xintLtorEq}%
\XINT_expr_defbin_b {iiexpr}{<=} {v}{vi} {xintiiLtorEq}%
\XINT_expr_defbin_b {expr} {>=} {v}{vi} {xintGtorEq}%
\XINT_expr_defbin_b {flexpr}{>=} {v}{vi} {xintGtorEq}%
\XINT_expr_defbin_b {iiexpr}{>=} {v}{vi} {xintiiGtorEq}%
\XINT_expr_defbin_b {expr} {!=} {v}{vi} {xintNeq}%
\XINT_expr_defbin_b {flexpr}{!=} {v}{vi} {xintNeq}%
\XINT_expr_defbin_b {iiexpr}{!=} {v}{vi} {xintiiNeq}%
\XINT_expr_defbin_b {expr} {..} {iii}{vi} {xintSeq::csv}%
\XINT_expr_defbin_b {flexpr}{..} {iii}{vi} {xintSeq::csv}%
\XINT_expr_defbin_b {iiexpr}{..} {iii}{vi} {xintiiSeq::csv}%
\XINT_expr_defbin_b {expr} {//} {vii}{vii}{xintDivTrunc}%
\XINT_expr_defbin_b {flexpr}{//} {vii}{vii}{xintDivTrunc}%
\XINT_expr_defbin_b {iiexpr}{//} {vii}{vii}{xintiiDivTrunc}%
\XINT_expr_defbin_b {expr} {/:} {vii}{vii}{xintMod}%
\XINT_expr_defbin_b {flexpr}{/:} {vii}{vii}{xintMod}%
\XINT_expr_defbin_b {iiexpr}{/:} {vii}{vii}{xintiiMod}%
\XINT_expr_defbin_b {expr} + {vi}{vi} {xintAdd}%
\XINT_expr_defbin_b {flexpr} + {vi}{vi} {XINTinFloatAdd}%
\XINT_expr_defbin_b {iiexpr} + {vi}{vi} {xintiiAdd}%
\XINT_expr_defbin_b {expr} - {vi}{vi} {xintSub}%
\XINT_expr_defbin_b {flexpr} - {vi}{vi} {XINTinFloatSub}%
\XINT_expr_defbin_b {iiexpr} - {vi}{vi} {xintiiSub}%
\XINT_expr_defbin_b {expr} * {vii}{vii}{xintMul}%
\XINT_expr_defbin_b {flexpr} * {vii}{vii}{XINTinFloatMul}%
\XINT_expr_defbin_b {iiexpr} * {vii}{vii}{xintiiMul}%
\XINT_expr_defbin_b {expr} / {vii}{vii}{xintDiv}%
\XINT_expr_defbin_b {flexpr} / {vii}{vii}{XINTinFloatDiv}%
\XINT_expr_defbin_b {iiexpr} / {vii}{vii}{xintiiDivRound}% CHANGED IN 1.1!
\XINT_expr_defbin_b {expr} ^ {ix}{ix} {xintPow}%
\XINT_expr_defbin_b {flexpr} ^ {ix}{ix} {XINTinFloatPowerH}%
\XINT_expr_defbin_b {iiexpr} ^ {ix}{ix} {xintiiPow}%
\XINT_expr_defbin_b {expr} {..[}{iii}{vi} {xintSeqA::csv}%
\XINT_expr_defbin_b {flexpr}{..[}{iii}{vi} {XINTinFloatSeqA::csv}%
\XINT_expr_defbin_b {iiexpr}{..[}{iii}{vi} {xintiiSeqA::csv}%
\XINT_expr_defbin_b {expr} {]..}{iii}{vi} {xintSeqB::csv}%
\XINT_expr_defbin_b {flexpr}{]..}{iii}{vi} {XINTinFloatSeqB::csv}%
\XINT_expr_defbin_b {iiexpr}{]..}{iii}{vi} {xintiiSeqB::csv}%
% \end{macrocode}
% \subsubsection{The ]+, ]\textendash, ]\texorpdfstring{\protect\lowast}{*}, ]/, ]\textasciicircum, +[, \textendash[, \texorpdfstring{\protect\lowast}{*}[, /[, and \textasciicircum[ list
% operators}
% \paragraph{\csh{XINT_expr_binop_inline_b}}\par
% \lverb|This handles acting on comma separated values (no need to bother
% about spaces in this context; expansion in a \csname...\endcsname.|
% \begin{macrocode}
\def\XINT_expr_binop_inline_a
{\expandafter\xint_gobble_i\romannumeral`&&@\XINT_expr_binop_inline_b }%
\def\XINT_expr_binop_inline_b #1#2,{\XINT_expr_binop_inline_c #2,{#1}}%
\def\XINT_expr_binop_inline_c #1{%
\if ,#1\xint_dothis\XINT_expr_binop_inline_e\fi
\if ^#1\xint_dothis\XINT_expr_binop_inline_end\fi
\xint_orthat\XINT_expr_binop_inline_d #1}%
\def\XINT_expr_binop_inline_d #1,#2{,#2{#1}\XINT_expr_binop_inline_b {#2}}%
\def\XINT_expr_binop_inline_e #1,#2{,\XINT_expr_binop_inline_b {#2}}%
\def\XINT_expr_binop_inline_end #1,#2{}%
\def\XINT_expr_deflistopr_c #1#2#3#4#5#6#7#8%
{%
\def #1##1% \XINT_expr_op_<op> ou flexpr ou iiexpr
{% keep value, get next number and operator, then do until
\expandafter #2\expandafter ##1%
\romannumeral`&&@\expandafter\XINT_expr_getnext }%
\def #2##1##2% \XINT_expr_until_<op>_a ou flexpr ou iiexpr
{\xint_UDsignfork ##2{\expandafter #2\expandafter ##1\romannumeral`&&@#4}%
-{#3##1##2}%
\krof }%
\def #3##1##2##3##4% \XINT_expr_until_<op>_b ou flexpr ou iiexpr
{% either execute next operation now, or first do next (possibly unary)
\ifnum ##2>#7%
\xint_afterfi {\expandafter #2\expandafter ##1\romannumeral`&&@%
\csname XINT_#8_op_##3\endcsname {##4}}%
\else \xint_afterfi {\expandafter ##2\expandafter ##3%
\csname .=\expandafter\XINT_expr_binop_inline_a\expandafter
{\expandafter\expandafter\expandafter#6\expandafter
\xint_exchangetwo_keepbraces\expandafter
{\expandafter\XINT_expr_unlock\expandafter ##4\expandafter}\expandafter}%
\romannumeral`&&@\XINT_expr_unlock ##1,^,\endcsname }%
\fi }%
\let #7#5%
}%
\def\XINT_expr_deflistopr_b #1#2#3#4%
{%
\expandafter\XINT_expr_deflistopr_c
\csname XINT_#1_op_#2\expandafter\endcsname
\csname XINT_#1_until_#2_a\expandafter\endcsname
\csname XINT_#1_until_#2_b\expandafter\endcsname
\csname XINT_#1_op_-#3\expandafter\endcsname
\csname xint_c_#3\expandafter\endcsname
\csname #4\expandafter\endcsname
\csname XINT_expr_precedence_#2\endcsname {#1}%
}%
% \end{macrocode}
% \lverb|This is for [x..y]*z syntax etc.... Attention that with 1.2d,
% precedence level of ^ raised to ix to make room for ***.|
% \begin{macrocode}
\XINT_expr_deflistopr_b {expr} {a+}{vi} {xintAdd}%
\XINT_expr_deflistopr_b {expr} {a-}{vi} {xintSub}%
\XINT_expr_deflistopr_b {expr} {a*}{vii}{xintMul}%
\XINT_expr_deflistopr_b {expr} {a/}{vii}{xintDiv}%
\XINT_expr_deflistopr_b {expr} {a^}{ix} {xintPow}%
\XINT_expr_deflistopr_b {iiexpr}{a+}{vi} {xintiiAdd}%
\XINT_expr_deflistopr_b {iiexpr}{a-}{vi} {xintiiSub}%
\XINT_expr_deflistopr_b {iiexpr}{a*}{vii}{xintiiMul}%
\XINT_expr_deflistopr_b {iiexpr}{a/}{vii}{xintiiDivRound}%
\XINT_expr_deflistopr_b {iiexpr}{a^}{ix} {xintiiPow}%
\XINT_expr_deflistopr_b {flexpr}{a+}{vi} {XINTinFloatAdd}%
\XINT_expr_deflistopr_b {flexpr}{a-}{vi} {XINTinFloatSub}%
\XINT_expr_deflistopr_b {flexpr}{a*}{vii}{XINTinFloatMul}%
\XINT_expr_deflistopr_b {flexpr}{a/}{vii}{XINTinFloatDiv}%
\XINT_expr_deflistopr_b {flexpr}{a^}{ix} {XINTinFloatPowerH}%
\def\XINT_expr_deflistopl_c #1#2#3#4#5#6#7%
{%
\def #1##1{\expandafter#2\expandafter##1\romannumeral`&&@%
\expandafter #3\romannumeral`&&@\XINT_expr_getnext }%
\def #2##1##2##3##4%
{% either execute next operation now, or first do next (possibly unary)
\ifnum ##2>#6%
\xint_afterfi {\expandafter #2\expandafter ##1\romannumeral`&&@%
\csname XINT_#7_op_##3\endcsname {##4}}%
\else \xint_afterfi {\expandafter ##2\expandafter ##3%
\csname .=\expandafter\XINT_expr_binop_inline_a\expandafter
{\expandafter#5\expandafter
{\expandafter\XINT_expr_unlock\expandafter ##1\expandafter}\expandafter}%
\romannumeral`&&@\XINT_expr_unlock ##4,^,\endcsname }%
\fi }%
\let #6#4%
}%
\def\XINT_expr_deflistopl_b #1#2#3#4%
{%
\expandafter\XINT_expr_deflistopl_c
\csname XINT_#1_op_#2\expandafter\endcsname
\csname XINT_#1_until_#2\expandafter\endcsname
\csname XINT_#1_until_)_a\expandafter\endcsname
\csname xint_c_#3\expandafter\endcsname
\csname #4\expandafter\endcsname
\csname XINT_expr_precedence_#2\endcsname {#1}%
}%
% \end{macrocode}
% \lverb|This is for z*[x..y] syntax etc...|
% \begin{macrocode}
\XINT_expr_deflistopl_b {expr} {+[}{vi} {xintAdd}%
\XINT_expr_deflistopl_b {expr} {-[}{vi} {xintSub}%
\XINT_expr_deflistopl_b {expr} {*[}{vii}{xintMul}%
\XINT_expr_deflistopl_b {expr} {/[}{vii}{xintDiv}%
\XINT_expr_deflistopl_b {expr} {^[}{ix} {xintPow}%
\XINT_expr_deflistopl_b {iiexpr}{+[}{vi} {xintiiAdd}%
\XINT_expr_deflistopl_b {iiexpr}{-[}{vi} {xintiiSub}%
\XINT_expr_deflistopl_b {iiexpr}{*[}{vii}{xintiiMul}%
\XINT_expr_deflistopl_b {iiexpr}{/[}{vii}{xintiiDivRound}%
\XINT_expr_deflistopl_b {iiexpr}{^[}{ix} {xintiiPow}%
\XINT_expr_deflistopl_b {flexpr}{+[}{vi} {XINTinFloatAdd}%
\XINT_expr_deflistopl_b {flexpr}{-[}{vi} {XINTinFloatSub}%
\XINT_expr_deflistopl_b {flexpr}{*[}{vii}{XINTinFloatMul}%
\XINT_expr_deflistopl_b {flexpr}{/[}{vii}{XINTinFloatDiv}%
\XINT_expr_deflistopl_b {flexpr}{^[}{ix} {XINTinFloatPowerH}%
% \end{macrocode}
% \subsubsection{The \textquotesingle and\textquotesingle, \textquotesingle
% or\textquotesingle, \textquotesingle xor\textquotesingle, and
% \textquotesingle mod\textquotesingle\ as infix operator words}
% \begin{macrocode}
\xintFor #1 in {and,or,xor,mod} \do {%
\expandafter\def\csname XINT_expr_itself_#1\endcsname {#1}}%
\expandafter\let\csname XINT_expr_precedence_and\expandafter\endcsname
\csname XINT_expr_precedence_&\endcsname
\expandafter\let\csname XINT_expr_precedence_or\expandafter\endcsname
\csname XINT_expr_precedence_|\endcsname
\expandafter\let\csname XINT_expr_precedence_mod\expandafter\endcsname
\csname XINT_expr_precedence_/:\endcsname
\xintFor #1 in {expr, flexpr, iiexpr} \do {%
\expandafter\let\csname XINT_#1_op_and\expandafter\endcsname
\csname XINT_#1_op_&\endcsname
\expandafter\let\csname XINT_#1_op_or\expandafter\endcsname
\csname XINT_#1_op_|\endcsname
\expandafter\let\csname XINT_#1_op_mod\expandafter\endcsname
\csname XINT_#1_op_/:\endcsname
}%
% \end{macrocode}
% \subsubsection{The \textbar\textbar,
% \&\&, \texorpdfstring{\protect\lowast\protect\lowast,
% \protect\lowast\protect\lowast[, ]\protect\lowast\protect\lowast}{**, **[, ]**}{} operators as synonyms}
% \begin{macrocode}
\expandafter\let\csname XINT_expr_precedence_==\expandafter\endcsname
\csname XINT_expr_precedence_=\endcsname
\expandafter\let\csname XINT_expr_precedence_&\string&\expandafter\endcsname
\csname XINT_expr_precedence_&\endcsname
\expandafter\let\csname XINT_expr_precedence_||\expandafter\endcsname
\csname XINT_expr_precedence_|\endcsname
\expandafter\let\csname XINT_expr_precedence_**\expandafter\endcsname
\csname XINT_expr_precedence_^\endcsname
\expandafter\let\csname XINT_expr_precedence_a**\expandafter\endcsname
\csname XINT_expr_precedence_a^\endcsname
\expandafter\let\csname XINT_expr_precedence_**[\expandafter\endcsname
\csname XINT_expr_precedence_^[\endcsname
\xintFor #1 in {expr, flexpr, iiexpr} \do {%
\expandafter\let\csname XINT_#1_op_==\expandafter\endcsname
\csname XINT_#1_op_=\endcsname
\expandafter\let\csname XINT_#1_op_&\string&\expandafter\endcsname
\csname XINT_#1_op_&\endcsname
\expandafter\let\csname XINT_#1_op_||\expandafter\endcsname
\csname XINT_#1_op_|\endcsname
\expandafter\let\csname XINT_#1_op_**\expandafter\endcsname
\csname XINT_#1_op_^\endcsname
\expandafter\let\csname XINT_#1_op_a**\expandafter\endcsname
\csname XINT_#1_op_a^\endcsname
\expandafter\let\csname XINT_#1_op_**[\expandafter\endcsname
\csname XINT_#1_op_^[\endcsname
}%
% \end{macrocode}
% \subsection{Macros for list selectors: [list][N], [list][:b], [list][a:], [list][a:b]}
% \localtableofcontents
%
% \lverb|1.1 (27 octobre 2014) I implement Python syntax, see
% http://stackoverflow.com/a/13005464/4184837. I do not implement third
% argument giving the step. Also, Python [5:2] selector returns empty
% and not, as I could have been tempted to do, (list[5], list[4], list[3]).
% Anyway, it is simpler not to do that. For reversing I could allow
% [::-1] syntax but this would get confusing, better to do function "reversed".
%
% This gets the job done, but I would definitely need \xintTrim::csv,
% \xintKeep::csv, \xintNthElt::csv for better efficiency. Not for 1.1.
%
% 2016/03/16. 1.2g decides that as [list][a:b] obeyed already Python syntax,
% for example [list][:n] keeps the first n elements, it was annoying that
% elements were tacitly numbered starting from 1 and not from 0 in the context
% of the [list][N] syntax. Thus now [list][n] returns the (n-1)-eth element.
% And one must use len(list) for the length.
%
% 2016/03/17. I had forgotten the 1.1 code comment above and 1.2g does it at
% last, in f-expandable versions \xintTrim:f:csv, \xintKeep:f:csv,
% \xintNthELtPy:f:csv and \xintLength:f:csv, which are all f-expandable for
% easier use with \xintNewExpr. Also \xintReverse:f:csv. I end up moving them
% all to xinttools.sty.
%
%
%|
% \begin{macrocode}
\def\XINT_tmpa #1#2#3#4#5#6%
{%
\def #1##1% \XINT_expr_op_][
{%
\expandafter #2\expandafter ##1\romannumeral`&&@\XINT_expr_getnext
}%
\def #2##1##2% \XINT_expr_until_][_a
{\xint_UDsignfork
##2{\expandafter #2\expandafter ##1\romannumeral`&&@#4}%
-{#3##1##2}%
\krof }%
\def #3##1##2##3##4% \XINT_expr_until_][_b
{%
\ifnum ##2>#5%
\xint_afterfi {\expandafter #2\expandafter ##1\romannumeral`&&@%
\csname XINT_#6_op_##3\endcsname {##4}}%
\else
\xint_afterfi
{\expandafter ##2\expandafter ##3\csname
.=\expandafter\xintListSel:f:csv
\romannumeral`&&@\XINT_expr_unlock ##4;%
\XINT_expr_unlock ##1;\endcsname % unlock for \xintNewExpr
}%
\fi
}%
\let #5\xint_c_ii
}%
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\XINT_tmpa
\csname XINT_#1_op_][\expandafter\endcsname
\csname XINT_#1_until_][_a\expandafter\endcsname
\csname XINT_#1_until_][_b\expandafter\endcsname
\csname XINT_#1_op_-vi\expandafter\endcsname
\csname XINT_expr_precedence_][\endcsname {#1}%
}%
\def\XINT_tmpa #1#2#3#4#5#6%
{%
\def #1##1% \XINT_expr_op_:
{%
\expandafter #2\expandafter ##1\romannumeral`&&@\XINT_expr_getnext
}%
\def #2##1##2% \XINT_expr_until_:_a
{\xint_UDsignfork
##2{\expandafter #2\expandafter ##1\romannumeral`&&@#4}%
-{#3##1##2}%
\krof }%
\def #3##1##2##3##4% \XINT_expr_until_:_b
{%
\ifnum ##2>#5%
\xint_afterfi {\expandafter #2\expandafter ##1\romannumeral`&&@%
\csname XINT_#6_op_##3\endcsname {##4}}%
\else
\xint_afterfi
{\expandafter ##2\expandafter ##3\csname
.=:\xintiiifSgn{\XINT_expr_unlock ##1}NPP.%
\xintiiifSgn{\XINT_expr_unlock ##4}NPP.%
\xintNum{\XINT_expr_unlock ##1};\xintNum{\XINT_expr_unlock ##4}\endcsname
}%
\fi
}%
\let #5\xint_c_iii
}%
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\XINT_tmpa
\csname XINT_#1_op_:\expandafter\endcsname
\csname XINT_#1_until_:_a\expandafter\endcsname
\csname XINT_#1_until_:_b\expandafter\endcsname
\csname XINT_#1_op_-vi\expandafter\endcsname
\csname XINT_expr_precedence_:\endcsname {#1}%
}%
\catcode`[ 11 \catcode`] 11
\let\XINT_expr_precedence_:] \xint_c_iii
\def\XINT_expr_op_:] #1{\expandafter\xint_c_i\expandafter )%
\csname .=]\xintiiifSgn{\XINT_expr_unlock #1}npp\XINT_expr_unlock #1\endcsname }%
\let\XINT_flexpr_op_:] \XINT_expr_op_:]
\let\XINT_iiexpr_op_:] \XINT_expr_op_:]
\let\XINT_expr_precedence_][: \xint_c_iii
% \end{macrocode}
% \lverb|At the end of the replacement text of \XINT_expr_op_][:, the : after
% index 0 must be catcode 12, else will be mistaken for the start of variable
% by expression parser (as <digits><variable> is allowed by the syntax and does
% tacit multiplication).|
% \begin{macrocode}
\edef\XINT_expr_op_][: #1{\xint_c_ii \expandafter\noexpand
\csname XINT_expr_itself_][\endcsname #10\string :}%
\let\XINT_flexpr_op_][: \XINT_expr_op_][:
\let\XINT_iiexpr_op_][: \XINT_expr_op_][:
% \end{macrocode}
% \subsubsection{\csh{xintListSel:f:csv}}
% \lverb|Some complications here are due to \xintNewExpr matters.
%
% 2016/03/17.
% 1.2g uses Python numbering not only for slices but also item extractors.
%
% It also implements faster extractors, acting directly on comma separated
% values with custom sub-macros \xintTrim:f:csv, \xintKeep:f:csv,
% \xintNthEltPy:f:csv and \xintLength:f:csv. We currently use here
% f-expandable versions for easier compatibility with \xintNewExpr. Also
% sub-optimal is the way the list argument is grabbed. But still better than
% the 1.1 version which used \xintCSVtoList everywhere for access to the
% routines provided with \xinttoolsnameimp.|
% \begin{macrocode}
\catcode`[ 12 \catcode`] 12
\def\xintListSel:f:csv #1{%
\if ]\noexpand#1\xint_dothis{\expandafter\XINT_listsel:_s\romannumeral`&&@}\fi
\if :\noexpand#1\xint_dothis{\XINT_listsel:_:}\fi
\xint_orthat {\XINT_listsel:_nth #1}%
}%
\def\XINT_listsel:_s #1{\if p#1\expandafter\XINT_listsel:_trim\else
\expandafter\XINT_listsel:_keep\fi }%
\def\XINT_listsel:_: #1.#2.{\csname XINT_listsel:_#1#2\endcsname }%
\def\XINT_listsel:_trim #1;#2;{\xintTrim:f:csv {\xintNum{#1}}{#2}}%
\def\XINT_listsel:_keep #1;#2;{\xintKeep:f:csv {\xintNum{#1}}{#2}}%
\def\XINT_listsel:_nth#1;#2;{\xintNthEltPy:f:csv {\xintNum{#1}}{#2}}%
\def\XINT_listsel:_PP #1;#2;#3;%
{\xintTrim:f:csv {\xintNum{#1}}{\xintKeep:f:csv {\xintNum{#2}}{#3}}}%
\def\XINT_listsel:_NN #1;#2;#3;%
{\xintTrim:f:csv {\xintNum{#2}}{\xintKeep:f:csv {\xintNum{#1}}{#3}}}%
\def\XINT_listsel:_NP #1;#2;#3;{\expandafter\XINT_listsel:_NP_a
\the\numexpr #1+\xintLength:f:csv{#3};#2;#3;}%
\def\XINT_listsel:_NP_a #1#2;%
{\if -#1\expandafter\XINT_listsel:_OP\fi\XINT_listsel:_PP #1#2;}%
\def\XINT_listsel:_OP\XINT_listsel:_PP #1;{\XINT_listsel:_PP 0;}%
\def\XINT_listsel:_PN #1;#2;#3;{\expandafter\XINT_listsel:_PN_a
\the\numexpr #2+\xintLength:f:csv{#3};#1;#3;}%
\def\XINT_listsel:_PN_a #1#2;#3;%
{\if -#1\expandafter\XINT_listsel:_PO\fi\XINT_listsel:_PP #3;#1#2;}%
\def\XINT_listsel:_PO\XINT_listsel:_PP #1;#2;{\XINT_listsel:_PP #1;0;}%
% \end{macrocode}
% \subsubsection{\csh{xintTrim:f:csv}}
% \lverb|1.2g 2016/03/17. Code in xinttools.sty|
% \subsubsection{\csh{xintKeep:f:csv}}
% \lverb|1.2g 2016/03/17. Code in xinttools.sty|
% \subsubsection{\csh{xintNthEltPy:f:csv}}
% \lverb|1.2g 2016/03/17. Code in xinttools.sty|
% \subsubsection{\csh{xintReverse:f:csv}}
% \lverb|1.2g 2016/03/17. Code in xinttools.sty|
% \subsubsection{\csh{xintLength:f:csv}}
% \lverb|1.2g 2016/03/17. Code in xinttools.sty|
%
%\subsection{Macros for a..b list generation}
% \localtableofcontents
%
% \lverb|Ne produit que des listes d'entiers inférieurs à la borne
% de TeX ! mais sous la forme N/1[0] en ce qui concerne \xintSeq::csv.|
%
%\subsubsection{\csh{xintSeq::csv}}
%\lverb|Commence par remplacer a par ceil(a) et b par floor(b) et renvoie
% ensuite les entiers entre les deux, possiblement en décroissant, et
% extrémités comprises. Si a=b est non entier en obtient donc ceil(a) et
% floor(a). Ne renvoie jamais une liste vide.
%
% Note: le a..b dans \xintfloatexpr utilise cette routine.|
% \begin{macrocode}
\def\xintSeq::csv {\romannumeral0\xintseq::csv }%
\def\xintseq::csv #1#2%
{%
\expandafter\XINT_seq::csv\expandafter
{\the\numexpr \xintiCeil{#1}\expandafter}\expandafter
{\the\numexpr \xintiFloor{#2}}%
}%
\def\XINT_seq::csv #1#2%
{%
\ifcase\ifnum #1=#2 0\else\ifnum #2>#1 1\else -1\fi\fi\space
\expandafter\XINT_seq::csv_z
\or
\expandafter\XINT_seq::csv_p
\else
\expandafter\XINT_seq::csv_n
\fi
{#2}{#1}%
}%
\def\XINT_seq::csv_z #1#2{ #1/1[0]}%
\def\XINT_seq::csv_p #1#2%
{%
\ifnum #1>#2
\expandafter\expandafter\expandafter\XINT_seq::csv_p
\else
\expandafter\XINT_seq::csv_e
\fi
\expandafter{\the\numexpr #1-\xint_c_i}{#2},#1/1[0]%
}%
\def\XINT_seq::csv_n #1#2%
{%
\ifnum #1<#2
\expandafter\expandafter\expandafter\XINT_seq::csv_n
\else
\expandafter\XINT_seq::csv_e
\fi
\expandafter{\the\numexpr #1+\xint_c_i}{#2},#1/1[0]%
}%
\def\XINT_seq::csv_e #1,{ }%
% \end{macrocode}
%\subsubsection{\csh{xintiiSeq::csv}}
% \begin{macrocode}
\def\xintiiSeq::csv {\romannumeral0\xintiiseq::csv }%
\def\xintiiseq::csv #1#2%
{%
\expandafter\XINT_iiseq::csv\expandafter
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}%
}%
\def\XINT_iiseq::csv #1#2%
{%
\ifcase\ifnum #1=#2 0\else\ifnum #2>#1 1\else -1\fi\fi\space
\expandafter\XINT_iiseq::csv_z
\or
\expandafter\XINT_iiseq::csv_p
\else
\expandafter\XINT_iiseq::csv_n
\fi
{#2}{#1}%
}%
\def\XINT_iiseq::csv_z #1#2{ #1}%
\def\XINT_iiseq::csv_p #1#2%
{%
\ifnum #1>#2
\expandafter\expandafter\expandafter\XINT_iiseq::csv_p
\else
\expandafter\XINT_seq::csv_e
\fi
\expandafter{\the\numexpr #1-\xint_c_i}{#2},#1%
}%
\def\XINT_iiseq::csv_n #1#2%
{%
\ifnum #1<#2
\expandafter\expandafter\expandafter\XINT_iiseq::csv_n
\else
\expandafter\XINT_seq::csv_e
\fi
\expandafter{\the\numexpr #1+\xint_c_i}{#2},#1%
}%
\def\XINT_seq::csv_e #1,{ }%
% \end{macrocode}
%\subsection{Macros for a..[d]..b list generation}
% \localtableofcontents
%
% \lverb|Contrarily to a..b which is limited to small integers, this works
% with a, b, and d (big) fractions. It will produce a «nil» list, if a>b and
% d<0 or a<b and d>0.|
%
%\subsubsection{\csh{xintSeqA::csv}, \csh{xintiiSeqA::csv}, \csh{XINTinFloatSeqA::csv}}
%
% \begin{macrocode}
\def\xintSeqA::csv #1%
{\expandafter\XINT_seqa::csv\expandafter{\romannumeral0\xintraw {#1}}}%
\def\XINT_seqa::csv #1#2{\expandafter\XINT_seqa::csv_a \romannumeral0\xintraw {#2};#1;}%
\def\xintiiSeqA::csv #1{\expandafter\XINT_iiseqa::csv\expandafter{\romannumeral`&&@#1}}%
\def\XINT_iiseqa::csv #1#2{\expandafter\XINT_seqa::csv_a\romannumeral`&&@#2;#1;}%
\def\XINTinFloatSeqA::csv #1{\expandafter\XINT_flseqa::csv\expandafter
{\romannumeral0\XINTinfloat [\XINTdigits]{#1}}}%
\def\XINT_flseqa::csv #1#2%
{\expandafter\XINT_seqa::csv_a\romannumeral0\XINTinfloat [\XINTdigits]{#2};#1;}%
\def\XINT_seqa::csv_a #1{\xint_UDzerominusfork
#1-{z}%
0#1{n}%
0-{p}%
\krof #1}%
% \end{macrocode}
%\subsubsection{\csh{xintSeqB::csv}}
% \lverb|With one year late documentation, let's just say, the #1 is
% \XINT_expr_unlock\.=Ua;b; with U=z or n or p, a=step, b=start.|
% \begin{macrocode}
\def\xintSeqB::csv #1#2%
{\expandafter\XINT_seqb::csv \expandafter{\romannumeral0\xintraw{#2}}{#1}}%
\def\XINT_seqb::csv #1#2{\expandafter\XINT_seqb::csv_a\romannumeral`&&@#2#1!}%
\def\XINT_seqb::csv_a #1#2;#3;#4!{\expandafter\XINT_expr_seq_empty?
\romannumeral0\csname XINT_seqb::csv_#1\endcsname {#3}{#4}{#2}}%
\def\XINT_seqb::csv_p #1#2#3%
{%
\xintifCmp {#1}{#2}{,#1\expandafter\XINT_seqb::csv_p\expandafter}%
{,#1\xint_gobble_iii}{\xint_gobble_iii}%
% \end{macrocode}
% \lverb|\romannumeral0 stopped by \endcsname, XINT_expr_seq_empty? constructs
% "nil".|
% \begin{macrocode}
{\romannumeral0\xintadd {#3}{#1}}{#2}{#3}%
}%
\def\XINT_seqb::csv_n #1#2#3%
{%
\xintifCmp {#1}{#2}{\xint_gobble_iii}{,#1\xint_gobble_iii}%
{,#1\expandafter\XINT_seqb::csv_n\expandafter}%
{\romannumeral0\xintadd {#3}{#1}}{#2}{#3}%
}%
\def\XINT_seqb::csv_z #1#2#3{,#1}%
% \end{macrocode}
%\subsubsection{\csh{xintiiSeqB::csv}}
% \begin{macrocode}
\def\xintiiSeqB::csv #1#2{\XINT_iiseqb::csv #1#2}%
\def\XINT_iiseqb::csv #1#2#3#4%
{\expandafter\XINT_iiseqb::csv_a
\romannumeral`&&@\expandafter \XINT_expr_unlock\expandafter#2%
\romannumeral`&&@\XINT_expr_unlock #4!}%
\def\XINT_iiseqb::csv_a #1#2;#3;#4!{\expandafter\XINT_expr_seq_empty?
\romannumeral`&&@\csname XINT_iiseqb::csv_#1\endcsname {#3}{#4}{#2}}%
\def\XINT_iiseqb::csv_p #1#2#3%
{%
\xintSgnFork{\XINT_Cmp {#1}{#2}}{,#1\expandafter\XINT_iiseqb::csv_p\expandafter}%
{,#1\xint_gobble_iii}{\xint_gobble_iii}%
{\romannumeral0\xintiiadd {#3}{#1}}{#2}{#3}%
}%
\def\XINT_iiseqb::csv_n #1#2#3%
{%
\xintSgnFork{\XINT_Cmp {#1}{#2}}{\xint_gobble_iii}{,#1\xint_gobble_iii}%
{,#1\expandafter\XINT_iiseqb::csv_n\expandafter}%
{\romannumeral0\xintiiadd {#3}{#1}}{#2}{#3}%
}%
\def\XINT_iiseqb::csv_z #1#2#3{,#1}%
% \end{macrocode}
%\subsubsection{\csh{XINTinFloatSeqB::csv}}
% \begin{macrocode}
\def\XINTinFloatSeqB::csv #1#2{\expandafter\XINT_flseqb::csv \expandafter
{\romannumeral0\XINTinfloat [\XINTdigits]{#2}}{#1}}%
\def\XINT_flseqb::csv #1#2{\expandafter\XINT_flseqb::csv_a\romannumeral`&&@#2#1!}%
\def\XINT_flseqb::csv_a #1#2;#3;#4!{\expandafter\XINT_expr_seq_empty?
\romannumeral`&&@\csname XINT_flseqb::csv_#1\endcsname {#3}{#4}{#2}}%
\def\XINT_flseqb::csv_p #1#2#3%
{%
\xintifCmp {#1}{#2}{,#1\expandafter\XINT_flseqb::csv_p\expandafter}%
{,#1\xint_gobble_iii}{\xint_gobble_iii}%
{\romannumeral0\XINTinfloatadd {#3}{#1}}{#2}{#3}%
}%
\def\XINT_flseqb::csv_n #1#2#3%
{%
\xintifCmp {#1}{#2}{\xint_gobble_iii}{,#1\xint_gobble_iii}%
{,#1\expandafter\XINT_flseqb::csv_n\expandafter}%
{\romannumeral0\XINTinfloatadd {#3}{#1}}{#2}{#3}%
}%
\def\XINT_flseqb::csv_z #1#2#3{,#1}%
% \end{macrocode}
% \subsection{The comma as binary operator}
% \lverb|New with 1.09a. Suffices to set its precedence level to two.|
% \begin{macrocode}
\def\XINT_tmpa #1#2#3#4#5#6%
{%
\def #1##1% \XINT_expr_op_,
{%
\expandafter #2\expandafter ##1\romannumeral`&&@\XINT_expr_getnext
}%
\def #2##1##2% \XINT_expr_until_,_a
{\xint_UDsignfork
##2{\expandafter #2\expandafter ##1\romannumeral`&&@#4}%
-{#3##1##2}%
\krof }%
\def #3##1##2##3##4% \XINT_expr_until_,_b
{%
\ifnum ##2>\xint_c_ii
\xint_afterfi {\expandafter #2\expandafter ##1\romannumeral`&&@%
\csname XINT_#6_op_##3\endcsname {##4}}%
\else
\xint_afterfi
{\expandafter ##2\expandafter ##3%
\csname .=\XINT_expr_unlock ##1,\XINT_expr_unlock ##4\endcsname }%
\fi
}%
\let #5\xint_c_ii
}%
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\XINT_tmpa
\csname XINT_#1_op_,\expandafter\endcsname
\csname XINT_#1_until_,_a\expandafter\endcsname
\csname XINT_#1_until_,_b\expandafter\endcsname
\csname XINT_#1_op_-vi\expandafter\endcsname
\csname XINT_expr_precedence_,\endcsname {#1}%
}%
% \end{macrocode}
% \subsection{The minus as prefix operator of variable precedence level}
% \lverb|Inherits the precedence level of the previous infix operator.|
% \begin{macrocode}
\def\XINT_tmpa #1#2#3%
{%
\expandafter\XINT_tmpb
\csname XINT_#1_op_-#3\expandafter\endcsname
\csname XINT_#1_until_-#3_a\expandafter\endcsname
\csname XINT_#1_until_-#3_b\expandafter\endcsname
\csname xint_c_#3\endcsname {#1}#2%
}%
\def\XINT_tmpb #1#2#3#4#5#6%
{%
\def #1% \XINT_expr_op_-<level>
{% get next number+operator then switch to _until macro
\expandafter #2\romannumeral`&&@\XINT_expr_getnext
}%
\def #2##1% \XINT_expr_until_-<l>_a
{\xint_UDsignfork
##1{\expandafter #2\romannumeral`&&@#1}%
-{#3##1}%
\krof }%
\def #3##1##2##3% \XINT_expr_until_-<l>_b
{% _until tests precedence level with next op, executes now or postpones
\ifnum ##1>#4%
\xint_afterfi {\expandafter #2\romannumeral`&&@%
\csname XINT_#5_op_##2\endcsname {##3}}%
\else
\xint_afterfi {\expandafter ##1\expandafter ##2%
\csname .=#6{\XINT_expr_unlock ##3}\endcsname }%
\fi
}%
}%
% \end{macrocode}
% \lverb|1.2d needs precedence 8 for *** and 9 for ^. Earlier, precedence
% level for ^ was only 8 but nevertheless the code did also "ix" here, which I
% think was unneeded back then.|
% \begin{macrocode}
\xintApplyInline{\XINT_tmpa {expr}\xintOpp}{{vi}{vii}{viii}{ix}}%
\xintApplyInline{\XINT_tmpa {flexpr}\xintOpp}{{vi}{vii}{viii}{ix}}%
\xintApplyInline{\XINT_tmpa {iiexpr}\xintiiOpp}{{vi}{vii}{viii}{ix}}%
% \end{macrocode}
% \subsection{? as two-way and ?? as three-way conditionals with braced branches}
% \lverb|In 1.1, I overload ? with ??, as : will be used for list extraction,
% problem with (stuff)?{?(1)}{0} for example, one should put a space (stuff)?{
% ?(1)}{0} will work. Small idiosyncrasy. (which has been removed in 1.2h,
% there is no problem anymore with (test)?{?(1)}{0}, however (test)?{?}{!}(x)
% is not accepted; but (test)?{?(x)}{!(x)} is or even with {?(}{!(}x).)
%
% syntax: ?{yes}{no} and ??{<0}{=0}{>0}.
%
% The difficulty is to recognize the second ? without removing braces as would
% be the case with standard parsing of operators. Hence the ? operator is
% intercepted in \XINT_expr_getop_b.
%
% 1.2h corrects a bug in \XINT_expr_op_? which in context like
% (test)?{\foo}{bar} would provoke expansion of \foo, or also with
% (test)?{}{bar} would result in an error. The fix also solves the
% (test)?{?(1)}{0} issue mentioned above.
% |
% \begin{macrocode}
\let\XINT_expr_precedence_? \xint_c_x
\def\XINT_expr_op_? #1#2%
{\XINT_expr_op_?checka #2!\xint_bye\XINT_expr_op_?a #1{#2}}%
\def\XINT_expr_op_?checka #1{\expandafter\XINT_expr_op_?checkb\detokenize{#1}}%
\def\XINT_expr_op_?checkb #1{\if ?#1\expandafter\XINT_expr_op_?checkc
\else\expandafter\xint_bye\fi }%
\def\XINT_expr_op_?checkc #1{\xint_gob_til_! #1\XINT_expr_op_?? !\xint_bye}%
\def\XINT_expr_op_?a #1#2#3%
{%
\xintiiifNotZero{\XINT_expr_unlock #1}{\XINT_expr_getnext #2}{\XINT_expr_getnext #3}%
}%
\let\XINT_flexpr_op_?\XINT_expr_op_?
\let\XINT_iiexpr_op_?\XINT_expr_op_?
\def\XINT_expr_op_?? !\xint_bye\xint_bye\XINT_expr_op_?a #1#2#3#4#5%
{%
\xintiiifSgn {\XINT_expr_unlock #1}%
{\XINT_expr_getnext #3}{\XINT_expr_getnext #4}{\XINT_expr_getnext #5}%
}%
% \end{macrocode}
% \subsection{! as postfix factorial operator}
% \lverb|A float version \xintFloatFac was at last done 2015/10/06 for 1.2.
% Attention 2015/11/29 for 1.2f: no more \xintFac, but \xintiFac.|
% \begin{macrocode}
\let\XINT_expr_precedence_! \xint_c_x
\def\XINT_expr_op_! #1{\expandafter\XINT_expr_getop
\csname .=\xintiFac{\XINT_expr_unlock #1}\endcsname }%
\def\XINT_flexpr_op_! #1{\expandafter\XINT_expr_getop
\csname .=\XINTinFloatFac{\XINT_expr_unlock #1}\endcsname }%
\def\XINT_iiexpr_op_! #1{\expandafter\XINT_expr_getop
\csname .=\xintiiFac{\XINT_expr_unlock #1}\endcsname }%
% \end{macrocode}
% \subsection{The A/B[N] mechanism}
% \lverb|Releases earlier than 1.1 required the use of braces around A/B[N]
% input. The [N] is now implemented directly. *BUT* this uses a delimited macro!
% thus N is not allowed to be itself an expression (I could add it...).
% \xintE, \xintiiE, and \XINTinFloatE all put #2 in a \numexpr. But attention
% to the fact that \numexpr stops at spaces separating digits:
% \the\numexpr 3 + 7 9\relax gives 109\relax !! Hence we have to be
% careful.
%
% \numexpr will not handle catcode 11 digits, but adding a \detokenize will
% suddenly make illicit for N to rely on macro expansion.|
% \begin{macrocode}
\catcode`[ 11
\catcode`* 11
\let\XINT_expr_precedence_[ \xint_c_vii
\def\XINT_expr_op_[ #1#2]{\expandafter\XINT_expr_getop
\csname .=\xintE{\XINT_expr_unlock #1}%
{\xint_zapspaces #2 \xint_gobble_i}\endcsname}%
\def\XINT_iiexpr_op_[ #1#2]{\expandafter\XINT_expr_getop
\csname .=\xintiiE{\XINT_expr_unlock #1}%
{\xint_zapspaces #2 \xint_gobble_i}\endcsname}%
\def\XINT_flexpr_op_[ #1#2]{\expandafter\XINT_expr_getop
\csname .=\XINTinFloatE{\XINT_expr_unlock #1}%
{\xint_zapspaces #2 \xint_gobble_i}\endcsname}%
\catcode`[ 12
\catcode`* 12
% \end{macrocode}
% \subsection{\csh{XINT_expr_op_`} for recognizing functions}
% \lverb|The "onlitteral" intercepts is for bool, togl, protect, ... but also
% for add, mul, seq, etc... Genuine functions have expr, iiexpr and
% flexpr versions (or only one or two of the three).
%
% With 1.2c "onlitteral" is also used to disambiguate variables from
% functions. However as I use only a \ifcsname test, in order to be able to
% re-define a variable as function, I move the check for being a function
% first. Each variable name now has its onlitteral_<name> associated macro
% which is the new way tacit multiplication in front of a parenthesis is
% implemented. This used to be decided much earlier at the time of
% \XINT_expr_func.
%
% The advantage of our choices for 1.2c is that the same name can be used for
% a variable or a function, the parser will apply the correct interpretation
% which is decided by the presence or not of an opening parenthesis next.|
% \begin{macrocode}
\def\XINT_tmpa #1#2#3{%
\def #1##1%
{%
\ifcsname XINT_#3_func_##1\endcsname
\xint_dothis{\expandafter\expandafter
\csname XINT_#3_func_##1\endcsname\romannumeral`&&@#2}\fi
\ifcsname XINT_expr_onlitteral_##1\endcsname
\xint_dothis{\csname XINT_expr_onlitteral_##1\endcsname}\fi
\xint_orthat{\XINT_expr_unknown_function {##1}%
\expandafter\XINT_expr_func_unknown\romannumeral`&&@#2}%
}%
}%
\def\XINT_expr_unknown_function #1{\xintError:removed \xint_gobble_i {#1}}%
\xintFor #1 in {expr,flexpr,iiexpr} \do {%
\expandafter\XINT_tmpa
\csname XINT_#1_op_`\expandafter\endcsname
\csname XINT_#1_oparen\endcsname
{#1}%
}%
\def\XINT_expr_func_unknown #1#2#3%
{\expandafter #1\expandafter #2\csname .=0\endcsname }%
% \end{macrocode}
% \subsection{The bool, togl, protect pseudo ``functions''}
% \lverb|bool, togl and protect use delimited macros. They are not true
% functions, they turn off the parser to gather their "variable".|
% \begin{macrocode}
\def\XINT_expr_onlitteral_bool #1)%
{\expandafter\XINT_expr_getop\csname .=\xintBool{#1}\endcsname }%
\def\XINT_expr_onlitteral_togl #1)%
{\expandafter\XINT_expr_getop\csname .=\xintToggle{#1}\endcsname }%
\def\XINT_expr_onlitteral_protect #1)%
{\expandafter\XINT_expr_getop\csname .=\detokenize{#1}\endcsname }%
% \end{macrocode}
% \subsection{The break function}
% \lverb|break is a true function, the parsing via expansion of the succeeding
% material proceeded via _oparen macros as with any other function.|
% \begin{macrocode}
\def\XINT_expr_func_break #1#2#3%
{\expandafter #1\expandafter #2\csname.=?\romannumeral`&&@\XINT_expr_unlock #3\endcsname }%
\let\XINT_flexpr_func_break \XINT_expr_func_break
\let\XINT_iiexpr_func_break \XINT_expr_func_break
% \end{macrocode}
% \subsection{The qint, qfrac, qfloat ``functions''}
% \lverb|New with 1.2. Allows the user to hand over quickly a big number to the
% parser, spaces not immediately removed but should be harmless in general.|
% \begin{macrocode}
\def\XINT_expr_onlitteral_qint #1)%
{\expandafter\XINT_expr_getop\csname .=\xintiNum{#1}\endcsname }%
\def\XINT_expr_onlitteral_qfrac #1)%
{\expandafter\XINT_expr_getop\csname .=\xintRaw{#1}\endcsname }%
\def\XINT_expr_onlitteral_qfloat #1)%
{\expandafter\XINT_expr_getop\csname .=\XINTinFloatdigits{#1}\endcsname }%
% \end{macrocode}
% \subsection{\csh{XINT_expr_op__} for recognizing variables}
% \lverb|The 1.1 mechanism for \XINT_expr_var_<varname> has been
% modified in 1.2c. The <varname> associated macro is now only expanded
% once, not twice. We arrive here via \XINT_expr_func.|
% \begin{macrocode}
\def\XINT_expr_op__ #1% op__ with two _'s
{%
\ifcsname XINT_expr_var_#1\endcsname
\expandafter\xint_firstoftwo
\else
\expandafter\xint_secondoftwo
\fi
{\expandafter\expandafter\expandafter
\XINT_expr_getop\csname XINT_expr_var_#1\endcsname}%
{\XINT_expr_unknown_variable {#1}%
\expandafter\XINT_expr_getop\csname .=0\endcsname}%
}%
\def\XINT_expr_unknown_variable #1{\xintError:removed \xint_gobble_i {#1}}%
\let\XINT_flexpr_op__ \XINT_expr_op__
\let\XINT_iiexpr_op__ \XINT_expr_op__
% \end{macrocode}
% \subsection{User defined variables: \csh{xintdefvar}, \csh{xintdefiivar}, \csh{xintdeffloatvar}}
% \lverb|1.1 An active : character will be a pain with our delimited macros and
% I almost decided not to use := but rather = as assignation operator, but this
% is the same problem inside expressions with the modulo operator /:, or with
% babel+frenchb with all high punctuation ?, !, :, ;.
%
% Variable names may contain letters, digits, underscores, and must not start
% with a digit. Names starting with @ or un underscore are reserved.
%
% Note (2015/11/11): although defined since october 2014 with 1.1, they were
% only very briefly mentioned in the user documentation, I should have
% expanded more. I am now adding functions to variables, and will rewrite
% entirely the documentation of xintexpr.sty.
%
% 1.2c adds the "onlitteral" macros as we changed our tricks to disambiguate
% variables from functions if followed by a parenthesis, in order to allow
% function names to have precedence on variable names.
%
% I don't issue warnings if a an attempt to define a variable name clashes
% with a pre-existing function name, as I would have to check expr, iiexpr and
% also floatexpr. And anyhow overloading a function name with a variable name
% is allowed, the only thing to know is that if an opening parenthesis follows
% it is the function meaning which prevails.
%
% 2015/11/13: I now first do an a priori complete expansion of #1, and
% then apply \detokenize to the result, and remove spaces.
%
% 2015/11/21: finally I do not detokenize the variable name. Because this
% complicated the \xintunassignvar if it did the same and we wanted to use it
% to redeclare a letter as dummy variable.
%
% Documentation of 1.2d said that the tacit multiplication always was done
% with increased precedence, but I had not at that time made up my mind for
% the case of variable(stuff) and pushed to CTAN early because I need to fix
% the bug I had introduced in 1.2c which itself I had pushed to CTAN early
% because I had to fix the 1.2 bug with subtraction....
%
% Finally I decide to do it indeed. Hence for 1.2e. This only impacts
% situations such as A/B(stuff), which are thus interpreted as A/(B*(stuff)).|
% \begin{macrocode}
\catcode`* 11
\def\XINT_expr_defvar #1#2#3;{%
\edef\XINT_expr_tmpa{#2}%
\edef\XINT_expr_tmpa {\xint_zapspaces_o\XINT_expr_tmpa}%
\ifnum\expandafter\xintLength\expandafter{\XINT_expr_tmpa}=\z@
\xintMessage {xintexpr}{Warning}
{Error: impossible to declare variable with empty name.}%
\else
\edef\XINT_expr_tmpb {\romannumeral0#1#3\relax }%
\expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname
{\expandafter\noexpand\XINT_expr_tmpb}%
\expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname
{\XINT_expr_precedence_*** *\expandafter\noexpand\XINT_expr_tmpb (}%
\ifxintverbose\xintMessage {xintexpr}{Info}
{Variable "\XINT_expr_tmpa" defined with value
\expandafter\XINT_expr_unlock\XINT_expr_tmpb.}%
\fi
\fi
}%
\catcode`* 12
\catcode`: 12
\def\xintdefvar #1:={\XINT_expr_defvar\xintbareeval {#1}}%
\def\xintdefiivar #1:={\XINT_expr_defvar\xintbareiieval {#1}}%
\def\xintdeffloatvar #1:={\XINT_expr_defvar\xintbarefloateval {#1}}%
\catcode`: 11
% \end{macrocode}
% \subsection{\csbh{xintunassignvar}}
% \lverb|1.2e. Currently not possible to genuinely ``undefine'' a
% variable, all we can do is to let it stand for zero and generate an
% error. The reason is that I chose to use \ifcsname tests in
% \XINT_expr_op__ and \XINT_expr_op_`.|
% \begin{macrocode}
\def\xintunassignvar #1{%
\edef\XINT_expr_tmpa{#1}%
\edef\XINT_expr_tmpa {\xint_zapspaces_o\XINT_expr_tmpa}%
\ifcsname XINT_expr_var_\XINT_expr_tmpa\endcsname
\ifnum\expandafter\xintLength\expandafter{\XINT_expr_tmpa}=\@ne
\expandafter\XINT_expr_makedummy \XINT_expr_tmpa
\ifxintverbose\xintMessage {xintexpr}{Info}
{Character \XINT_expr_tmpa\space usable as dummy variable (if letter).}%
\fi
\else
\expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname
{\csname .=0\endcsname\noexpand\XINT_expr_undefined {\XINT_expr_tmpa}}%
\expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname
{\csname .=0\endcsname\noexpand\XINT_expr_undefined {\XINT_expr_tmpa}*}%
\ifxintverbose\xintMessage {xintexpr}{Info}
{Variable \XINT_expr_tmpa\space has been ``unassigned''.}%
\fi
\fi
\else
\xintMessage {xintexpr}{Warning}
{Error: there was no such variable \XINT_expr_tmpa\space to unassign.}%
\fi
}%
\def\XINT_expr_undefined #1{\xintError:replaced_by_zero\xint_gobble_i {#1}}%
% \end{macrocode}
% \subsection{seq and the implementation of dummy variables}
% \localtableofcontents
% \lverb|All of seq, add, mul, rseq, etc... (actually all of the extensive
% changes from xintexpr 1.09n to 1.1) was done around June 15-25th 2014, but the
% problem is that I did not document the code enough, and I had a hard time
% understanding in October what I had done in June. Despite the lesson, again
% being short on time, I do not document enough my current understanding of the
% innards of the beast...
%
% I added subs, and iter in October (also the [:n], [n:] list extractors),
% proving I did at least understand a bit (or rather could imitate) my earlier
% code (but don't ask me to explain \xintNewExpr !)
%
% The \XINT_expr_onlitteral_seq_a parses: "expression, variable=list)"
% (when it is called the opening ( has been swallowed, and it looks for
% the ending one.) Both expression and list may themselves contain
% parentheses and commas, we allow nesting. For example "x^2,x=1..10)",
% at the end of seq_a we have {variable{expression}}{list}, in this
% example {x{x^2}}{1..10}, or more complicated
% "seq(add(y,y=1..x),x=1..10)" will work too. The variable is a single
% lowercase Latin letter.
%
% The complications with \xint_c_xviii in seq_f is for the recurrent
% thing that we don't know in what type of expressions we are, hence we
% must move back up, with some loss of efficiency (superfluous check for
% minus sign, etc...). But the code manages simultaneously expr, flexpr
% and iiexpr.|
%
% \subsubsection{All letters usable as dummy variables}
% \lverb|The nil variable was introduced in 1.1 but isn't used under that
% name. However macros handling a..[d]..b, or for seq with dummy variable
% where omit has omitted everyting may in practice inject a nil value as
% current number.
%
% 1.2c has changed the way variables are disambiguated from functions and for
% this it has added here the definitions of \XINT_expr_onlitteral_<name>.
%
% In 1.1 a letter variable say X was acting as a delimited macro looking for
% !X{stuff} and then would expand the stuff inside a \csname.=...\endcsname. I
% don't think I used the possibilities this opened and the 1.2c version has
% stuff _already_ encapsulated thus a single token. Only one expansion, not
% two is then needed in \XINT_expr_op__.
%
% I had to accordingly modify seq, add, mul and subs, but fortunately realized
% that the @, @1, etc... variables for rseq, rrseq and iter already had been
% defined in the way now also followed by the Latin letters as dummy
% variables.
%
% The 1.2e \XINT_expr_makedummy should not be used with multi-letter argument.
% The add, mul, seq, etc... can only work with one-letter long dummy variable.
% And this will almost certainly not change. Public interface is via
% \xintunassignvar which one can use with a letter to re-declare it as dummy
% variable. Also 1.2e does the tacit multiplication x(stuff)->x*(stuff) in its
% higher precedence form. Things are easy now that variables always fetch a
% single already locked value \.=<number>.
%
% The tacit multiplication in case of the ``nil'' variable doesn't make much
% sense but we do it anyhow.|
% \begin{macrocode}
\catcode`* 11
\def\XINT_expr_makedummy #1%
{%
\expandafter\def\csname XINT_expr_var_#1\endcsname ##1\relax !#1##2%
{##2##1\relax !#1##2}%
\expandafter\def\csname XINT_expr_onlitteral_#1\endcsname ##1\relax !#1##2%
{\XINT_expr_precedence_*** *##2(##1\relax !#1##2}%
}%
\xintApplyUnbraced \XINT_expr_makedummy {abcdefghijklmnopqrstuvwxyz}%
\xintApplyUnbraced \XINT_expr_makedummy {ABCDEFGHIJKLMNOPQRSTUVWXYZ}%
\edef\XINT_expr_var_nil {\expandafter\noexpand\csname .= \endcsname}%
\edef\XINT_expr_onlitteral_nil
{\XINT_expr_precedence_*** *\expandafter\noexpand\csname .= \endcsname (}%
\catcode`* 12
% \end{macrocode}
% \subsubsection{omit and abort}
% \lverb|& attention à ce & qui est de catcode 14 dans les \lverb
% June 24 and 25, 2014.
%
% Added comments 2015/11/13:
%
% Et la documentation ? on n'y comprend plus rien. Trop
% rusé.$newline
% \def\XINT_expr_var_omit #1\relax !{1^C!{}{}{}\.=!\relax !}$newline
% \def\XINT_expr_var_abort #1\relax !{1^C!{}{}{}\.=^\relax !}$newline
% C'était accompagné de \XINT_expr_precedence_^C=0 et d'un hack au sein même
% des macros until de plus bas niveau.
%
% Le mécanisme sioux était le suivant: ^C est déclaré comme un opérateur de
% précédence nulle. Lorsque le parseur trouve un "omit" dans un seq ou autre,
% il va insérer dans le stream \XINT_expr_getop suivi du texte de
% remplacement. Donc ici on avait un 1 comme place holder, puis l'opérateur
% ^C. Celui-ci étant de précédence zéro provoque la finalisation de tous les
% calculs antérieurs dans le sous-bareeval. Mais j'ai dû hacker le until_end_b
% (et le until_)_b) qui confronté à ^C, va se relancer à zéro, le getnext va
% trouver le !{}{}{}\.=! et ensuite il y aura \relax, et le résultat sera \.=!
% pour omit ou \.=^ pour abort. Les routines des boucles seq, iter, etc...
% peuvent alors repérer le ! ou ^ et agir en conséquence (un long paragraphe
% pour ne décrire que partiellement une ou deux lignes de codes...).
%
% Mais ^C a été fait alors que je n'avais pas encore les variables muettes. Je
% dois trouver autre chose, car seq(2^C, C=1..5) est alors impossible. De
% toute façon ce ^C était à usage interne uniquement.
%
% Il me faut un symbole d'opérateur qui ne rentre pas en conflit. Bon je vais
% prendre !?. Ensuite au lieu de hacker until_end, il vaut mieux lui donner
% précédence 2 (mais ça ne pourra pas marcher à l'intérieur de parenthèses il
% faut d'abord les fermer manuellement) et lui associer un simplement un op
% spécial. Je n'avais pas fait cela peut-être pour éviter d'avoir à définir
% plusieurs macros. Le #1 dans la définition de \XINT_expr_op_!? est le
% résultat de l'évaluation forcée précédente.
%
% Attention que les premier ! doiventt être de catcode 12 sinon ils
% signalent une sous-expression qui déclenche une multiplication tacite.
%
% |
% \begin{macrocode}
\edef\XINT_expr_var_omit #1\relax !{1\string !?!\relax !}%
\edef\XINT_expr_var_abort #1\relax !{1\string !?^\relax !}%
\def\XINT_expr_op_!? #1#2\relax {\expandafter\XINT_expr_foundend\csname .=#2\endcsname}%
\let\XINT_iiexpr_op_!? \XINT_expr_op_!?
\let\XINT_flexpr_op_!? \XINT_expr_op_!?
% \end{macrocode}
% \subsubsection{The special variables @, @1, @2, @3, @4, @@, @@(1), \dots, @@@,
% @@@(1), \dots for recursion}
% \lverb|October 2014: I had completely forgotten what the @@@ etc... stuff
% were supposed to do: this is for nesting recursions! (I was mad back in
% June). @@(N) gives the Nth back, @@@(N) gives the Nth back of the higher
% recursion!
%
% 1.2c adds the needed "onlitteral" now that tacit multiplication between a
% variable and a ( has a new mechanism. 1.2e does this tacit multiplication
% with higher precedence.
%
% For the record, the ~ has catcode 3 in this code.|
% \begin{macrocode}
\catcode`? 3 \catcode`* 11
\def\XINT_expr_var_@ #1~#2{#2#1~#2}%
\expandafter\let\csname XINT_expr_var_@1\endcsname \XINT_expr_var_@
\expandafter\def\csname XINT_expr_var_@2\endcsname #1~#2#3{#3#1~#2#3}%
\expandafter\def\csname XINT_expr_var_@3\endcsname #1~#2#3#4{#4#1~#2#3#4}%
\expandafter\def\csname XINT_expr_var_@4\endcsname #1~#2#3#4#5{#5#1~#2#3#4#5}%
\def\XINT_expr_onlitteral_@ #1~#2{\XINT_expr_precedence_*** *#2(#1~#2}%
\expandafter\let\csname XINT_expr_onlitteral_@1\endcsname \XINT_expr_onlitteral_@
\expandafter\def\csname XINT_expr_onlitteral_@2\endcsname #1~#2#3%
{\XINT_expr_precedence_*** *#3(#1~#2#3}%
\expandafter\def\csname XINT_expr_onlitteral_@3\endcsname #1~#2#3#4%
{\XINT_expr_precedence_*** *#4(#1~#2#3#4}%
\expandafter\def\csname XINT_expr_onlitteral_@4\endcsname #1~#2#3#4#5%
{\XINT_expr_precedence_*** *#5(#1~#2#3#4#5}%
\catcode`* 12
\def\XINT_expr_func_@@ #1#2#3#4~#5?%
{%
\expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand
{\xintNum{\XINT_expr_unlock#3}}{#5}#4~#5?%
}%
\def\XINT_expr_func_@@@ #1#2#3#4~#5~#6?%
{%
\expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand
{\xintNum{\XINT_expr_unlock#3}}{#6}#4~#5~#6?%
}%
\def\XINT_expr_func_@@@@ #1#2#3#4~#5~#6~#7?%
{%
\expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand
{\xintNum{\XINT_expr_unlock#3}}{#7}#4~#5~#6~#7?%
}%
\let\XINT_flexpr_func_@@\XINT_expr_func_@@
\let\XINT_flexpr_func_@@@\XINT_expr_func_@@@
\let\XINT_flexpr_func_@@@@\XINT_expr_func_@@@@
\def\XINT_iiexpr_func_@@ #1#2#3#4~#5?%
{%
\expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand
{\XINT_expr_unlock#3}{#5}#4~#5?%
}%
\def\XINT_iiexpr_func_@@@ #1#2#3#4~#5~#6?%
{%
\expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand
{\XINT_expr_unlock#3}{#6}#4~#5~#6?%
}%
\def\XINT_iiexpr_func_@@@@ #1#2#3#4~#5~#6~#7?%
{%
\expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand
{\XINT_expr_unlock#3}{#7}#4~#5~#6~#7?%
}%
\catcode`? 11
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_onlitteral_seq}}
% \begin{macrocode}
\def\XINT_expr_onlitteral_seq
{\expandafter\XINT_expr_onlitteral_seq_f\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}}%
\def\XINT_expr_onlitteral_seq_f #1#2{\xint_c_xviii `{seqx}#2)\relax #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_onlitteral_seq_a}}
% \begin{macrocode}
\def\XINT_expr_onlitteral_seq_a #1#2,%
{%
\ifcase\XINT_isbalanced_a \relax #1#2(\xint_bye)\xint_bye
\expandafter\XINT_expr_onlitteral_seq_c
\or\expandafter\XINT_expr_onlitteral_seq_b
\else\expandafter\xintError:we_are_doomed
\fi {#1#2},%
}%
\def\XINT_expr_onlitteral_seq_b #1,{\XINT_expr_onlitteral_seq_a {#1,}}%
\def\XINT_expr_onlitteral_seq_c #1,#2#3% #3 pour absorber le =
{%
\XINT_expr_onlitteral_seq_d {#2{#1}}{}%
}%
\def\XINT_expr_onlitteral_seq_d #1#2#3)%
{%
\ifcase\XINT_isbalanced_a \relax #2#3(\xint_bye)\xint_bye
\or\expandafter\XINT_expr_onlitteral_seq_e
\else\expandafter\xintError:we_are_doomed
\fi
{#1}{#2#3}%
}%
\def\XINT_expr_onlitteral_seq_e #1#2{\XINT_expr_onlitteral_seq_d {#1}{#2)}}%
% \end{macrocode}
% \subsubsection{\csh{XINT_isbalanced_a} for \csh{XINT_expr_onlitteral_seq_a}}
% \lverb|Expands to \xint_c_mone in case a closing ) had no opening ( matching
% it, to \@ne if opening ) had no closing ) matching it, to \z@ if expression
% was balanced.|
% \begin{macrocode}
% use as \XINT_isbalanced_a \relax #1(\xint_bye)\xint_bye
\def\XINT_isbalanced_a #1({\XINT_isbalanced_b #1)\xint_bye }%
\def\XINT_isbalanced_b #1)#2%
{\xint_bye #2\XINT_isbalanced_c\xint_bye\XINT_isbalanced_error }%
% \end{macrocode}
% \lverb|if #2 is not \xint_bye, a ) was found, but there was no (. Hence error -> -1|
% \begin{macrocode}
\def\XINT_isbalanced_error #1)\xint_bye {\xint_c_mone}%
% \end{macrocode}
% \lverb|#2 was \xint_bye, was there a ) in original #1?|
% \begin{macrocode}
\def\XINT_isbalanced_c\xint_bye\XINT_isbalanced_error #1%
{\xint_bye #1\XINT_isbalanced_yes\xint_bye\XINT_isbalanced_d #1}%
% \end{macrocode}
% \lverb|#1 is \xint_bye, there was never ( nor ) in original #1, hence OK.|
% \begin{macrocode}
\def\XINT_isbalanced_yes\xint_bye\XINT_isbalanced_d\xint_bye )\xint_bye {\xint_c_ }%
% \end{macrocode}
% \lverb|#1 is not \xint_bye, there was indeed a ( in original #1. We check if
% we see a ). If we do, we then loop until no ( nor ) is to be found.|
% \begin{macrocode}
\def\XINT_isbalanced_d #1)#2%
{\xint_bye #2\XINT_isbalanced_no\xint_bye\XINT_isbalanced_a #1#2}%
% \end{macrocode}
% \lverb|#2 was \xint_bye, we did not find a closing ) in original #1. Error.|
% \begin{macrocode}
\def\XINT_isbalanced_no\xint_bye #1\xint_bye\xint_bye {\xint_c_i }%
% \end{macrocode}
% \subsubsection{\csh{XINT_allexpr_func_seqx}}
% \lverb|1.2c uses \xintthebareval, ... which strangely were not available at
% 1.1 time. This spares some tokens from \XINT_expr_seq:_d and cousins. Also now
% variables have changed their mode of operation they pick only one token which
% must be an already encapsulated value.
%
% In \XINT_allexp_seqx, #2 is the list, evaluated and encapsulated, #3 is the
% dummy variable, #4 is the expression to evaluate repeatedly.
%
% A special case is a list generated by <variable>++: then #2 is {\.=+\.=<start>}.|
% \begin{macrocode}
\def\XINT_expr_func_seqx #1#2{\XINT_allexpr_seqx \xintthebareeval }%
\def\XINT_flexpr_func_seqx #1#2{\XINT_allexpr_seqx \xintthebarefloateval}%
\def\XINT_iiexpr_func_seqx #1#2{\XINT_allexpr_seqx \xintthebareiieval }%
\def\XINT_allexpr_seqx #1#2#3#4%
{%
\expandafter \XINT_expr_getop
\csname .=\expandafter\XINT_expr_seq:_aa
\romannumeral`&&@\XINT_expr_unlock #2!{#1#4\relax !#3}\endcsname
}%
\def\XINT_expr_seq:_aa #1{\if +#1\expandafter\XINT_expr_seq:_A\else
\expandafter\XINT_expr_seq:_a\fi #1}%
% \end{macrocode}
% \subsubsection{Evaluation over list, \csh{XINT_expr_seq:_a} with break,
% abort, omit}
% \lverb|The #2 here is \...bareeval <expression>\relax !<variable name>. The #1
% is a comma separated list of values to assign to the dummy variable. The
% \XINT_expr_seq_empty? intervenes immediately after handling of firstvalue.
%
% 1.2c has rewritten to a large extent this and other similar loops because
% the dummy variables now fetch a single encapsulated token (apart from a good
% means to lose a few hours needlessly -- as I have had to rewrite and review
% most everything, this change could make the thing more efficient if the same
% variable is used many times in an expression, but we are talking
% micro-seconds here anyhow.)|
% \begin{macrocode}
\def\XINT_expr_seq:_a #1!#2{\expandafter\XINT_expr_seq_empty?
\romannumeral0\XINT_expr_seq:_b {#2}#1,^,}%
\def\XINT_expr_seq:_b #1#2#3,{%
\if ,#2\xint_dothis\XINT_expr_seq:_noop\fi
\if ^#2\xint_dothis\XINT_expr_seq:_end\fi
\xint_orthat{\expandafter\XINT_expr_seq:_c}\csname.=#2#3\endcsname {#1}%
}%
\def\XINT_expr_seq:_noop\csname.=,#1\endcsname #2{\XINT_expr_seq:_b {#2}#1,}%
\def\XINT_expr_seq:_end \csname.=^\endcsname #1{}%
\def\XINT_expr_seq:_c #1#2{\expandafter\XINT_expr_seq:_d\romannumeral`&&@#2#1{#2}}%
\def\XINT_expr_seq:_d #1{\if #1^\xint_dothis\XINT_expr_seq:_abort\fi
\if #1?\xint_dothis\XINT_expr_seq:_break\fi
\if #1!\xint_dothis\XINT_expr_seq:_omit\fi
\xint_orthat{\XINT_expr_seq:_goon #1}}%
\def\XINT_expr_seq:_abort #1!#2#3#4#5^,{}%
\def\XINT_expr_seq:_break #1!#2#3#4#5^,{,#1}%
\def\XINT_expr_seq:_omit #1!#2#3#4{\XINT_expr_seq:_b {#4}}%
\def\XINT_expr_seq:_goon #1!#2#3#4{,#1\XINT_expr_seq:_b {#4}}%
% \end{macrocode}
% \lverb|If all is omitted or list is empty, _empty? will fetch within the ##1
% a \endcsname token and construct "nil" via <space>\endcsname, if not ##1
% will be a comma and the gobble will swallow the space token and the
% extra \endcsname.|
% \begin{macrocode}
\def\XINT_expr_seq_empty? #1{%
\def\XINT_expr_seq_empty? ##1{\if ,##1\expandafter\xint_gobble_i\fi #1\endcsname }}%
\XINT_expr_seq_empty? { }%
% \end{macrocode}
% \subsubsection{Evaluation over ++ generated lists with \csh{XINT_expr_seq:_A}}
% \lverb|This is for index lists generated by n++. The starting point will have
% been replaced by its ceil (added: in fact with version 1.1. the ceil was not
% yet evaluated, but _var_<letter> did an expansion of what they fetch). We use
% \numexpr rather than \xintInc, hence the indexing is limited to small
% integers.
%
% The 1.2c version of n++ produces a #1 here which is already a single
% \.=<value> token.|
% \begin{macrocode}
\def\XINT_expr_seq:_A +#1!%
{\expandafter\XINT_expr_seq_empty?\romannumeral0\XINT_expr_seq:_D #1}%
\def\XINT_expr_seq:_D #1#2{\expandafter\XINT_expr_seq:_E\romannumeral`&&@#2#1{#2}}%
\def\XINT_expr_seq:_E #1{\if #1^\xint_dothis\XINT_expr_seq:_Abort\fi
\if #1?\xint_dothis\XINT_expr_seq:_Break\fi
\if #1!\xint_dothis\XINT_expr_seq:_Omit\fi
\xint_orthat{\XINT_expr_seq:_Goon #1}}%
\def\XINT_expr_seq:_Abort #1!#2#3#4{}%
\def\XINT_expr_seq:_Break #1!#2#3#4{,#1}%
\def\XINT_expr_seq:_Omit #1!#2#3%
{\expandafter\XINT_expr_seq:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\endcsname}%
\def\XINT_expr_seq:_Goon #1!#2#3%
{,#1\expandafter\XINT_expr_seq:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\endcsname}%
% \end{macrocode}
% \subsection{add, mul}
% \lverb|1.2c uses more directly the \xintiiAdd etc... macros and has
% opxadd/opxmul rather than a single opx. This is less conceptual as I use
% explicitely the associated macro names for +, * but this makes other things
% more efficient, and the code more readable.|
% \begin{macrocode}
\def\XINT_expr_onlitteral_add
{\expandafter\XINT_expr_onlitteral_add_f\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}}%
\def\XINT_expr_onlitteral_add_f #1#2{\xint_c_xviii `{opxadd}#2)\relax #1}%
\def\XINT_expr_onlitteral_mul
{\expandafter\XINT_expr_onlitteral_mul_f\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}}%
\def\XINT_expr_onlitteral_mul_f #1#2{\xint_c_xviii `{opxmul}#2)\relax #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_func_opxadd}, \csh{XINT_flexpr_func_opxadd},
% \csh{XINT_iiexpr_func_opxadd} and same for mul}
% |modified 1.2c.|
% \begin{macrocode}
\def\XINT_expr_func_opxadd #1#2{\XINT_allexpr_opx \xintbareeval {\xintAdd 0}}%
\def\XINT_flexpr_func_opxadd #1#2{\XINT_allexpr_opx \xintbarefloateval {\XINTinFloatAdd 0}}%
\def\XINT_iiexpr_func_opxadd #1#2{\XINT_allexpr_opx \xintbareiieval {\xintiiAdd 0}}%
\def\XINT_expr_func_opxmul #1#2{\XINT_allexpr_opx \xintbareeval {\xintMul 1}}%
\def\XINT_flexpr_func_opxmul #1#2{\XINT_allexpr_opx \xintbarefloateval {\XINTinFloatMul 1}}%
\def\XINT_iiexpr_func_opxmul #1#2{\XINT_allexpr_opx \xintbareiieval {\xintiiMul 1}}%
% \end{macrocode}
% \lverb|#1=bareval etc, #2={Add0} ou {Mul1}, #3=liste encapsulée, #4=la variable, #5=expression|
% \begin{macrocode}
\def\XINT_allexpr_opx #1#2#3#4#5%
{%
\expandafter\XINT_expr_getop
\csname.=\romannumeral`&&@\expandafter\XINT_expr_op:_a
\romannumeral`&&@\XINT_expr_unlock #3!{#1#5\relax !#4}{#2}\endcsname
}%
\def\XINT_expr_op:_a #1!#2#3{\XINT_expr_op:_b #3{#2}#1,^,}%
% \end{macrocode}
% \lverb|#2 in \XINT_expr_op:_b is the partial result of computation so far, not
% locked. A noop with have #4=, and #5 the next item which we need to recover.
% No need to be very efficient for that in op:_noop. In op:_d, #4 is \xintAdd or
% similar.|
% \begin{macrocode}
\def\XINT_expr_op:_b #1#2#3#4#5,{%
\if ,#4\xint_dothis\XINT_expr_op:_noop\fi
\if ^#4\xint_dothis\XINT_expr_op:_end\fi
\xint_orthat{\expandafter\XINT_expr_op:_c}\csname.=#4#5\endcsname {#3}#1{#2}%
}%
\def\XINT_expr_op:_c #1#2#3#4{\expandafter\XINT_expr_op:_d\romannumeral0#2#1#3{#4}{#2}}%
\def\XINT_expr_op:_d #1!#2#3#4#5%
{\expandafter\XINT_expr_op:_b\expandafter #4\expandafter
{\romannumeral`&&@#4{\XINT_expr_unlock#1}{#5}}}%
% \end{macrocode}
% \lverb|The replacement text had expr_seq:_b rather than expr_op:_b due to a
% left-over from copy-paste. This made add and mul fail with an empty range
% for the variable (or "nil" in the list of values). Fixed in 1.2h.|
% \begin{macrocode}
\def\XINT_expr_op:_noop\csname.=,#1\endcsname #2#3#4{\XINT_expr_op:_b #3{#4}{#2}#1,}%
\def\XINT_expr_op:_end \csname.=^\endcsname #1#2#3{#3}%
% \end{macrocode}
% \subsection{subs}
% \lverb|Got simpler with 1.2c as now the dummy variable fetches an
% already encapsulated value, which is anyhow the form in which we get
% it.|
% \begin{macrocode}
\def\XINT_expr_onlitteral_subs
{\expandafter\XINT_expr_onlitteral_subs_f\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}}%
\def\XINT_expr_onlitteral_subs_f #1#2{\xint_c_xviii `{subx}#2)\relax #1}%
\def\XINT_expr_func_subx #1#2{\XINT_allexpr_subx \xintbareeval }%
\def\XINT_flexpr_func_subx #1#2{\XINT_allexpr_subx \xintbarefloateval}%
\def\XINT_iiexpr_func_subx #1#2{\XINT_allexpr_subx \xintbareiieval }%
\def\XINT_allexpr_subx #1#2#3#4% #2 is the value to assign to the dummy variable
{% #3 is the dummy variable, #4 is the expression to evaluate
\expandafter\expandafter\expandafter\XINT_expr_getop
\expandafter\XINT_expr_subx:_end\romannumeral0#1#4\relax !#3#2%
}%
\def\XINT_expr_subx:_end #1!#2#3{#1}%
% \end{macrocode}
% \subsection{rseq}
% \localtableofcontents
%
% \lverb|When func_rseq has its turn, initial segment has been scanned by
% oparen, the ; mimicking the rôle of a closing parenthesis, and stopping
% further expansion. Notice that the ; is discovered during standard parsing
% mode, it may be for example {;} or arise from expansion as rseq does not use
% a delimited macro to locate it.
%
% Here and in rrseq and iter, 1.2c adds also use of \xintthebareeval, etc...|
% \begin{macrocode}
\def\XINT_expr_func_rseq {\XINT_allexpr_rseq \xintbareeval \xintthebareeval }%
\def\XINT_flexpr_func_rseq {\XINT_allexpr_rseq \xintbarefloateval \xintthebarefloateval }%
\def\XINT_iiexpr_func_rseq {\XINT_allexpr_rseq \xintbareiieval \xintthebareiieval }%
\def\XINT_allexpr_rseq #1#2#3%
{%
\expandafter\XINT_expr_rseqx\expandafter #1\expandafter#2\expandafter
#3\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rseqx}}
% \lverb|The (#5) is for ++ mechanism which must have its closing parenthesis.|
% \begin{macrocode}
\def\XINT_expr_rseqx #1#2#3#4#5%
{%
\expandafter\XINT_expr_rseqy\romannumeral0#1(#5)\relax #3#4#2%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rseqy}}
% \lverb|#1=valeurs pour variable (locked),
% #2=toutes les valeurs initiales (csv,locked),
% #3=variable, #4=expr,
% #5=\xintthebareeval ou \xintthebarefloateval ou \xintthebareiieval|
% \begin{macrocode}
\def\XINT_expr_rseqy #1#2#3#4#5%
{%
\expandafter \XINT_expr_getop
\csname .=\XINT_expr_unlock #2%
\expandafter\XINT_expr_rseq:_aa
\romannumeral`&&@\XINT_expr_unlock #1!{#5#4\relax !#3}#2\endcsname
}%
\def\XINT_expr_rseq:_aa #1{\if +#1\expandafter\XINT_expr_rseq:_A\else
\expandafter\XINT_expr_rseq:_a\fi #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rseq:_a} etc\dots}
% \begin{macrocode}
\def\XINT_expr_rseq:_a #1!#2#3{\XINT_expr_rseq:_b {#3}{#2}#1,^,}%
\def\XINT_expr_rseq:_b #1#2#3#4,{%
\if ,#3\xint_dothis\XINT_expr_rseq:_noop\fi
\if ^#3\xint_dothis\XINT_expr_rseq:_end\fi
\xint_orthat{\expandafter\XINT_expr_rseq:_c}\csname.=#3#4\endcsname
{#1}{#2}%
}%
\def\XINT_expr_rseq:_noop\csname.=,#1\endcsname #2#3{\XINT_expr_rseq:_b {#2}{#3}#1,}%
\def\XINT_expr_rseq:_end \csname.=^\endcsname #1#2{}%
\def\XINT_expr_rseq:_c #1#2#3%
{\expandafter\XINT_expr_rseq:_d\romannumeral`&&@#3#1~#2{#3}}%
\def\XINT_expr_rseq:_d #1{%
\if ^#1\xint_dothis\XINT_expr_rseq:_abort\fi
\if ?#1\xint_dothis\XINT_expr_rseq:_break\fi
\if !#1\xint_dothis\XINT_expr_rseq:_omit\fi
\xint_orthat{\XINT_expr_rseq:_goon #1}}%
\def\XINT_expr_rseq:_goon #1!#2#3~#4#5{,#1\expandafter\XINT_expr_rseq:_b
\romannumeral0\XINT_expr_lockit {#1}{#5}}%
\def\XINT_expr_rseq:_omit #1!#2#3~{\XINT_expr_rseq:_b }%
\def\XINT_expr_rseq:_abort #1!#2#3~#4#5#6^,{}%
\def\XINT_expr_rseq:_break #1!#2#3~#4#5#6^,{,#1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rseq:_A} etc\dots}
% \lverb |n++ for rseq. With 1.2c dummy variables pick a single token.|
% \begin{macrocode}
\def\XINT_expr_rseq:_A +#1!#2#3{\XINT_expr_rseq:_D #1#3{#2}}%
\def\XINT_expr_rseq:_D #1#2#3%
{\expandafter\XINT_expr_rseq:_E\romannumeral`&&@#3#1~#2{#3}}%
\def\XINT_expr_rseq:_E #1{\if #1^\xint_dothis\XINT_expr_rseq:_Abort\fi
\if #1?\xint_dothis\XINT_expr_rseq:_Break\fi
\if #1!\xint_dothis\XINT_expr_rseq:_Omit\fi
\xint_orthat{\XINT_expr_rseq:_Goon #1}}%
\def\XINT_expr_rseq:_Goon #1!#2#3~#4#5%
{,#1\expandafter\XINT_expr_rseq:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\expandafter\endcsname
\romannumeral0\XINT_expr_lockit{#1}{#5}}%
\def\XINT_expr_rseq:_Omit #1!#2#3~%#4#5%
{\expandafter\XINT_expr_rseq:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\endcsname }%
\def\XINT_expr_rseq:_Abort #1!#2#3~#4#5{}%
\def\XINT_expr_rseq:_Break #1!#2#3~#4#5{,#1}%
% \end{macrocode}
% \subsection{iter}
% \localtableofcontents
%
% \lverb|Prior to 1.2g, the iter keyword was what is now called iterr,
% analogous with rrseq. Somehow I forgot an iter functioning like rseq
% with the sole difference of printing only the last iteration. Both rseq and
% iter work well with list selectors, as @ refers to the whole comma separated
% sequence of the initial values. I have thus deliberately done the backwards
% incompatible renaming of iter to iterr, and the new iter.|
% \begin{macrocode}
\def\XINT_expr_func_iter {\XINT_allexpr_iter \xintbareeval \xintthebareeval }%
\def\XINT_flexpr_func_iter {\XINT_allexpr_iter \xintbarefloateval \xintthebarefloateval }%
\def\XINT_iiexpr_func_iter {\XINT_allexpr_iter \xintbareiieval \xintthebareiieval }%
\def\XINT_allexpr_iter #1#2#3%
{%
\expandafter\XINT_expr_iterx\expandafter #1\expandafter#2\expandafter
#3\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iterx}}
% \lverb|The (#5) is for ++ mechanism which must have its closing parenthesis.|
% \begin{macrocode}
\def\XINT_expr_iterx #1#2#3#4#5%
{%
\expandafter\XINT_expr_itery\romannumeral0#1(#5)\relax #3#4#2%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_itery}}
% \lverb|#1=valeurs pour variable (locked),
% #2=toutes les valeurs initiales (csv,locked),
% #3=variable, #4=expr,
% #5=\xintthebareeval ou \xintthebarefloateval ou \xintthebareiieval|
% \begin{macrocode}
\def\XINT_expr_itery #1#2#3#4#5%
{%
\expandafter \XINT_expr_getop
\csname .=%
\expandafter\XINT_expr_iter:_aa
\romannumeral`&&@\XINT_expr_unlock #1!{#5#4\relax !#3}#2\endcsname
}%
\def\XINT_expr_iter:_aa #1{\if +#1\expandafter\XINT_expr_iter:_A\else
\expandafter\XINT_expr_iter:_a\fi #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iter:_a} etc\dots}
% \begin{macrocode}
\def\XINT_expr_iter:_a #1!#2#3{\XINT_expr_iter:_b {#3}{#2}#1,^,}%
\def\XINT_expr_iter:_b #1#2#3#4,{%
\if ,#3\xint_dothis\XINT_expr_iter:_noop\fi
\if ^#3\xint_dothis\XINT_expr_iter:_end\fi
\xint_orthat{\expandafter\XINT_expr_iter:_c}%
\csname.=#3#4\endcsname {#1}{#2}%
}%
\def\XINT_expr_iter:_noop\csname.=,#1\endcsname #2#3{\XINT_expr_iter:_b {#2}{#3}#1,}%
\def\XINT_expr_iter:_end \csname.=^\endcsname #1#2{\XINT_expr:_unlock #1}%
\def\XINT_expr_iter:_c #1#2#3%
{\expandafter\XINT_expr_iter:_d\romannumeral`&&@#3#1~#2{#3}}%
\def\XINT_expr_iter:_d #1{%
\if ^#1\xint_dothis\XINT_expr_iter:_abort\fi
\if ?#1\xint_dothis\XINT_expr_iter:_break\fi
\if !#1\xint_dothis\XINT_expr_iter:_omit\fi
\xint_orthat{\XINT_expr_iter:_goon #1}}%
\def\XINT_expr_iter:_goon #1!#2#3~#4#5%
{\expandafter\XINT_expr_iter:_b\romannumeral0\XINT_expr_lockit {#1}{#5}}%
\def\XINT_expr_iter:_omit #1!#2#3~{\XINT_expr_iter:_b }%
\def\XINT_expr_iter:_abort #1!#2#3~#4#5#6^,{\XINT_expr_unlock #4}%
\def\XINT_expr_iter:_break #1!#2#3~#4#5#6^,{#1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iter:_A} etc\dots}
% \lverb |n++ for iter. With 1.2c dummy variables pick a single token.|
% \begin{macrocode}
\def\XINT_expr_iter:_A +#1!#2#3{\XINT_expr_iter:_D #1#3{#2}}%
\def\XINT_expr_iter:_D #1#2#3%
{\expandafter\XINT_expr_iter:_E\romannumeral`&&@#3#1~#2{#3}}%
\def\XINT_expr_iter:_E #1{\if #1^\xint_dothis\XINT_expr_iter:_Abort\fi
\if #1?\xint_dothis\XINT_expr_iter:_Break\fi
\if #1!\xint_dothis\XINT_expr_iter:_Omit\fi
\xint_orthat{\XINT_expr_iter:_Goon #1}}%
\def\XINT_expr_iter:_Goon #1!#2#3~#4#5%
{\expandafter\XINT_expr_iter:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\expandafter\endcsname
\romannumeral0\XINT_expr_lockit{#1}{#5}}%
\def\XINT_expr_iter:_Omit #1!#2#3~%#4#5%
{\expandafter\XINT_expr_iter:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\endcsname }%
\def\XINT_expr_iter:_Abort #1!#2#3~#4#5{\XINT_expr:_unlock #4}%
\def\XINT_expr_iter:_Break #1!#2#3~#4#5{#1}%
% \end{macrocode}
% \subsection{rrseq}
% \localtableofcontents
%
% \lverb|When func_rrseq has its turn, initial segment has been scanned
% by oparen, the ; mimicking the rôle of a closing parenthesis, and
% stopping further expansion.|
% \begin{macrocode}
\def\XINT_expr_func_rrseq {\XINT_allexpr_rrseq \xintbareeval \xintthebareeval }%
\def\XINT_flexpr_func_rrseq {\XINT_allexpr_rrseq \xintbarefloateval \xintthebarefloateval }%
\def\XINT_iiexpr_func_rrseq {\XINT_allexpr_rrseq \xintbareiieval \xintthebareiieval }%
\def\XINT_allexpr_rrseq #1#2#3%
{%
\expandafter\XINT_expr_rrseqx\expandafter #1\expandafter#2\expandafter
#3\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rrseqx}}
% \lverb|The (#5) is for ++ mechanism which must have its closing parenthesis.|
% \begin{macrocode}
\def\XINT_expr_rrseqx #1#2#3#4#5%
{%
\expandafter\XINT_expr_rrseqy\romannumeral0#1(#5)\expandafter\relax
\expandafter{\romannumeral0\xintapply \XINT_expr_lockit
{\xintRevWithBraces{\xintCSVtoListNonStripped{\XINT_expr_unlock #3}}}}%
#3#4#2%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rrseqy}}
% \lverb|#1=valeurs pour variable (locked),
% #2=initial values (reversed, one (braced) token each)
% #3=toutes les valeurs initiales (csv,locked),
% #4=variable, #5=expr,
% #6=\xintthebareeval ou \xintthebarefloateval ou \xintthebareiieval|
% \begin{macrocode}
\def\XINT_expr_rrseqy #1#2#3#4#5#6%
{%
\expandafter \XINT_expr_getop
\csname .=\XINT_expr_unlock #3%
\expandafter\XINT_expr_rrseq:_aa
\romannumeral`&&@\XINT_expr_unlock #1!{#6#5\relax !#4}{#2}\endcsname
}%
\def\XINT_expr_rrseq:_aa #1{\if +#1\expandafter\XINT_expr_rrseq:_A\else
\expandafter\XINT_expr_rrseq:_a\fi #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rrseq:_a} etc\dots}
% \lverb|Attention que ? a catcode 3 ici et dans iter.|
% \begin{macrocode}
\catcode`? 3
\def\XINT_expr_rrseq:_a #1!#2#3{\XINT_expr_rrseq:_b {#3}{#2}#1,^,}%
\def\XINT_expr_rrseq:_b #1#2#3#4,{%
\if ,#3\xint_dothis\XINT_expr_rrseq:_noop\fi
\if ^#3\xint_dothis\XINT_expr_rrseq:_end\fi
\xint_orthat{\expandafter\XINT_expr_rrseq:_c}\csname.=#3#4\endcsname
{#1}{#2}%
}%
\def\XINT_expr_rrseq:_noop\csname.=,#1\endcsname #2#3{\XINT_expr_rrseq:_b {#2}{#3}#1,}%
\def\XINT_expr_rrseq:_end \csname.=^\endcsname #1#2{}%
\def\XINT_expr_rrseq:_c #1#2#3%
{\expandafter\XINT_expr_rrseq:_d\romannumeral`&&@#3#1~#2?{#3}}%
\def\XINT_expr_rrseq:_d #1{%
\if ^#1\xint_dothis\XINT_expr_rrseq:_abort\fi
\if ?#1\xint_dothis\XINT_expr_rrseq:_break\fi
\if !#1\xint_dothis\XINT_expr_rrseq:_omit\fi
\xint_orthat{\XINT_expr_rrseq:_goon #1}%
}%
\def\XINT_expr_rrseq:_goon #1!#2#3~#4?#5{,#1\expandafter\XINT_expr_rrseq:_b\expandafter
{\romannumeral0\xinttrim{-1}{\XINT_expr_lockit{#1}#4}}{#5}}%
\def\XINT_expr_rrseq:_omit #1!#2#3~{\XINT_expr_rrseq:_b }%
\def\XINT_expr_rrseq:_abort #1!#2#3~#4?#5#6^,{}%
\def\XINT_expr_rrseq:_break #1!#2#3~#4?#5#6^,{,#1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_rrseq:_A} etc\dots}
% \lverb |n++ for rrseq. With 1.2C, the #1 in \XINT_expr_rrseq:_A is a single token.|
% \begin{macrocode}
\def\XINT_expr_rrseq:_A +#1!#2#3{\XINT_expr_rrseq:_D #1{#3}{#2}}%
\def\XINT_expr_rrseq:_D #1#2#3%
{\expandafter\XINT_expr_rrseq:_E\romannumeral`&&@#3#1~#2?{#3}}%
\def\XINT_expr_rrseq:_Goon #1!#2#3~#4?#5%
{,#1\expandafter\XINT_expr_rrseq:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\expandafter\endcsname
\expandafter{\romannumeral0\xinttrim{-1}{\XINT_expr_lockit{#1}#4}}{#5}}%
\def\XINT_expr_rrseq:_Omit #1!#2#3~%#4?#5%
{\expandafter\XINT_expr_rrseq:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\endcsname}%
\def\XINT_expr_rrseq:_Abort #1!#2#3~#4?#5{}%
\def\XINT_expr_rrseq:_Break #1!#2#3~#4?#5{,#1}%
\def\XINT_expr_rrseq:_E #1{\if #1^\xint_dothis\XINT_expr_rrseq:_Abort\fi
\if #1?\xint_dothis\XINT_expr_rrseq:_Break\fi
\if #1!\xint_dothis\XINT_expr_rrseq:_Omit\fi
\xint_orthat{\XINT_expr_rrseq:_Goon #1}}%
% \end{macrocode}
% \subsection{iterr}
% \localtableofcontents
% \begin{macrocode}
\def\XINT_expr_func_iterr {\XINT_allexpr_iterr \xintbareeval \xintthebareeval }%
\def\XINT_flexpr_func_iterr {\XINT_allexpr_iterr \xintbarefloateval \xintthebarefloateval }%
\def\XINT_iiexpr_func_iterr {\XINT_allexpr_iterr \xintbareiieval \xintthebareiieval }%
\def\XINT_allexpr_iterr #1#2#3%
{%
\expandafter\XINT_expr_iterrx\expandafter #1\expandafter #2\expandafter
#3\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iterrx}}
% \lverb|The (#5) is for ++ mechanism which must have its closing parenthesis.|
% \begin{macrocode}
\def\XINT_expr_iterrx #1#2#3#4#5%
{%
\expandafter\XINT_expr_iterry\romannumeral0#1(#5)\expandafter\relax
\expandafter{\romannumeral0\xintapply \XINT_expr_lockit
{\xintRevWithBraces{\xintCSVtoListNonStripped{\XINT_expr_unlock #3}}}}%
#3#4#2%
}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iterry}}
% \lverb|#1=valeurs pour variable (locked),
% #2=initial values (reversed, one (braced) token each)
% #3=toutes les valeurs initiales (csv,locked),
% #4=variable, #5=expr,
% #6=\xintbareeval ou \xintbarefloateval ou \xintbareiieval|
% \begin{macrocode}
\def\XINT_expr_iterry #1#2#3#4#5#6%
{%
\expandafter \XINT_expr_getop
\csname .=%
\expandafter\XINT_expr_iterr:_aa
\romannumeral`&&@\XINT_expr_unlock #1!{#6#5\relax !#4}{#2}\endcsname
}%
\def\XINT_expr_iterr:_aa #1{\if +#1\expandafter\XINT_expr_iterr:_A\else
\expandafter\XINT_expr_iterr:_a\fi #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iterr:_a} etc\dots}
% \begin{macrocode}
\def\XINT_expr_iterr:_a #1!#2#3{\XINT_expr_iterr:_b {#3}{#2}#1,^,}%
\def\XINT_expr_iterr:_b #1#2#3#4,{%
\if ,#3\xint_dothis\XINT_expr_iterr:_noop\fi
\if ^#3\xint_dothis\XINT_expr_iterr:_end\fi
\xint_orthat{\expandafter\XINT_expr_iterr:_c}%
\csname.=#3#4\endcsname {#1}{#2}%
}%
\def\XINT_expr_iterr:_noop\csname.=,#1\endcsname #2#3{\XINT_expr_iterr:_b {#2}{#3}#1,}%
\def\XINT_expr_iterr:_end \csname.=^\endcsname #1#2%
{\expandafter\xint_gobble_i\romannumeral0\xintapplyunbraced
{,\XINT_expr:_unlock}{\xintReverseOrder{#1\space}}}%
\def\XINT_expr_iterr:_c #1#2#3%
{\expandafter\XINT_expr_iterr:_d\romannumeral`&&@#3#1~#2?{#3}}%
\def\XINT_expr_iterr:_d #1{%
\if ^#1\xint_dothis\XINT_expr_iterr:_abort\fi
\if ?#1\xint_dothis\XINT_expr_iterr:_break\fi
\if !#1\xint_dothis\XINT_expr_iterr:_omit\fi
\xint_orthat{\XINT_expr_iterr:_goon #1}%
}%
\def\XINT_expr_iterr:_goon #1!#2#3~#4?#5{\expandafter\XINT_expr_iterr:_b\expandafter
{\romannumeral0\xinttrim{-1}{\XINT_expr_lockit{#1}#4}}{#5}}%
\def\XINT_expr_iterr:_omit #1!#2#3~{\XINT_expr_iterr:_b }%
\def\XINT_expr_iterr:_abort #1!#2#3~#4?#5#6^,%
{\expandafter\xint_gobble_i\romannumeral0\xintapplyunbraced
{,\XINT_expr:_unlock}{\xintReverseOrder{#4\space}}}%
\def\XINT_expr_iterr:_break #1!#2#3~#4?#5#6^,%
{\expandafter\xint_gobble_iv\romannumeral0\xintapplyunbraced
{,\XINT_expr:_unlock}{\xintReverseOrder{#4\space}},#1}%
\def\XINT_expr:_unlock #1{\XINT_expr_unlock #1}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_iterr:_A} etc\dots}
% \lverb |n++ for iterr. ? is of catcode 3 here.|
% \begin{macrocode}
\def\XINT_expr_iterr:_A +#1!#2#3{\XINT_expr_iterr:_D #1{#3}{#2}}%
\def\XINT_expr_iterr:_D #1#2#3%
{\expandafter\XINT_expr_iterr:_E\romannumeral`&&@#3#1~#2?{#3}}%
\def\XINT_expr_iterr:_Goon #1!#2#3~#4?#5%
{\expandafter\XINT_expr_iterr:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\expandafter\endcsname
\expandafter{\romannumeral0\xinttrim{-1}{\XINT_expr_lockit{#1}#4}}{#5}}%
\def\XINT_expr_iterr:_Omit #1!#2#3~%#4?#5%
{\expandafter\XINT_expr_iterr:_D
\csname.=\the\numexpr \XINT_expr_unlock#3+\xint_c_i\endcsname}%
\def\XINT_expr_iterr:_Abort #1!#2#3~#4?#5%
{\expandafter\xint_gobble_i\romannumeral0\xintapplyunbraced
{,\XINT_expr:_unlock}{\xintReverseOrder{#4\space}}}%
\def\XINT_expr_iterr:_Break #1!#2#3~#4?#5%
{\expandafter\xint_gobble_iv\romannumeral0\xintapplyunbraced
{,\XINT_expr:_unlock}{\xintReverseOrder{#4\space}},#1}%
\def\XINT_expr_iterr:_E #1{\if #1^\xint_dothis\XINT_expr_iterr:_Abort\fi
\if #1?\xint_dothis\XINT_expr_iterr:_Break\fi
\if #1!\xint_dothis\XINT_expr_iterr:_Omit\fi
\xint_orthat{\XINT_expr_iterr:_Goon #1}}%
\catcode`? 11
% \end{macrocode}
% \subsection{Macros handling csv lists for functions with multiple comma
% separated arguments in expressions}
% \localtableofcontents
% \lverb|These macros are used inside \csname...\endcsname. These things
% are not initiated by a \romannumeral in general, but in some cases they are,
% especially when involved in an \xintNewExpr. They will then be protected
% against expansion and expand only later in contexts governed by an
% initial \romannumeral-`0. There each new item may need to be expanded, which
% would not be the case in the use for the _func_ things.
%
% 1.2g adds (to be continued)|
%
% \subsubsection{\csh{xintANDof:csv}}
% \lverb|1.09a. For use by \xintexpr inside \csname. 1.1, je remplace
% ifTrueAelseB par iiNotZero pour des raisons d'optimisations.|
% \begin{macrocode}
\def\xintANDof:csv #1{\expandafter\XINT_andof:_a\romannumeral`&&@#1,,^}%
\def\XINT_andof:_a #1{\if ,#1\expandafter\XINT_andof:_e
\else\expandafter\XINT_andof:_c\fi #1}%
\def\XINT_andof:_c #1,{\xintiiifNotZero {#1}{\XINT_andof:_a}{\XINT_andof:_no}}%
\def\XINT_andof:_no #1^{0}%
\def\XINT_andof:_e #1^{1}% works with empty list
% \end{macrocode}
% \subsubsection{\csh{xintORof:csv}}
% \lverb|1.09a. For use by \xintexpr.|
% \begin{macrocode}
\def\xintORof:csv #1{\expandafter\XINT_orof:_a\romannumeral`&&@#1,,^}%
\def\XINT_orof:_a #1{\if ,#1\expandafter\XINT_orof:_e
\else\expandafter\XINT_orof:_c\fi #1}%
\def\XINT_orof:_c #1,{\xintiiifNotZero{#1}{\XINT_orof:_yes}{\XINT_orof:_a}}%
\def\XINT_orof:_yes #1^{1}%
\def\XINT_orof:_e #1^{0}% works with empty list
% \end{macrocode}
% \subsubsection{\csh{xintXORof:csv}}
% \lverb|1.09a. For use by \xintexpr (inside a \csname..\endcsname).|
% \begin{macrocode}
\def\xintXORof:csv #1{\expandafter\XINT_xorof:_a\expandafter 0\romannumeral`&&@#1,,^}%
\def\XINT_xorof:_a #1#2,{\XINT_xorof:_b #2,#1}%
\def\XINT_xorof:_b #1{\if ,#1\expandafter\XINT_xorof:_e
\else\expandafter\XINT_xorof:_c\fi #1}%
\def\XINT_xorof:_c #1,#2%
{\xintiiifNotZero {#1}{\if #20\xint_afterfi{\XINT_xorof:_a 1}%
\else\xint_afterfi{\XINT_xorof:_a 0}\fi}%
{\XINT_xorof:_a #2}%
}%
\def\XINT_xorof:_e ,#1#2^{#1}% allows empty list (then returns 0)
% \end{macrocode}
% \subsubsection{Generic csv routine}
% \lverb|1.1. generic routine. up to the loss of some efficiency, especially
% for Sum:csv and Prod:csv, where \XINTinFloat will be done twice for each
% argument.|
% \begin{macrocode}
\def\XINT_oncsv:_empty #1,^,#2{#2}%
\def\XINT_oncsv:_end ^,#1#2#3#4{#1}%
\def\XINT_oncsv:_a #1#2#3%
{\if ,#3\expandafter\XINT_oncsv:_empty\else\expandafter\XINT_oncsv:_b\fi #1#2#3}%
\def\XINT_oncsv:_b #1#2#3,%
{\expandafter\XINT_oncsv:_c \expandafter{\romannumeral`&&@#2{#3}}#1#2}%
\def\XINT_oncsv:_c #1#2#3#4,{\expandafter\XINT_oncsv:_d \romannumeral`&&@#4,{#1}#2#3}%
\def\XINT_oncsv:_d #1%
{\if ^#1\expandafter\XINT_oncsv:_end\else\expandafter\XINT_oncsv:_e\fi #1}%
\def\XINT_oncsv:_e #1,#2#3#4%
{\expandafter\XINT_oncsv:_c\expandafter {\romannumeral`&&@#3{#4{#1}}{#2}}#3#4}%
% \end{macrocode}
% \subsubsection{\csh{xintMaxof:csv}, \csh{xintiiMaxof:csv}}
% \lverb|1.09i. Rewritten for 1.1. Compatible avec liste vide donnant valeur par
% défaut. Pas compatible avec items manquants.
% ah je m'aperçois au dernier moment que je n'ai pas en effet de \xintiiMax.
% Je devrais le rajouter. En tout cas ici c'est uniquement pour xintiiexpr,
% dans il faut bien sûr ne pas faire de xintNum, donc il faut un iimax.|
% \begin{macrocode}
\def\xintMaxof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintmax
\expandafter\xint_firstofone\romannumeral`&&@#1,^,{0/1[0]}}%
\def\xintiiMaxof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintiimax
\expandafter\xint_firstofone\romannumeral`&&@#1,^,0}%
% \end{macrocode}
% \subsubsection{\csh{xintMinof:csv}, \csh{xintiiMinof:csv}}
% \lverb|1.09i. Rewritten for 1.1. For use by \xintiiexpr.|
% \begin{macrocode}
\def\xintMinof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintmin
\expandafter\xint_firstofone\romannumeral`&&@#1,^,{0/1[0]}}%
\def\xintiiMinof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintiimin
\expandafter\xint_firstofone\romannumeral`&&@#1,^,0}%
% \end{macrocode}
% \subsubsection{\csh{xintSum:csv}, \csh{xintiiSum:csv}}
% \lverb|1.09a. Rewritten for 1.1. For use by \xintexpr.|
% \begin{macrocode}
\def\xintSum:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintadd
\expandafter\xint_firstofone\romannumeral`&&@#1,^,{0/1[0]}}%
\def\xintiiSum:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintiiadd
\expandafter\xint_firstofone\romannumeral`&&@#1,^,0}%
% \end{macrocode}
% \subsubsection{\csh{xintPrd:csv}, \csh{xintiiPrd:csv}}
% \lverb|1.09a. Rewritten for 1.1. For use by \xintexpr.|
% \begin{macrocode}
\def\xintPrd:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintmul
\expandafter\xint_firstofone\romannumeral`&&@#1,^,{1/1[0]}}%
\def\xintiiPrd:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintiimul
\expandafter\xint_firstofone\romannumeral`&&@#1,^,1}%
% \end{macrocode}
% \subsubsection{\csh{xintGCDof:csv}, \csh{xintLCMof:csv}}
% \lverb|1.09a. Rewritten for 1.1. For use by \xintexpr. Expansion réinstaurée
% pour besoins de xintNewExpr de version 1.1|
% \begin{macrocode}
\def\xintGCDof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintgcd
\expandafter\xint_firstofone\romannumeral`&&@#1,^,1}%
\def\xintLCMof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintlcm
\expandafter\xint_firstofone\romannumeral`&&@#1,^,0}%
% \end{macrocode}
% \subsubsection{\csh{xintiiGCDof:csv}, \csh{xintiiLCMof:csv}}
% \lverb|1.1a pour \xintiiexpr. Ces histoires de ii sont pénibles à la fin.|
% \begin{macrocode}
\def\xintiiGCDof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintiigcd
\expandafter\xint_firstofone\romannumeral`&&@#1,^,1}%
\def\xintiiLCMof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintiilcm
\expandafter\xint_firstofone\romannumeral`&&@#1,^,0}%
% \end{macrocode}
% \subsubsection{\csh{XINTinFloatdigits}, \csh{XINTinFloatSqrtdigits}, \csh{XINTinFloatFacdigits}}
% \lverb|for \xintNewExpr matters, mainly.|
% \begin{macrocode}
\def\XINTinFloatdigits {\XINTinFloat [\XINTdigits]}%
\def\XINTinFloatSqrtdigits {\XINTinFloatSqrt[\XINTdigits]}%
\def\XINTinFloatFacdigits {\XINTinFloatFac [\XINTdigits]}%
% \end{macrocode}
% \subsubsection{\csh{XINTinFloatMaxof:csv}, \csh{XINTinFloatMinof:csv}}
% \lverb|1.09a. Rewritten for 1.1. For use by \xintfloatexpr. Name changed in 1.09h|
% \begin{macrocode}
\def\XINTinFloatMaxof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintmax
\expandafter\XINTinFloatdigits\romannumeral`&&@#1,^,{0[0]}}%
\def\XINTinFloatMinof:csv #1{\expandafter\XINT_oncsv:_a\expandafter\xintmin
\expandafter\XINTinFloatdigits\romannumeral`&&@#1,^,{0[0]}}%
% \end{macrocode}
% \subsubsection{\csh{XINTinFloatSum:csv}, \csh{XINTinFloatPrd:csv}}
% \lverb|1.09a. Rewritten for 1.1. For use by \xintfloatexpr.|
% \begin{macrocode}
\def\XINTinFloatSum:csv #1{\expandafter\XINT_oncsv:_a\expandafter\XINTinfloatadd
\expandafter\XINTinFloatdigits\romannumeral`&&@#1,^,{0[0]}}%
\def\XINTinFloatPrd:csv #1{\expandafter\XINT_oncsv:_a\expandafter\XINTinfloatmul
\expandafter\XINTinFloatdigits\romannumeral`&&@#1,^,{1[0]}}%
% \end{macrocode}
% \subsection{The num, reduce, abs, sgn, frac, floor, ceil, sqr, sqrt, sqrtr, float,
% round, trunc, mod, quo, rem, gcd, lcm, max, min, \textasciigrave
% +\textasciigrave, \textasciigrave
% \texorpdfstring{\protect\lowast}{*}\textasciigrave, ?, !, not, all, any,
% xor, if, ifsgn, even, odd, first, last, len, reversed, factorial and binomial functions}
% \localtableofcontents
% \begin{macrocode}
\def\XINT_expr_twoargs #1,#2,{{#1}{#2}}%
\def\XINT_expr_argandopt #1,#2,#3.#4#5%
{%
\if\relax#3\relax\expandafter\xint_firstoftwo\else
\expandafter\xint_secondoftwo\fi
{#4}{#5[\xintNum {#2}]}{#1}%
}%
\def\XINT_expr_oneortwo #1#2#3,#4,#5.%
{%
\if\relax#5\relax\expandafter\xint_firstoftwo\else
\expandafter\xint_secondoftwo\fi
{#1{0}}{#2{\xintNum {#4}}}{#3}%
}%
\def\XINT_iiexpr_oneortwo #1#2,#3,#4.%
{%
\if\relax#4\relax\expandafter\xint_firstoftwo\else
\expandafter\xint_secondoftwo\fi
{#1{0}}{#1{#3}}{#2}%
}%
\def\XINT_expr_func_num #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintNum {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_num\XINT_expr_func_num
\let\XINT_iiexpr_func_num\XINT_expr_func_num
% [0] added Oct 25. For interaction with SPRaw::csv
\def\XINT_expr_func_reduce #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintIrr {\XINT_expr_unlock #3}[0]\endcsname }%
\let\XINT_flexpr_func_reduce\XINT_expr_func_reduce
% no \XINT_iiexpr_func_reduce
\def\XINT_expr_func_abs #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintAbs {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_abs\XINT_expr_func_abs
\def\XINT_iiexpr_func_abs #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiAbs {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_sgn #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintSgn {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_sgn\XINT_expr_func_sgn
\def\XINT_iiexpr_func_sgn #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiSgn {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_frac #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintTFrac {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_flexpr_func_frac #1#2#3{\expandafter #1\expandafter #2\csname
.=\XINTinFloatFracdigits {\XINT_expr_unlock #3}\endcsname }%
% \end{macrocode}
% \lverb|no \XINT_iiexpr_func_frac|
% \begin{macrocode}
\def\XINT_expr_func_floor #1#2#3%
{\expandafter #1\expandafter #2\csname .=\xintFloor {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_floor\XINT_expr_func_floor
% \end{macrocode}
% \lverb|The floor and ceil functions in \xintiiexpr require protect(a/b) or,
% better, \qfrac(a/b); else the / will be executed first and do an integer
% rounded division.|
% \begin{macrocode}
\def\XINT_iiexpr_func_floor #1#2#3%
{%
\expandafter #1\expandafter #2\csname.=\xintiFloor {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_ceil #1#2#3%
{\expandafter #1\expandafter #2\csname .=\xintCeil {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_ceil\XINT_expr_func_ceil
\def\XINT_iiexpr_func_ceil #1#2#3%
{%
\expandafter #1\expandafter #2\csname.=\xintiCeil {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_sqr #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintSqr {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_flexpr_func_sqr #1#2#3%
{%
\expandafter #1\expandafter #2\csname
.=\XINTinFloatMul{\XINT_expr_unlock #3}{\XINT_expr_unlock #3}\endcsname
}%
\def\XINT_expr_func_factorial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_expr_argandopt
\romannumeral`&&@\XINT_expr_unlock#3,,.\xintiFac\XINTinFloatFac
\endcsname
}%
\def\XINT_flexpr_func_factorial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_expr_argandopt
\romannumeral`&&@\XINT_expr_unlock#3,,.\XINTinFloatFacdigits\XINTinFloatFac
\endcsname
}%
\def\XINT_iiexpr_func_factorial #1#2#3%
{%
\expandafter #1\expandafter #2\csname.=\xintiiFac{\XINT_expr_unlock #3}\endcsname
}%
\def\XINT_iiexpr_func_sqr #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiSqr {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_sqrt #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_expr_argandopt
\romannumeral`&&@\XINT_expr_unlock#3,,.\XINTinFloatSqrtdigits\XINTinFloatSqrt
\endcsname
}%
\let\XINT_flexpr_func_sqrt\XINT_expr_func_sqrt
\def\XINT_iiexpr_func_sqrt #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiSqrt {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_iiexpr_func_sqrtr #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiSqrtR {\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_round #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_expr_oneortwo
\expandafter\xintiRound\expandafter\xintRound
\romannumeral`&&@\XINT_expr_unlock #3,,.\endcsname
}%
\let\XINT_flexpr_func_round\XINT_expr_func_round
\def\XINT_iiexpr_func_round #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_iiexpr_oneortwo\expandafter\xintiRound
\romannumeral`&&@\XINT_expr_unlock #3,,.\endcsname
}%
\def\XINT_expr_func_trunc #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_expr_oneortwo
\expandafter\xintiTrunc\expandafter\xintTrunc
\romannumeral`&&@\XINT_expr_unlock #3,,.\endcsname
}%
\let\XINT_flexpr_func_trunc\XINT_expr_func_trunc
\def\XINT_iiexpr_func_trunc #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_iiexpr_oneortwo\expandafter\xintiTrunc
\romannumeral`&&@\XINT_expr_unlock #3,,.\endcsname
}%
\def\XINT_expr_func_float #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINT_expr_argandopt
\romannumeral`&&@\XINT_expr_unlock #3,,.\XINTinFloatdigits\XINTinFloat
\endcsname
}%
\let\XINT_flexpr_func_float\XINT_expr_func_float
% \XINT_iiexpr_func_float not defined
\def\XINT_expr_func_mod #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintMod
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_flexpr_func_mod #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\XINTinFloatMod
\romannumeral`&&@\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_iiexpr_func_mod #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiiMod
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_expr_func_binomial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiBinomial
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_flexpr_func_binomial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\XINTinFloatBinomial
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_iiexpr_func_binomial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiiBinomial
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_expr_func_pfactorial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiPFactorial
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_flexpr_func_pfactorial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\XINTinFloatPFactorial
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_iiexpr_func_pfactorial #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiiPFactorial
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_expr_func_quo #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiQuo
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\let\XINT_flexpr_func_quo\XINT_expr_func_quo
\def\XINT_iiexpr_func_quo #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiiQuo
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_expr_func_rem #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiRem
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\let\XINT_flexpr_func_rem\XINT_expr_func_rem
\def\XINT_iiexpr_func_rem #1#2#3%
{%
\expandafter #1\expandafter #2\csname .=%
\expandafter\expandafter\expandafter\xintiiRem
\expandafter\XINT_expr_twoargs
\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\def\XINT_expr_func_gcd #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintGCDof:csv{\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_gcd\XINT_expr_func_gcd
\def\XINT_iiexpr_func_gcd #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiGCDof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_lcm #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintLCMof:csv{\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_lcm\XINT_expr_func_lcm
\def\XINT_iiexpr_func_lcm #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiLCMof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_max #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintMaxof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_iiexpr_func_max #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiMaxof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_flexpr_func_max #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\XINTinFloatMaxof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_min #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintMinof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_iiexpr_func_min #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiMinof:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_flexpr_func_min #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\XINTinFloatMinof:csv{\XINT_expr_unlock #3}\endcsname }%
\expandafter\def\csname XINT_expr_func_+\endcsname #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintSum:csv{\XINT_expr_unlock #3}\endcsname }%
\expandafter\def\csname XINT_flexpr_func_+\endcsname #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\XINTinFloatSum:csv{\XINT_expr_unlock #3}\endcsname }%
\expandafter\def\csname XINT_iiexpr_func_+\endcsname #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiSum:csv{\XINT_expr_unlock #3}\endcsname }%
\expandafter\def\csname XINT_expr_func_*\endcsname #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintPrd:csv{\XINT_expr_unlock #3}\endcsname }%
\expandafter\def\csname XINT_flexpr_func_*\endcsname #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\XINTinFloatPrd:csv{\XINT_expr_unlock #3}\endcsname }%
\expandafter\def\csname XINT_iiexpr_func_*\endcsname #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiPrd:csv{\XINT_expr_unlock #3}\endcsname }%
\def\XINT_expr_func_? #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintiiIsNotZero {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_? \XINT_expr_func_?
\let\XINT_iiexpr_func_? \XINT_expr_func_?
\def\XINT_expr_func_! #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiIsZero {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_! \XINT_expr_func_!
\let\XINT_iiexpr_func_! \XINT_expr_func_!
\def\XINT_expr_func_not #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiIsZero {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_not \XINT_expr_func_not
\let\XINT_iiexpr_func_not \XINT_expr_func_not
\def\XINT_expr_func_all #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintANDof:csv{\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_all\XINT_expr_func_all
\let\XINT_iiexpr_func_all\XINT_expr_func_all
\def\XINT_expr_func_any #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintORof:csv{\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_any\XINT_expr_func_any
\let\XINT_iiexpr_func_any\XINT_expr_func_any
\def\XINT_expr_func_xor #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\xintXORof:csv{\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_xor\XINT_expr_func_xor
\let\XINT_iiexpr_func_xor\XINT_expr_func_xor
\def\xintifNotZero: #1,#2,#3,{\xintiiifNotZero{#1}{#2}{#3}}%
\def\XINT_expr_func_if #1#2#3%
{\expandafter #1\expandafter #2\csname
.=\expandafter\xintifNotZero:\romannumeral`&&@\XINT_expr_unlock #3,\endcsname }%
\let\XINT_flexpr_func_if\XINT_expr_func_if
\let\XINT_iiexpr_func_if\XINT_expr_func_if
\def\xintifSgn: #1,#2,#3,#4,{\xintiiifSgn{#1}{#2}{#3}{#4}}%
\def\XINT_expr_func_ifsgn #1#2#3%
{%
\expandafter #1\expandafter #2\csname
.=\expandafter\xintifSgn:\romannumeral`&&@\XINT_expr_unlock #3,\endcsname
}%
\let\XINT_flexpr_func_ifsgn\XINT_expr_func_ifsgn
\let\XINT_iiexpr_func_ifsgn\XINT_expr_func_ifsgn
\def\XINT_expr_func_len #1#2#3%
{\expandafter#1\expandafter#2%
\csname.=\xintLength:f:csv {\XINT_expr_unlock#3}\endcsname }%
\let\XINT_flexpr_func_len \XINT_expr_func_len
\let\XINT_iiexpr_func_len \XINT_expr_func_len
\def\XINT_expr_func_first #1#2#3%
{\expandafter #1\expandafter #2\csname.=\expandafter\XINT_expr_func_firsta
\romannumeral`&&@\XINT_expr_unlock #3,^\endcsname }%
\def\XINT_expr_func_firsta #1,#2^{#1}%
\let\XINT_flexpr_func_first\XINT_expr_func_first
\let\XINT_iiexpr_func_first\XINT_expr_func_first
\def\XINT_expr_func_last #1#2#3% will not work in \xintNewExpr if macro param involved
{\expandafter #1\expandafter #2\csname.=\expandafter\XINT_expr_func_lasta
\romannumeral`&&@\XINT_expr_unlock #3,^\endcsname }%
\def\XINT_expr_func_lasta #1,#2%
{\if ^#2 #1\expandafter\xint_gobble_ii\fi \XINT_expr_func_lasta #2}%
\let\XINT_flexpr_func_last\XINT_expr_func_last
\let\XINT_iiexpr_func_last\XINT_expr_func_last
\def\XINT_expr_func_odd #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintOdd{\XINT_expr_unlock #3}\endcsname}%
\let\XINT_flexpr_func_odd\XINT_expr_func_odd
\def\XINT_iiexpr_func_odd #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiOdd{\XINT_expr_unlock #3}\endcsname}%
\def\XINT_expr_func_even #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintEven{\XINT_expr_unlock #3}\endcsname}%
\let\XINT_flexpr_func_even\XINT_expr_func_even
\def\XINT_iiexpr_func_even #1#2#3%
{\expandafter #1\expandafter #2\csname.=\xintiiEven{\XINT_expr_unlock #3}\endcsname}%
\def\XINT_expr_func_nuple #1#2#3%
{\expandafter #1\expandafter #2\csname .=\XINT_expr_unlock #3\endcsname }%
\let\XINT_flexpr_func_nuple\XINT_expr_func_nuple
\let\XINT_iiexpr_func_nuple\XINT_expr_func_nuple
% \end{macrocode}
% \lverb|1.2c I hesitated but left the function "reversed" from 1.1 with
% this name, not "reverse". But the inner not public macro got renamed
% into \xintReverse::csv. 1.2g opts for the name \xintReverse:f:csv, and
% rewrites it for direct handling of csv lists. 2016/03/17.|
% \begin{macrocode}
\def\XINT_expr_func_reversed #1#2#3%
{\expandafter #1\expandafter #2\csname .=%
\xintReverse:f:csv {\XINT_expr_unlock #3}\endcsname }%
\let\XINT_flexpr_func_reversed\XINT_expr_func_reversed
\let\XINT_iiexpr_func_reversed\XINT_expr_func_reversed
% \end{macrocode}
% \subsection{f-expandable versions of the \csh{xintSeqB::csv} and alike
% routines, for \csh{xintNewExpr}}
% \localtableofcontents
% \subsubsection{\csh{xintSeqB:f:csv}}
% \lverb|Produces in f-expandable way. If the step is zero, gives empty result
% except if start and end coincide.|
% \begin{macrocode}
\def\xintSeqB:f:csv #1#2%
{\expandafter\XINT_seqb:f:csv \expandafter{\romannumeral0\xintraw{#2}}{#1}}%
\def\XINT_seqb:f:csv #1#2{\expandafter\XINT_seqb:f:csv_a\romannumeral`&&@#2#1!}%
\def\XINT_seqb:f:csv_a #1#2;#3;#4!{%
\expandafter\xint_gobble_i\romannumeral`&&@%
\xintifCmp {#3}{#4}\XINT_seqb:f:csv_bl\XINT_seqb:f:csv_be\XINT_seqb:f:csv_bg
#1{#3}{#4}{}{#2}}%
\def\XINT_seqb:f:csv_be #1#2#3#4#5{,#2}%
\def\XINT_seqb:f:csv_bl #1{\if #1p\expandafter\XINT_seqb:f:csv_pa\else
\xint_afterfi{\expandafter,\xint_gobble_iv}\fi }%
\def\XINT_seqb:f:csv_pa #1#2#3#4{\expandafter\XINT_seqb:f:csv_p\expandafter
{\romannumeral0\xintadd{#4}{#1}}{#2}{#3,#1}{#4}}%
\def\XINT_seqb:f:csv_p #1#2%
{%
\xintifCmp {#1}{#2}\XINT_seqb:f:csv_pa\XINT_seqb:f:csv_pb\XINT_seqb:f:csv_pc
{#1}{#2}%
}%
\def\XINT_seqb:f:csv_pb #1#2#3#4{#3,#1}%
\def\XINT_seqb:f:csv_pc #1#2#3#4{#3}%
\def\XINT_seqb:f:csv_bg #1{\if #1n\expandafter\XINT_seqb:f:csv_na\else
\xint_afterfi{\expandafter,\xint_gobble_iv}\fi }%
\def\XINT_seqb:f:csv_na #1#2#3#4{\expandafter\XINT_seqb:f:csv_n\expandafter
{\romannumeral0\xintadd{#4}{#1}}{#2}{#3,#1}{#4}}%
\def\XINT_seqb:f:csv_n #1#2%
{%
\xintifCmp {#1}{#2}\XINT_seqb:f:csv_nc\XINT_seqb:f:csv_nb\XINT_seqb:f:csv_na
{#1}{#2}%
}%
\def\XINT_seqb:f:csv_nb #1#2#3#4{#3,#1}%
\def\XINT_seqb:f:csv_nc #1#2#3#4{#3}%
% \end{macrocode}
%\subsubsection{\csh{xintiiSeqB:f:csv}}
% \lverb|Produces in f-expandable way. If the step is zero, gives empty result
% except if start and end coincide.
%
% 2015/11/11. I correct a typo dating back to release 1.1 (2014/10/29): the
% macro name had a "b" rather than "B", hence was not functional (causing
% \xintNewIIExpr to fail on inputs such as #1..[1]..#2).|
% \begin{macrocode}
\def\xintiiSeqB:f:csv #1#2%
{\expandafter\XINT_iiseqb:f:csv \expandafter{\romannumeral`&&@#2}{#1}}%
\def\XINT_iiseqb:f:csv #1#2{\expandafter\XINT_iiseqb:f:csv_a\romannumeral`&&@#2#1!}%
\def\XINT_iiseqb:f:csv_a #1#2;#3;#4!{%
\expandafter\xint_gobble_i\romannumeral`&&@%
\xintSgnFork{\XINT_Cmp {#3}{#4}}%
\XINT_iiseqb:f:csv_bl\XINT_seqb:f:csv_be\XINT_iiseqb:f:csv_bg
#1{#3}{#4}{}{#2}}%
\def\XINT_iiseqb:f:csv_bl #1{\if #1p\expandafter\XINT_iiseqb:f:csv_pa\else
\xint_afterfi{\expandafter,\xint_gobble_iv}\fi }%
\def\XINT_iiseqb:f:csv_pa #1#2#3#4{\expandafter\XINT_iiseqb:f:csv_p\expandafter
{\romannumeral0\xintiiadd{#4}{#1}}{#2}{#3,#1}{#4}}%
\def\XINT_iiseqb:f:csv_p #1#2%
{%
\xintSgnFork{\XINT_Cmp {#1}{#2}}%
\XINT_iiseqb:f:csv_pa\XINT_iiseqb:f:csv_pb\XINT_iiseqb:f:csv_pc {#1}{#2}%
}%
\def\XINT_iiseqb:f:csv_pb #1#2#3#4{#3,#1}%
\def\XINT_iiseqb:f:csv_pc #1#2#3#4{#3}%
\def\XINT_iiseqb:f:csv_bg #1{\if #1n\expandafter\XINT_iiseqb:f:csv_na\else
\xint_afterfi{\expandafter,\xint_gobble_iv}\fi }%
\def\XINT_iiseqb:f:csv_na #1#2#3#4{\expandafter\XINT_iiseqb:f:csv_n\expandafter
{\romannumeral0\xintiiadd{#4}{#1}}{#2}{#3,#1}{#4}}%
\def\XINT_iiseqb:f:csv_n #1#2%
{%
\xintSgnFork{\XINT_Cmp {#1}{#2}}%
\XINT_seqb:f:csv_nc\XINT_seqb:f:csv_nb\XINT_iiseqb:f:csv_na {#1}{#2}%
}%
% \end{macrocode}
%\subsubsection{\csh{XINTinFloatSeqB:f:csv}}
% \lverb|Produces in f-expandable way. If the step is zero, gives empty result
% except if start and end coincide. This is all for \xintNewExpr.|
% \begin{macrocode}
\def\XINTinFloatSeqB:f:csv #1#2{\expandafter\XINT_flseqb:f:csv \expandafter
{\romannumeral0\XINTinfloat [\XINTdigits]{#2}}{#1}}%
\def\XINT_flseqb:f:csv #1#2{\expandafter\XINT_flseqb:f:csv_a\romannumeral`&&@#2#1!}%
\def\XINT_flseqb:f:csv_a #1#2;#3;#4!{%
\expandafter\xint_gobble_i\romannumeral`&&@%
\xintifCmp {#3}{#4}\XINT_flseqb:f:csv_bl\XINT_seqb:f:csv_be\XINT_flseqb:f:csv_bg
#1{#3}{#4}{}{#2}}%
\def\XINT_flseqb:f:csv_bl #1{\if #1p\expandafter\XINT_flseqb:f:csv_pa\else
\xint_afterfi{\expandafter,\xint_gobble_iv}\fi }%
\def\XINT_flseqb:f:csv_pa #1#2#3#4{\expandafter\XINT_flseqb:f:csv_p\expandafter
{\romannumeral0\XINTinfloatadd{#4}{#1}}{#2}{#3,#1}{#4}}%
\def\XINT_flseqb:f:csv_p #1#2%
{%
\xintifCmp {#1}{#2}%
\XINT_flseqb:f:csv_pa\XINT_flseqb:f:csv_pb\XINT_flseqb:f:csv_pc {#1}{#2}%
}%
\def\XINT_flseqb:f:csv_pb #1#2#3#4{#3,#1}%
\def\XINT_flseqb:f:csv_pc #1#2#3#4{#3}%
\def\XINT_flseqb:f:csv_bg #1{\if #1n\expandafter\XINT_flseqb:f:csv_na\else
\xint_afterfi{\expandafter,\xint_gobble_iv}\fi }%
\def\XINT_flseqb:f:csv_na #1#2#3#4{\expandafter\XINT_flseqb:f:csv_n\expandafter
{\romannumeral0\XINTinfloatadd{#4}{#1}}{#2}{#3,#1}{#4}}%
\def\XINT_flseqb:f:csv_n #1#2%
{%
\xintifCmp {#1}{#2}%
\XINT_seqb:f:csv_nc\XINT_seqb:f:csv_nb\XINT_flseqb:f:csv_na {#1}{#2}%
}%
% \end{macrocode}
% \subsection{User defined functions: \csh{xintdeffunc}, \csh{xintdefiifunc},
% \csh{xintdeffloatfunc}}
%
% \lverb|1.2c (November 11-12, 2015). It is possible to
% overload a variable name with a function name (and conversely). The function
% interpretation with be used only if followed by an opening parenthesis,
% disabling the tacit multiplication usually applied to variables. Crazy
% things such as add(f(f), f=1..10) are possible if there is a function "f".
% Or we can use "e" both for an exponential function and the Euler constant.
%
% 2015/11/13: function candidates names first completely expanded, then
% detokenized and cleaned of spaces.
%
% 2015/11/21: no more \detokenize on the function names. Also I use
% #1(#2)#3:=#4 rather than #1(#2):=#3. Ah, rather #1(#2)#3=#4, then I don't
% have to worry about active :.
%
% 2016/02/22: 1.2f la macro associée à la fonction ne débute plus par un
% \romannumeral, de toute façon est pour emploi dans \csname..\endcsname.
%
% 2016/03/08: adding a pair of braces thus allowing comma separated
% expressions; until then the user had to do \xintdeffunc foo(x,..):=(.., ..,
% ..)\relax.
% |
% \begin{macrocode}
\catcode`: 12
\def\XINT_tmpa #1#2#3#4%
{%
\def #1##1(##2)##3=##4;{%
\edef\XINT_expr_tmpa {##1}%
\edef\XINT_expr_tmpa {\xint_zapspaces_o \XINT_expr_tmpa}%
\def\XINT_expr_tmpb {0}%
\def\XINT_expr_tmpc {(##4)}%
\xintFor ####1 in {##2} \do
{\edef\XINT_expr_tmpb {\the\numexpr\XINT_expr_tmpb+\xint_c_i}%
\edef\XINT_expr_tmpc {subs(\unexpanded\expandafter{\XINT_expr_tmpc},%
####1=################\XINT_expr_tmpb)}%
}%
\expandafter#3\csname XINT_#2_userfunc_\XINT_expr_tmpa\endcsname
[\XINT_expr_tmpb]{\XINT_expr_tmpc}%
\expandafter\XINT_expr_defuserfunc
\csname XINT_#2_func_\XINT_expr_tmpa\expandafter\endcsname
\csname XINT_#2_userfunc_\XINT_expr_tmpa\endcsname
\ifxintverbose\xintMessage {xintexpr}{Info}
{Function \XINT_expr_tmpa\space for \string\xint #4 parser
associated to \string\XINT_#2_userfunc_\XINT_expr_tmpa\space
with meaning \expandafter\meaning
\csname XINT_#2_userfunc_\XINT_expr_tmpa\endcsname}%
\fi
}%
}%
\catcode`: 11
\XINT_tmpa\xintdeffunc {expr} \XINT_NewFunc {expr}%
\XINT_tmpa\xintdefiifunc {iiexpr}\XINT_NewIIFunc {iiexpr}%
\XINT_tmpa\xintdeffloatfunc{flexpr}\XINT_NewFloatFunc{floatexpr}%
\def\XINT_expr_defuserfunc #1#2{%
\def #1##1##2##3{\expandafter ##1\expandafter ##2%
\csname .=\expandafter #2\romannumeral`&&@\XINT_expr_unlock ##3,\endcsname
}%
}%
% \end{macrocode}
% \subsection{\csh{xintNewFunction}}
% \lverb|1.2h (2016/11/20). Syntax is \xintNewFunction{<name>}[nb of
% arguments]{expression with #1, #2,... as in \xintNewExpr}. This defines
% a function for all three parsers but the expression parsing is delayed until
% function execution. Hence the expression admits all constructs, contrarily
% to \xintNewExpr or \xintdeffunc.
% |
% \begin{macrocode}
\def\XINT_expr_wrapit #1{\expandafter\XINT_expr_wrap\csname.=#1\endcsname}%
\def\xintNewFunction #1#2[#3]#4%
{%
\edef\XINT_expr_tmpa {#1}%
\edef\XINT_expr_tmpa {\xint_zapspaces_o \XINT_expr_tmpa}%
\def\XINT_expr_tmpb ##1##2##3##4##5##6##7##8##9{#4}%
\begingroup
\ifcase #3\relax
\toks0{,}%
\or \toks0{##1,}%
\or \toks0{##1,##2,}%
\or \toks0{##1,##2,##3,}%
\or \toks0{##1,##2,##3,##4,}%
\or \toks0{##1,##2,##3,##4,##5,}%
\or \toks0{##1,##2,##3,##4,##5,##6,}%
\or \toks0{##1,##2,##3,##4,##5,##6,##7,}%
\or \toks0{##1,##2,##3,##4,##5,##6,##7,##8,}%
\else \toks0{##1,##2,##3,##4,##5,##6,##7,##8,##9,}%
\fi
\expandafter
\endgroup
\expandafter
\def\csname XINT_expr_macrofunc_\XINT_expr_tmpa\expandafter\endcsname
\the\toks0\expandafter{\XINT_expr_tmpb
{\XINT_expr_wrapit{##1}}{\XINT_expr_wrapit{##2}}{\XINT_expr_wrapit{##3}}%
{\XINT_expr_wrapit{##4}}{\XINT_expr_wrapit{##5}}{\XINT_expr_wrapit{##6}}%
{\XINT_expr_wrapit{##7}}{\XINT_expr_wrapit{##8}}{\XINT_expr_wrapit{##9}}}%
\expandafter\XINT_expr_newfunction
\csname XINT_expr_func_\XINT_expr_tmpa\expandafter\endcsname
\csname XINT_expr_macrofunc_\XINT_expr_tmpa\endcsname\xintbareeval
\expandafter\XINT_expr_newfunction
\csname XINT_iiexpr_func_\XINT_expr_tmpa\expandafter\endcsname
\csname XINT_expr_macrofunc_\XINT_expr_tmpa\endcsname\xintbareiieval
\expandafter\XINT_expr_newfunction
\csname XINT_flexpr_func_\XINT_expr_tmpa\expandafter\endcsname
\csname XINT_expr_macrofunc_\XINT_expr_tmpa\endcsname\xintbarefloateval
\ifxintverbose
\xintMessage {xintexpr}{Info}
{Function \XINT_expr_tmpa\space for the expression parsers is
associated to \string\XINT_expr_macrofunc_\XINT_expr_tmpa\space
with meaning \expandafter\meaning
\csname XINT_expr_macrofunc_\XINT_expr_tmpa\endcsname}%
\fi
}%
\def\XINT_expr_newfunction #1#2#3%
{%
\def#1##1##2##3{\expandafter ##1\expandafter ##2\romannumeral`&&@%
#3\expandafter#2\romannumeral`&&@\XINT_expr_unlock##3,\relax}%
}%
% \end{macrocode}
% \subsection{\csh{xintNewExpr}, \csh{xintNewIExpr}, \csh{xintNewFloatExpr},
% \csh{xintNewIIExpr}}
% \localtableofcontents
% \lverb|&
% There was an \xintNewExpr already in 1.07 from May 2013, which was
% modified in September 2013 to work with the # macro parameter character,
% and then refactored into a more powerful version in June 2014 for 1.1
% release of 2014/10/28. List handling causes special
% challenges, addressed by \xintApply::csv, \xintApply:::csv, ... next.
%
% Comments finally added 2015/12/11 (with later edits):
%
% The whole point is to expand completely macros when they have only numerical
% arguments and to inhibit this expansion if not. This is done in a recursive
% way: the catcode 12 ~ is used to register a macro name whose expansion must
% be inhibited. Any argument itself starting with such a ~ will
% force use of ~ for the macro which receives it.
%
% In this context the catcode 12 $$ is used to signal a "virtual
% list" argument. It triggers insertion of \xintApply::csv or
% \xintApply:::csv for delayed handling later. This succeeds into handling
% inputs such as [#1..[#2]..#3][#4:#5]...
%
% A final
% \scantokens converts the "~" prefixed names into real control sequences.
%
% For this whole mechanism we need to have everything expressed using
% exclusively f-expandable macros. We avoid \csname...\endcsname like
% construct, but if absolutely needed perhaps we will do it ultimately.
%
% For the iterating loops seq, iter, etc..., and dummy variables, we have no
% macros to our disposal to handle the case where the list
% of indices is not explicit. Moreover omit, abort, break can not work with
% non numerical data. Thus the whole mechanism is currently not appicable to
% them. It does work when the macro parameters (or variables for \xintdeffunc)
% do not intervene in the list of values to iterate over. But we can not delay
% expansion of dummy variables.
% |
% \subsubsection{\csh{xintApply::csv}}
% \begin{macrocode}
\def\xintApply::csv #1#2%
{\expandafter\XINT_applyon::_a\expandafter {\romannumeral`&&@#2}{#1}}%
\def\XINT_applyon::_a #1#2{\XINT_applyon::_b {#2}{}#1,,}%
\def\XINT_applyon::_b #1#2#3,{\expandafter\XINT_applyon::_c \romannumeral`&&@#3,{#1}{#2}}%
\def\XINT_applyon::_c #1{\if #1,\expandafter\XINT_applyon::_end
\else\expandafter\XINT_applyon::_d\fi #1}%
\def\XINT_applyon::_d #1,#2{\expandafter\XINT_applyon::_e\romannumeral`&&@#2{#1},{#2}}%
\def\XINT_applyon::_e #1,#2#3{\XINT_applyon::_b {#2}{#3, #1}}%
\def\XINT_applyon::_end #1,#2#3{\xint_secondoftwo #3}%
% \end{macrocode}
% \subsubsection{\csh{xintApply:::csv}}
% \begin{macrocode}
\def\xintApply:::csv #1#2#3%
{\expandafter\XINT_applyon:::_a\expandafter{\romannumeral`&&@#2}{#1}{#3}}%
\def\XINT_applyon:::_a #1#2#3{\XINT_applyon:::_b {#2}{#3}{}#1,,}%
\def\XINT_applyon:::_b #1#2#3#4,%
{\expandafter\XINT_applyon:::_c \romannumeral`&&@#4,{#1}{#2}{#3}}%
\def\XINT_applyon:::_c #1{\if #1,\expandafter\XINT_applyon:::_end
\else\expandafter\XINT_applyon:::_d\fi #1}%
\def\XINT_applyon:::_d #1,#2#3%
{\expandafter\XINT_applyon:::_e\expandafter
{\romannumeral`&&@\xintApply::csv {#2{#1}}{#3}},{#2}{#3}}%
\def\XINT_applyon:::_e #1,#2#3#4{\XINT_applyon:::_b {#2}{#3}{#4, #1}}%
\def\XINT_applyon:::_end #1,#2#3#4{\xint_secondoftwo #4}%
% \end{macrocode}
% \subsubsection{\csh{XINT_expr_RApply::csv}, \csh{XINT_expr_LApply::csv},
% \csh{XINT_expr_RLApply:::csv}}
% \lverb|The #1 in _Rapply will start with a ~. No risk of glueing to previous
% ~expandafter during the \scantokens.
%
% Attention here and next ~ has catcode 12 and not 3 like elsewhere in
% xintexpr.|
% \begin{macrocode}
\catcode`~ 12
\def\XINT_expr_RApply::csv #1#2#3#4%
{~xintApply::csv{~expandafter#1~xint_exchangetwo_keepbraces{#4}}{#3}}%
\def\XINT_expr_LApply::csv #1#2#3#4{~xintApply::csv{#1{#3}}{#4}}%
\def\XINT_expr_RLApply:::csv #1#2{~xintApply:::csv{#1}}%
% \end{macrocode}
% \subsubsection{Mysterious stuff}
% \lverb|~ and $$ of catcode 12 in what follows.|
% \begin{macrocode}
\catcode`$ 12 % $
\def\XINT_xptwo_getab_b #1#2!#3%
{\expandafter\XINT_xptwo_getab_c\romannumeral`&&@#3!#1{#1#2}}%
\def\XINT_xptwo_getab_c #1#2!#3#4#5#6{#1#3{#5}{#6}{#1#2}{#4}}%
\def\xint_ddfork #1$$#2#3\krof {#2}% $$
\def\XINT_NEfork #1#2{\xint_ddfork
#1#2\XINT_expr_RLApply:::csv
#1$\XINT_expr_RApply::csv% $
$#2\XINT_expr_LApply::csv% $
$${\XINT_NEfork_nn #1#2}% $$
\krof }%
\def\XINT_NEfork_nn #1#2#3#4{%
\if #1##\xint_dothis{#3}\fi
\if #1~\xint_dothis{#3}\fi
\if #2##\xint_dothis{#3}\fi
\if #2~\xint_dothis{#3}\fi
\xint_orthat {\csname #4NE\endcsname }%
}%
\def\XINT_NEfork_one #1#2!#3#4#5#6{%
\if ###1\xint_dothis {#3}\fi
\if ~#1\xint_dothis {#3}\fi
\if $#1\xint_dothis {~xintApply::csv{#3#5}}\fi %$
\xint_orthat {\csname #4NE\endcsname #6}{#1#2}%
}%
\toks0 {}%
\xintFor #1 in
{DivTrunc,Mod,Round,Trunc,iRound,iTrunc,iQuo,iRem,
iiDivTrunc,iiDivRound,iiMod,iiQuo,iiRem,%
Lt,Gt,Eq,LtorEq,GtorEq,Neq,%
iiLt,iiGt,iiEq,iiLtorEq,iiGtorEq,iiNeq,%
Add,Sub,Mul,Div,Pow,E,%
iiAdd,iiSub,iiMul,iiPow,iiE,%
AND,OR,XOR,%
SeqA::csv,iiSeqA::csv}\do
{\toks0
\expandafter{\the\toks0% no space!
\expandafter\let\csname xint#1NE\expandafter\endcsname\csname xint#1\expandafter
\endcsname\expandafter\def\csname xint#1\endcsname ####1####2{%
\expandafter\XINT_NEfork
\romannumeral`&&@\expandafter\XINT_xptwo_getab_b
\romannumeral`&&@####2!{####1}{~xint#1}{xint#1}}%
}%
}%
% cela aurait-il un sens d'ajouter Raw et iNum (à cause de qint, qfrac,
% qfloat?). Pas le temps d'y réfléchir. Je ne fais rien.
\xintFor #1 in {Num,Irr,Abs,iiAbs,Sgn,iiSgn,TFrac,Floor,iFloor,Ceil,iCeil,%
Sqr,iiSqr,iiSqrt,iiSqrtR,iiIsZero,iiIsNotZero,iiifNotZero,iiifSgn,%
Odd,Even,iiOdd,iiEven,Opp,iiOpp,iiifZero,iFac,iBinomial,%
iPFactorial,iiFac,iiBinomial,iiPFactorial,Bool,Toggle}\do
{\toks0 \expandafter{\the\toks0%
\expandafter\let\csname xint#1NE\expandafter\endcsname\csname
xint#1\expandafter
\endcsname\expandafter\def\csname xint#1\endcsname ####1{%
\expandafter\XINT_NEfork_one\romannumeral`&&@####1!{~xint#1}{xint#1}{}{}}%
}%
}%
\toks0
\expandafter{\the\toks0
\let\XINTinFloatFacNE\XINTinFloatFac
\def\XINTinFloatFac ##1{%
\expandafter\XINT_NEfork_one
\romannumeral`&&@##1!{~XINTinFloatFac}{XINTinFloatFac}{}{}}%
}%
\xintFor #1 in {Add,Sub,Mul,Div,Binomial,PFactorial,PowerH,E,Mod,SeqA::csv}\do
{\toks0
\expandafter{\the\toks0%
\expandafter\let\csname XINTinFloat#1NE\expandafter\endcsname
\csname XINTinFloat#1\expandafter\endcsname
\expandafter\def\csname XINTinFloat#1\endcsname ####1####2{%
\expandafter\XINT_NEfork
\romannumeral`&&@\expandafter\XINT_xptwo_getab_b
\romannumeral`&&@####2!{####1}{~XINTinFloat#1}{XINTinFloat#1}}%
}%
}%
\xintFor #1 in {XINTinFloatdigits,XINTinFloatFracdigits,XINTinFloatSqrtdigits,XINTinFloatFacdigits}\do
{\toks0
\expandafter{\the\toks0%
\expandafter\let\csname #1NE\expandafter\endcsname\csname #1\expandafter
\endcsname\expandafter\def\csname #1\endcsname ####1{\expandafter
\XINT_NEfork_one\romannumeral`&&@####1!{~#1}{#1}{}{}}%
}%
}%
\xintFor #1 in {xintSeq::csv,xintiiSeq::csv,XINTinFloatSeq::csv}\do
{\toks0
\expandafter{\the\toks0% no space
\expandafter\let\csname #1NE\expandafter\endcsname\csname #1\expandafter
\endcsname\expandafter\def\csname #1\endcsname ####1####2{%
\expandafter\XINT_NEfork
\romannumeral`&&@\expandafter\XINT_xptwo_getab_b
\romannumeral`&&@####2!{####1}{$noexpand$#1}{#1}}%
}%
}%
\xintFor #1 in {xintSeqB,xintiiSeqB,XINTinFloatSeqB}\do
{\toks0
\expandafter{\the\toks0% no space
\expandafter\let\csname #1::csvNE\expandafter\endcsname\csname #1::csv\expandafter
\endcsname\expandafter\def\csname #1::csv\endcsname ####1####2{%
\expandafter\XINT_NEfork
\romannumeral`&&@\expandafter\XINT_xptwo_getab_b
\romannumeral`&&@####2!{####1}{$noexpand$#1:f:csv}{#1::csv}}%
}%
}%
\toks0
\expandafter{\the\toks0
\let\XINTinFloatNE\XINTinFloat
\def\XINTinFloat [##1]##2{% not ultimately general, but got tired
\expandafter\XINT_NEfork_one
\romannumeral`&&@##2!{~XINTinFloat[##1]}{XINTinFloat}{}{[##1]}}%
\let\XINTinFloatSqrtNE\XINTinFloatSqrt
\def\XINTinFloatSqrt [##1]##2{%
\expandafter\XINT_NEfork_one
\romannumeral`&&@##2!{~XINTinFloatSqrt[##1]}{XINTinFloatSqrt}{}{[##1]}}%
\let\XINTinFloatFacNE\XINTinFloatFac
\def\XINTinFloatFac [##1]##2{%
\expandafter\XINT_NEfork_one
\romannumeral`&&@##2!{~XINTinFloatFac[##1]}{XINTinFloatFac}{}{[##1]}}%
}%
\xintFor #1 in {ANDof,ORof,XORof,iiMaxof,iiMinof,iiSum,iiPrd,
GCDof,LCMof,Sum,Prd,Maxof,Minof}\do
{\toks0
\expandafter{\the\toks0\expandafter\def\csname xint#1:csv\endcsname {~xint#1:csv}}%
}%
\xintFor #1 in
{XINTinFloatMaxof,XINTinFloatMinof,XINTinFloatSum,XINTinFloatPrd}\do
{\toks0
\expandafter{\the\toks0\expandafter\def\csname #1:csv\endcsname {~#1:csv}}%
}%
% \end{macrocode}
% \lverb|~xintListSel:f:csv must have space after it, the reason being in
% \XINT_expr_until_:_b which inserts a : as fist token of something which will
% reappear later following ~xintListSel:f:csv.
%
% Notice that 1.1 was chicken and did not even try to expand the Reverse and
% ListSel by fear of the complexities and overhead of checking whether it
% contained macro parameters (possibly embedded in sub-macros).|
% \begin{macrocode}
\toks0 \expandafter{\the\toks0
\def\xintReverse:f:csv {~xintReverse:f:csv }%
\def\xintListSel:f:csv {~xintListSel:f:csv }%
}%
\odef\XINT_expr_redefinemacros {\the\toks0}% Not \edef ! (subtle)
\def\XINT_expr_redefineprints
{%
\def\XINT_flexpr_noopt
{\expandafter\XINT_flexpr_withopt_b\expandafter-\romannumeral0\xintbarefloateval }%
\def\XINT_flexpr_withopt_b ##1##2%
{\expandafter\XINT_flexpr_wrap\csname .;##1.=\XINT_expr_unlock ##2\endcsname }%
\def\XINT_expr_unlock_sp ##1.;##2##3.=##4!%
{\if -##2\expandafter\xint_firstoftwo\else\expandafter\xint_secondoftwo\fi
\XINTdigits{{##2##3}}{##4}}%
\def\XINT_expr_print ##1{\expandafter\xintSPRaw::csv\expandafter
{\romannumeral`&&@\XINT_expr_unlock ##1}}%
\def\XINT_iiexpr_print ##1{\expandafter\xintCSV::csv\expandafter
{\romannumeral`&&@\XINT_expr_unlock ##1}}%
\def\XINT_boolexpr_print ##1{\expandafter\xintIsTrue::csv\expandafter
{\romannumeral`&&@\XINT_expr_unlock ##1}}%
% \end{macrocode}
% \begin{macrocode}
\def\xintCSV::csv {~xintCSV::csv }%
\def\xintSPRaw::csv {~xintSPRaw::csv }%
\def\xintPFloat::csv {~xintPFloat::csv }%
\def\xintIsTrue::csv {~xintIsTrue::csv }%
\def\xintRound::csv {~xintRound::csv }%
}%
\toks0 {}%
% \end{macrocode}
% \subsubsection{\csh{xintNewExpr}, ..., at last.}
% \lverb|&
% 1.2c modifications to accomodate \XINT_expr_deffunc_newexpr etc..
%
% 1.2f adds token \XINT_newexpr_clean to be able to have a different
% \XINT_newfunc_clean |
% \begin{macrocode}
\def\xintNewExpr {\XINT_NewExpr{}\XINT_expr_redefineprints\xint_firstofone
\xinttheexpr\XINT_newexpr_clean}%
\def\xintNewFloatExpr{\XINT_NewExpr{}\XINT_expr_redefineprints\xint_firstofone
\xintthefloatexpr\XINT_newexpr_clean}%
\def\xintNewIExpr {\XINT_NewExpr{}\XINT_expr_redefineprints\xint_firstofone
\xinttheiexpr\XINT_newexpr_clean}%
\def\xintNewIIExpr {\XINT_NewExpr{}\XINT_expr_redefineprints\xint_firstofone
\xinttheiiexpr\XINT_newexpr_clean}%
\def\xintNewBoolExpr {\XINT_NewExpr{}\XINT_expr_redefineprints\xint_firstofone
\xinttheboolexpr\XINT_newexpr_clean}%
\def\XINT_newexpr_clean #1>{\noexpand\romannumeral`&&@}%
% \end{macrocode}
% \lverb|1.2c for \xintdeffunc, \xintdefiifunc, \xintdeffloatfunc.|
% \begin{macrocode}
\def\XINT_NewFunc
{\XINT_NewExpr,{}\xint_gobble_i\xintthebareeval \XINT_newfunc_clean }%
\def\XINT_NewFloatFunc
{\XINT_NewExpr,{}\xint_gobble_i\xintthebarefloateval\XINT_newfunc_clean }%
\def\XINT_NewIIFunc
{\XINT_NewExpr,{}\xint_gobble_i\xintthebareiieval \XINT_newfunc_clean }%
\def\XINT_newfunc_clean #1>{}%
% \end{macrocode}
% \lverb|1.2c adds optional logging. For this needed to pass to _NewExpr_a the
% macro name as parameter. And _NewExpr itself receives two new parameters to
% treat both \xintNewExpr and \xintdeffunc.
%
% Up to and including 1.2c the definition was global. Starting with 1.2d it is
% done locally.
% |
% \begin{macrocode}
\def\XINT_NewExpr #1#2#3#4#5#6#7[#8]%
{%
\begingroup
\ifcase #8\relax
\toks0 {\endgroup\def#6}%
\or \toks0 {\endgroup\def#6##1#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1##4#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1##4#1##5#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1##4#1##5#1##6#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1##4#1##5#1##6#1##7#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1##4#1##5#1##6#1##7#1##8#1}%
\or \toks0 {\endgroup\def#6##1#1##2#1##3#1##4#1##5#1##6#1##7#1##8#1##9#1}%
\fi
\xintexprSafeCatcodes
\XINT_expr_redefinemacros
#2%
\XINT_NewExpr_a #3#4#5#6%
}%
% \end{macrocode}
% \lverb|& attention que & est de catcode 14
% $catcode38 12
% For the 1.2a release I replaced all \romannumeral-`0 by a fancier
% \romannumeral`&&@ (with & of catcode 7). I got lucky here that it worked,
% despite @ being of catcode comment (anyhow \input xintexpr.sty would not
% have compiled if not, and I would have realized immediately). But to be
% honest I wouldn't have been 100$% sure
% beforehand that &&@ worked also with @ comment character. I now know.
%
% 1.2d's \xintNewExpr makes a local definition. In earlier releases, the
% definition was global.|
% \begin{macrocode}
\catcode`~ 13 \catcode`@ 14 \catcode`\% 6 \catcode`# 12 \catcode`$ 11 @ $
\def\XINT_NewExpr_a %1%2%3%4%5@
{@
\def\XINT_tmpa %%1%%2%%3%%4%%5%%6%%7%%8%%9{%5}@
\def~{$noexpand$}@
\catcode`: 11 \catcode`_ 11
\catcode`# 12 \catcode`~ 13 \escapechar 126
\endlinechar -1 \everyeof {\noexpand }@
\edef\XINT_tmpb
{\scantokens\expandafter
{\romannumeral`&&@\expandafter%2\XINT_tmpa {#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}\relax}@
}@
\escapechar 92 \catcode`# 6 \catcode`$ 0 @ $
\edef\XINT_tmpa %%1%%2%%3%%4%%5%%6%%7%%8%%9@
{\scantokens\expandafter{\expandafter%3\meaning\XINT_tmpb}}@
\the\toks0\expandafter{\XINT_tmpa{%%1}{%%2}{%%3}{%%4}{%%5}{%%6}{%%7}{%%8}{%%9}}@
%1{\ifxintverbose
\xintMessage{xintexpr}{Info}@
{\string%4\space now with meaning \meaning%4}@
\fi}@
}@
\catcode`% 14
\let\xintexprRestoreCatcodes\empty
\def\xintexprSafeCatcodes
{%
\edef\xintexprRestoreCatcodes {%
\catcode59=\the\catcode59 % ;
\catcode34=\the\catcode34 % "
\catcode63=\the\catcode63 % ?
\catcode124=\the\catcode124 % |
\catcode38=\the\catcode38 % &
\catcode33=\the\catcode33 % !
\catcode93=\the\catcode93 % ]
\catcode91=\the\catcode91 % [
\catcode94=\the\catcode94 % ^
\catcode95=\the\catcode95 % _
\catcode47=\the\catcode47 % /
\catcode41=\the\catcode41 % )
\catcode40=\the\catcode40 % (
\catcode42=\the\catcode42 % *
\catcode43=\the\catcode43 % +
\catcode62=\the\catcode62 % >
\catcode60=\the\catcode60 % <
\catcode58=\the\catcode58 % :
\catcode46=\the\catcode46 % .
\catcode45=\the\catcode45 % -
\catcode44=\the\catcode44 % ,
\catcode61=\the\catcode61 % =
\catcode32=\the\catcode32\relax % space
}%
\catcode59=12 % ;
\catcode34=12 % "
\catcode63=12 % ?
\catcode124=12 % |
\catcode38=4 % &
\catcode33=12 % !
\catcode93=12 % ]
\catcode91=12 % [
\catcode94=7 % ^
\catcode95=8 % _
\catcode47=12 % /
\catcode41=12 % )
\catcode40=12 % (
\catcode42=12 % *
\catcode43=12 % +
\catcode62=12 % >
\catcode60=12 % <
\catcode58=12 % :
\catcode46=12 % .
\catcode45=12 % -
\catcode44=12 % ,
\catcode61=12 % =
\catcode32=10 % space
}%
\let\XINT_tmpa\relax \let\XINT_tmpb\relax \let\XINT_tmpc\relax
\XINT_restorecatcodes_endinput%
% \end{macrocode}
%
% \StoreCodelineNo {xintexpr}
%
% \MakePercentComment
%</xintexpr>------------------------------------------------------
%<*dtx>-----------------------------------------------------------
\iffalse
% grep -c -e "^{%" xint*sty
xint.sty:233
xintbinhex.sty:69
xintcfrac.sty:183
xintcore.sty:287
xintexpr.sty:147
xintfrac.sty:463
xintgcd.sty:59
xintkernel.sty:7
xintseries.sty:48
xinttools.sty:147
\fi
% grep -o "^{%" xint*sty | wc -l
\def\totala{ 1643}
\iffalse
% grep -c -e "^}%" xint*sty
xint.sty:233
xintbinhex.sty:69
xintcfrac.sty:183
xintcore.sty:287
xintexpr.sty:178
xintfrac.sty:463
xintgcd.sty:61
xintkernel.sty:9
xintseries.sty:48
xinttools.sty:147
\fi
% grep -o "^}%" xint*sty | wc -l
\def\totalb{ 1678}
\DeleteShortVerb{\|}
\def\mymacro #1{\mymacroaux #1}
\def\mymacroaux #1#2{\strut \csname #1nameimp\endcsname:& \dtt{ #2.}\tabularnewline }
\indent
\begin{tabular}[t]{r@{}r}
\xintApplyInline\mymacro\storedlinecounts
\end{tabular}
\def\mymacroaux #1#2{#2}%
%
\parbox[t]{10cm}{Total number of code lines:
\dtt{\the\numexpr
\xintListWithSep+{\xintApply\mymacro\storedlinecounts}\relax }.
\ifdefined\totala
(but \dtt{\the\numexpr \totala+\totalb\relax} lines among them
start either with \{\% or with \}\%.)\fi
Each package starts with circa \dtt{50} lines dealing with catcodes,
package identification and reloading management, also for Plain
\TeX\strut. Version {\xintbndlversion} of {\xintbndldate}.\par
}
\CharacterTable
{Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
Digits \0\1\2\3\4\5\6\7\8\9
Exclamation \! Double quote \" Hash (number) \#
Dollar \$ Percent \% Ampersand \&
Acute accent \' Left paren \( Right paren \)
Asterisk \* Plus \+ Comma \,
Minus \- Point \. Solidus \/
Colon \: Semicolon \; Less than \<
Equals \= Greater than \> Question mark \?
Commercial at \@ Left bracket \[ Backslash \\
Right bracket \] Circumflex \^ Underscore \_
Grave accent \` Left brace \{ Vertical bar \|
Right brace \} Tilde \~}
\CheckSum {30303}%
\makeatletter\check@checksum\makeatother
\Finale
%% End of file xint.dtx
|